summaryrefslogtreecommitdiff
path: root/certs/test
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2012-09-27 22:36:21 +0200
committerAzul <azul@riseup.net>2012-09-27 22:36:21 +0200
commit1208257bcc0e2a6648b68433a7b7e24791f92583 (patch)
treec676f2030bef20705e46421b478b7f9305bcf13e /certs/test
parente17a2a676e0ce585ef9eaa9077887bfe1bc1173f (diff)
adding in leap web certs - merging repos
Diffstat (limited to 'certs/test')
-rw-r--r--certs/test/functional/certs_controller_test.rb15
-rw-r--r--certs/test/integration/navigation_test.rb9
-rw-r--r--certs/test/leap_web_certs_test.rb7
-rw-r--r--certs/test/test_helper.rb10
-rw-r--r--certs/test/unit/cert_pool_test.rb51
-rw-r--r--certs/test/unit/cert_test.rb48
6 files changed, 140 insertions, 0 deletions
diff --git a/certs/test/functional/certs_controller_test.rb b/certs/test/functional/certs_controller_test.rb
new file mode 100644
index 0000000..04669f5
--- /dev/null
+++ b/certs/test/functional/certs_controller_test.rb
@@ -0,0 +1,15 @@
+require 'test_helper'
+
+class CertsControllerTest < ActionController::TestCase
+ setup do
+ end
+
+ test "should send cert" do
+ cert = stub :zipped => "adsf", :zipname => "cert_stub.zip"
+ Cert.expects(:pick_from_pool).returns(cert)
+ get :show
+ assert_response :success
+ assert_equal cert.zipped, @response.body
+ assert_attachement_filename "cert_stub.zip"
+ end
+end
diff --git a/certs/test/integration/navigation_test.rb b/certs/test/integration/navigation_test.rb
new file mode 100644
index 0000000..eec8c0e
--- /dev/null
+++ b/certs/test/integration/navigation_test.rb
@@ -0,0 +1,9 @@
+require 'test_helper'
+
+class NavigationTest < ActionDispatch::IntegrationTest
+
+ # test "the truth" do
+ # assert true
+ # end
+end
+
diff --git a/certs/test/leap_web_certs_test.rb b/certs/test/leap_web_certs_test.rb
new file mode 100644
index 0000000..ee2058b
--- /dev/null
+++ b/certs/test/leap_web_certs_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class LeapWebCertsTest < ActiveSupport::TestCase
+ test "truth" do
+ assert_kind_of Module, LeapWebCerts
+ end
+end
diff --git a/certs/test/test_helper.rb b/certs/test/test_helper.rb
new file mode 100644
index 0000000..b268c51
--- /dev/null
+++ b/certs/test/test_helper.rb
@@ -0,0 +1,10 @@
+ENV["RAILS_ENV"] = "test"
+require File.expand_path('../dummy/config/environment', __FILE__)
+require 'rails/test_help'
+require 'mocha'
+
+Rails.backtrace_cleaner.remove_silencers!
+
+# Load support files
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
+
diff --git a/certs/test/unit/cert_pool_test.rb b/certs/test/unit/cert_pool_test.rb
new file mode 100644
index 0000000..24ace57
--- /dev/null
+++ b/certs/test/unit/cert_pool_test.rb
@@ -0,0 +1,51 @@
+require 'test_helper'
+
+class CertPoolTest < ActiveSupport::TestCase
+
+ setup do
+ 2.times { Cert.create! }
+ end
+
+ teardown do
+ Cert.all.each {|c| c.destroy}
+ end
+
+ test "picks random sample" do
+ Cert.create! # with 3 certs chances are pretty low we pick the same one 40 times.
+ picked = []
+ first = Cert.sample.id
+ current = Cert.sample.id
+ 40.times do
+ break if current != first
+ current = Cert.sample.id
+ end
+ assert_not_equal current, first
+ end
+
+ test "picks cert from the pool" do
+ assert_difference "Cert.count", -1 do
+ cert = Cert.pick_from_pool
+ end
+ end
+
+ test "err's out if all certs have been destroyed" do
+ sample = Cert.first.tap{|c| c.destroy}
+ Cert.all.each {|c| c.destroy}
+ assert_raises RECORD_NOT_FOUND do
+ Cert.expects(:sample).returns(sample)
+ cert = Cert.pick_from_pool
+ end
+ end
+
+ test "picks other cert if first pick has been destroyed" do
+ first = Cert.first.tap{|c| c.destroy}
+ second = Cert.first
+ Cert.expects(:sample).at_least_once.
+ returns(first).
+ then.returns(second)
+ cert = Cert.pick_from_pool
+ assert_equal second, cert
+ assert_nil Cert.first
+ end
+
+end
diff --git a/certs/test/unit/cert_test.rb b/certs/test/unit/cert_test.rb
new file mode 100644
index 0000000..21ef169
--- /dev/null
+++ b/certs/test/unit/cert_test.rb
@@ -0,0 +1,48 @@
+require 'test_helper'
+
+class CertTest < ActiveSupport::TestCase
+
+ setup do
+ @sample = Cert.new
+ @sample.set_random
+ @sample.attach_zip
+ end
+
+ test "certs come with attachments" do
+ assert @sample.has_attachment? "cert.txt"
+ end
+
+ test "cert.zip_attachment returns couchDB attachment" do
+ assert_equal "text/plain", @sample.zip_attachment["content_type"]
+ end
+
+ test "cert.zipped returns the actual data" do
+ @sample.save # This is required!
+ assert lines = @sample.zipped.split("\n")
+ assert_equal "-----BEGIN RSA PRIVATE KEY-----", lines.first.chomp
+ assert_equal "-----END CERTIFICATE-----", lines.last.chomp
+ end
+
+ test "cert.zipname returns name for the zip file" do
+ assert_equal "cert.txt", @sample.zipname
+ end
+
+ test "test data is valid" do
+ assert @sample.valid?
+ end
+
+ test "validates random" do
+ @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"
+ end
+ end
+
+ test "validates attachment" do
+ @sample.stubs(:attach_zip)
+ @sample.delete_attachment(@sample.zipname)
+ assert !@sample.valid?, "Cert should require zipped attachment"
+ end
+
+end