summaryrefslogtreecommitdiff
path: root/certs/test/unit/client_certificate_test.rb
blob: bcc61cc945c85ee53300ebaf7b5a6b89ccd39b6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'test_helper'

class ClientCertificateTest < ActiveSupport::TestCase

  test "new cert has all we need" do
    sample = ClientCertificate.new
    assert sample.key
    assert sample.cert
    assert sample.to_s
  end

  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
    sample = ClientCertificate.new
    cert = OpenSSL::X509::Certificate.new(sample.cert.to_pem)
    assert_equal ClientCertificate.root_ca.openssl_body.subject, cert.issuer
  end

end