summaryrefslogtreecommitdiff
path: root/certs/test
diff options
context:
space:
mode:
Diffstat (limited to 'certs/test')
-rw-r--r--certs/test/functional/certs_controller_test.rb37
-rw-r--r--certs/test/unit/client_certificate_test.rb23
2 files changed, 45 insertions, 15 deletions
diff --git a/certs/test/functional/certs_controller_test.rb b/certs/test/functional/certs_controller_test.rb
index 75256ca..7826dd6 100644
--- a/certs/test/functional/certs_controller_test.rb
+++ b/certs/test/functional/certs_controller_test.rb
@@ -1,21 +1,40 @@
require 'test_helper'
class CertsControllerTest < ActionController::TestCase
- setup do
- end
- test "should require login" do
+ test "send free cert without login" do
+ cert = stub :to_s => "free cert"
+ ClientCertificate.expects(:new).with(free: true).returns(cert)
get :show
- assert_response :redirect
- assert_redirected_to login_url
+ assert_response :success
+ assert_equal cert.to_s, @response.body
end
- test "should send cert" do
+ test "send cert" do
login
- cert = stub :cert => "adsf", :key => "key"
- ClientCertificate.expects(:new).returns(cert)
+ cert = stub :to_s => "real cert"
+ ClientCertificate.expects(:new).with(free: false).returns(cert)
get :show
assert_response :success
- assert_equal cert.key + cert.cert, @response.body
+ assert_equal cert.to_s, @response.body
+ end
+
+ test "login required if free certs disabled" do
+ with_config free_certs_enabled: false do
+ get :show
+ assert_response :redirect
+ end
end
+
+ test "get paid cert if free certs disabled" do
+ with_config free_certs_enabled: false do
+ login
+ cert = stub :to_s => "real cert"
+ ClientCertificate.expects(:new).with(free: false).returns(cert)
+ get :show
+ assert_response :success
+ assert_equal cert.to_s, @response.body
+ end
+ end
+
end
diff --git a/certs/test/unit/client_certificate_test.rb b/certs/test/unit/client_certificate_test.rb
index 71a1d90..bcc61cc 100644
--- a/certs/test/unit/client_certificate_test.rb
+++ b/certs/test/unit/client_certificate_test.rb
@@ -2,17 +2,28 @@ require 'test_helper'
class ClientCertificateTest < ActiveSupport::TestCase
- setup do
- @sample = ClientCertificate.new
+ test "new cert has all we need" do
+ sample = ClientCertificate.new
+ assert sample.key
+ assert sample.cert
+ assert sample.to_s
end
- test "new cert has all we need" do
- assert @sample.key
- assert @sample.cert
+ test "free cert has configured postfix" do
+ sample = ClientCertificate.new(free: true)
+ postfix = APP_CONFIG[:free_cert_postfix]
+ assert sample.cert.subject.common_name.include?(postfix)
+ end
+
+ test "real cert has no free cert postfix" do
+ sample = ClientCertificate.new
+ postfix = APP_CONFIG[:free_cert_postfix]
+ assert !sample.cert.subject.common_name.include?(postfix)
end
test "cert issuer matches ca subject" do
- cert = OpenSSL::X509::Certificate.new(@sample.cert)
+ sample = ClientCertificate.new
+ cert = OpenSSL::X509::Certificate.new(sample.cert.to_pem)
assert_equal ClientCertificate.root_ca.openssl_body.subject, cert.issuer
end