From c90d30621e042cc3e52ffc87e3491ab110a57e9e Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 24 Sep 2012 12:16:14 +0200 Subject: ported over proper ways of creating certs Will now use .txt as the extention Returns the actual content on .zipped With tests. --- leap_ca.gemspec | 2 ++ lib/leap_ca/cert.rb | 13 +++++++++---- test/test_helper.rb | 3 +++ test/unit/cert_test.rb | 16 ++++++++++++---- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/leap_ca.gemspec b/leap_ca.gemspec index 01a2f33..43c2e27 100644 --- a/leap_ca.gemspec +++ b/leap_ca.gemspec @@ -20,5 +20,7 @@ Gem::Specification.new do |s| s.add_dependency "couchrest_model", "~> 2.0.0.beta2" s.add_dependency "daemons" s.add_dependency "yajl-ruby" + s.add_development_dependency "minitest", "~> 3.2.0" + s.add_development_dependency "mocha" end diff --git a/lib/leap_ca/cert.rb b/lib/leap_ca/cert.rb index 80adfbb..1459e01 100644 --- a/lib/leap_ca/cert.rb +++ b/lib/leap_ca/cert.rb @@ -13,7 +13,7 @@ class Cert < CouchRest::Model::Base validates :random, :presence => true, :numericality => {:greater_than => 0, :less_than => 1} - validates :zipped, :presence => true + validates :zip_attachment, :presence => true design do end @@ -23,15 +23,20 @@ class Cert < CouchRest::Model::Base end def attach_zip - self.create_attachment :file => StringIO.new("dummy cert"), :name => zipname + file = File.open File.join(LEAP_CA_ROOT, "config", "cert") + self.create_attachment :file => file, :name => zipname end def zipname - 'cert.zip' + 'cert.txt' end - def zipped + def zip_attachment attachments[zipname] end + def zipped + read_attachment(zipname) + end + end diff --git a/test/test_helper.rb b/test/test_helper.rb index 742e462..d78cc96 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,6 @@ require 'rubygems' require 'minitest/autorun' +LEAP_CA_ROOT = File.expand_path('../..', __FILE__) +$:.unshift File.expand_path('lib', LEAP_CA_ROOT) + require 'mocha' diff --git a/test/unit/cert_test.rb b/test/unit/cert_test.rb index 3f4c01f..761e5a9 100644 --- a/test/unit/cert_test.rb +++ b/test/unit/cert_test.rb @@ -1,5 +1,5 @@ require 'test_helper' -require 'lib/cert' +require 'leap_ca/cert' class CertTest < MiniTest::Unit::TestCase @@ -10,21 +10,29 @@ class CertTest < MiniTest::Unit::TestCase end def test_certs_come_with_attachments - assert @sample.has_attachment? "cert.zip" + assert @sample.has_attachment? "cert.txt" end def test_zipper_returns_zip_attachement - assert_equal "application/zip", @sample.zipped["content_type"] + assert_equal "text/plain", @sample.zip_attachment["content_type"] end def test_zipname_returns_name_of_zip_file - assert_equal "cert.zip", @sample.zipname + assert_equal "cert.txt", @sample.zipname end 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 + end + def test_validation_of_random @sample.stubs(:set_random) [0, 1, nil, "asdf"].each do |invalid| -- cgit v1.2.3