summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2012-09-24 12:16:14 +0200
committerAzul <azul@riseup.net>2012-09-24 12:16:14 +0200
commitc90d30621e042cc3e52ffc87e3491ab110a57e9e (patch)
tree9ebb5b3026dddd4c3c56f4eb333201327a2641aa
parent06b8d8c971a07df3f96fdfd0e753a8284d0dac5a (diff)
ported over proper ways of creating certs
Will now use .txt as the extention Returns the actual content on .zipped With tests.
-rw-r--r--leap_ca.gemspec2
-rw-r--r--lib/leap_ca/cert.rb13
-rw-r--r--test/test_helper.rb3
-rw-r--r--test/unit/cert_test.rb16
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|