diff options
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/cert_test.rb | 52 | ||||
-rw-r--r-- | test/unit/couch_changes_test.rb | 6 | ||||
-rw-r--r-- | test/unit/couch_stream_test.rb | 6 |
3 files changed, 23 insertions, 41 deletions
diff --git a/test/unit/cert_test.rb b/test/unit/cert_test.rb index 761e5a9..21e4d96 100644 --- a/test/unit/cert_test.rb +++ b/test/unit/cert_test.rb @@ -1,50 +1,32 @@ -require 'test_helper' -require 'leap_ca/cert' +require File.expand_path('../../test_helper.rb', __FILE__) class CertTest < MiniTest::Unit::TestCase def setup - @sample = Cert.new - @sample.set_random - @sample.attach_zip + @cert = LeapCA::Cert.new end - def test_certs_come_with_attachments - assert @sample.has_attachment? "cert.txt" - end + def test_generate + @cert.generate - def test_zipper_returns_zip_attachement - assert_equal "text/plain", @sample.zip_attachment["content_type"] - end + assert @cert.cert, 'certificate should exist' + assert @cert.key, 'key should exist' - def test_zipname_returns_name_of_zip_file - assert_equal "cert.txt", @sample.zipname - end + ca = OpenSSL::X509::Certificate.new(File.read(LeapCA::Config.ca_cert_path)) + cert = OpenSSL::X509::Certificate.new(@cert.cert) + key = OpenSSL::PKey::RSA.new(@cert.key) - def test_test_data - assert @sample.valid? - end - - def test_zipped_returns_actual_data - @sample.save # This is required! - lines = @sample.zipped.split("\n") - assert_equal 56, lines.count - assert_equal "-----BEGIN RSA PRIVATE KEY-----", lines.first.chomp - assert_equal "-----END CERTIFICATE-----", lines.last.chomp + assert cert.verify(ca.public_key), "cert was not signed by CA" + assert_equal ca.subject.to_s, cert.issuer.to_s, 'issuer should match' + assert_equal "test", cert.public_key.public_decrypt(key.private_encrypt("test")), 'keypair should be able to encrypt/decrypt' end def test_validation_of_random - @sample.stubs(:set_random) - [0, 1, nil, "asdf"].each do |invalid| - @sample.random = invalid - assert !@sample.valid?, "#{invalid} should not be a valid value for random" + @cert.stubs(:set_random) + [1, nil, "asdf"].each do |invalid| + @cert.random = invalid + assert !@cert.valid?, "#{invalid} should not be a valid value for random" end end - def test_validation_of_attachement - @sample.stubs(:attach_zip) - @sample.delete_attachment(@sample.zipname) - assert !@sample.valid?, "Cert should require zipped attachment" - end - -end +end
\ No newline at end of file diff --git a/test/unit/couch_changes_test.rb b/test/unit/couch_changes_test.rb index 2ef5de3..9c99d30 100644 --- a/test/unit/couch_changes_test.rb +++ b/test/unit/couch_changes_test.rb @@ -1,5 +1,5 @@ -require 'test_helper' -require 'lib/couch_changes' +require File.expand_path('../../test_helper.rb', __FILE__) +require 'leap_ca/couch_changes' class CouchChangesTest < MiniTest::Unit::TestCase @@ -7,7 +7,7 @@ class CouchChangesTest < MiniTest::Unit::TestCase def setup @stream = mock() - @changes = CouchChanges.new(@stream) + @changes = LeapCA::CouchChanges.new(@stream) end def test_last_seq diff --git a/test/unit/couch_stream_test.rb b/test/unit/couch_stream_test.rb index af5a34e..7f86351 100644 --- a/test/unit/couch_stream_test.rb +++ b/test/unit/couch_stream_test.rb @@ -1,5 +1,5 @@ -require 'test_helper' -require 'lib/couch_stream' +require File.expand_path('../../test_helper.rb', __FILE__) +require 'leap_ca/couch_stream' # we'll mock this module Yajl @@ -11,7 +11,7 @@ class CouchStreamTest < MiniTest::Unit::TestCase def setup @root = "http://server/database" - @stream = CouchStream.new(@root) + @stream = LeapCA::CouchStream.new(@root) @url = @root + "/_changes?a=b&c=d" @path = "_changes" @options = {:a => :b, :c => :d} |