aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Rokos <m.rokos@sh.cvut.cz>2002-07-01 14:33:16 +0000
committerMichal Rokos <m.rokos@sh.cvut.cz>2002-07-01 14:33:16 +0000
commite7c83103da77739c5f75092520533f3c3e290860 (patch)
tree2477f8fa0774719db56cc9ca78d3f4984ed148ff
parent56ce81c3c2112a40b326023996c9a96f90fd2759 (diff)
downloadruby-openssl-history-e7c83103da77739c5f75092520533f3c3e290860.tar.gz
NEW TestCases
-rw-r--r--ChangeLog4
-rwxr-xr-xtest/tc_x509name.rb59
-rwxr-xr-xtest/tc_x509req.rb111
-rwxr-xr-xtest/tc_x509revoked.rb4
4 files changed, 174 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index c0f1494..96728b3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,10 @@ ChangeLog for
### CHANGE LOG ###
+Mon, 1 Jul 2002 15:36:28 +0100 -- Michal Rokos <m.rokos@sh.cvut.cz>
+ * tc_x509name.rb: NEW (TestCase)
+ * tc_x509req.rb: NEW (TestCase)
+
Mon, 1 Jul 2002 14:04:35 +0100 -- Michal Rokos <m.rokos@sh.cvut.cz>
* tc_x509revoked.rb: NEW (TestCase)
diff --git a/test/tc_x509name.rb b/test/tc_x509name.rb
new file mode 100755
index 0000000..a93ecb1
--- /dev/null
+++ b/test/tc_x509name.rb
@@ -0,0 +1,59 @@
+#!/usr/bin/env ruby
+=begin
+= $RCSfile$ -- TestCases for OpenSSL::X509::Name
+
+= Info
+ 'OpenSSL for Ruby 2' project
+ Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
+ All rights reserved.
+
+= Licence
+ This program is licenced under the same licence as Ruby.
+ (See the file 'LICENCE'.)
+
+= Version
+ $Id$
+=end
+
+require 'test/unit'
+require 'openssl'
+
+include OpenSSL
+include X509
+
+##
+# OpenSSL::debug = true
+#
+
+class TC_Name < Test::Unit::TestCase
+ def set_up
+ ##
+ # NONE
+ #
+ end
+ def test_name
+ a = [["C", "CZ"], ["O", "OpenSSL for Ruby"], ["OU", "Development"], ["CN", "Tester"]]
+ s = ""
+ a.each do |e|
+ s += "/" + e.join("=")
+ end
+
+ name = Name::new(a)
+
+ assert_equal(s, name.to_s, "to_s")
+ assert_equal(a, name.to_a, "to_a")
+ end
+ def test_cmp
+ ##
+ # TODO
+ # #cmp
+ # <=>
+ #
+ end
+ def tear_down
+ ##
+ # NONE
+ #
+ end
+end
+
diff --git a/test/tc_x509req.rb b/test/tc_x509req.rb
new file mode 100755
index 0000000..1968558
--- /dev/null
+++ b/test/tc_x509req.rb
@@ -0,0 +1,111 @@
+#!/usr/bin/env ruby
+=begin
+= $RCSfile$ -- TestCases for OpenSSL::X509::Request
+
+= Info
+ 'OpenSSL for Ruby 2' project
+ Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
+ All rights reserved.
+
+= Licence
+ This program is licenced under the same licence as Ruby.
+ (See the file 'LICENCE'.)
+
+= Version
+ $Id$
+=end
+
+require 'test/unit'
+require 'openssl'
+
+include OpenSSL
+include X509
+
+##
+# OpenSSL::debug = true
+#
+
+puts "Creating blank certificate"
+$req = Request::new()
+
+puts "Generating 1024-bit RSA key"
+$rsa = PKey::RSA::generate(1024) {|p, n| # the same as in OpenSSL
+ if (p == 0) then putc "." # BN_generate_prime
+ elsif (p == 1) then putc "+" # BN_generate_prime
+ elsif (p == 2) then putc "*" # searching good prime, n = #of try, but also data from BN_generate_prime
+ elsif (p == 3) then putc "\n" # found good prime, n==0 - p, n==1 - q, but also data from BN_generate_prime
+ else putc "*" # BN_generate_prime
+ end
+}
+
+##
+# NOTE
+# tests are numbered, because we depend on their exec. order
+#
+class TC_Request < Test::Unit::TestCase
+ def set_up
+ ##
+ # NONE
+ #
+ end
+ def test_01version
+ version = 2
+
+ assert_equal(0, $req.version, "version")
+ $req.version = version
+ assert_equal(version, $req.version, "version =")
+ end
+ def test_02subject
+ a = [["C", "CZ"], ["O", "OpenSSL for Ruby"], ["OU", "Development"], ["CN", "Tester"]]
+
+ assert_instance_of(Name, $req.subject, "subject")
+ assert_equal("", $req.subject.to_s, "subject")
+ $req.subject = Name::new(a)
+ assert_equal(a, $req.subject.to_a, "subject =")
+ end
+ def test_03pubkey
+ pubk = $rsa.public_key
+
+ ##
+ # NOTE
+ # empty public_key throws "unknown public key type"
+ #
+ $req.public_key = pubk
+ ##
+ # TODO
+ # FIXME
+ # add == method to PKeys
+ # assert_equal(pubk, $req.public_key, "public_key")
+ #
+ end
+ def test_04attributes
+ ##
+ # TODO
+ # attributes
+ # attributes =
+ # attributes
+ # add_attribute
+ # attributes
+ #
+ end
+ def test_05sign_verify
+ $req.sign($rsa, Digest::MD5::new)
+ assert($req.verify($rsa), "verify")
+ end
+ def test_06export
+ assert_instance_of(String, $req.to_pem, "to_pem")
+ assert_instance_of(String, $req.to_text, "to_text")
+ end
+ def test_07load
+ txt = $req.to_text
+
+ req = Request::new($req.to_pem)
+ assert_equal(txt, req.to_text, "new instance from PEM")
+ end
+ def tear_down
+ ##
+ # NONE
+ #
+ end
+end
+
diff --git a/test/tc_x509revoked.rb b/test/tc_x509revoked.rb
index d8188fc..50f77c4 100755
--- a/test/tc_x509revoked.rb
+++ b/test/tc_x509revoked.rb
@@ -25,10 +25,6 @@ include X509
# OpenSSL::debug = true
#
-##
-# NOTE
-# tests are numbered, because we depend on their exec. order
-#
class TC_Revoked < Test::Unit::TestCase
def set_up
@rev = Revoked::new()