Skip to content

Commit

Permalink
Cover PKI validation with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karlerikounapuu committed May 5, 2020
1 parent 2dbcbf1 commit e18942e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/fixtures/certificates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
one:
api_user: api_bestnames
common_name: registry.test
crt: "-----BEGIN CERTIFICATE-----\nMIICYjCCAcugAwIBAgIBADANBgkqhkiG9w0BAQ0FADBNMQswCQYDVQQGEwJ1czEO\nMAwGA1UECAwFVGV4YXMxFjAUBgNVBAoMDVJlZ2lzdHJ5IHRlc3QxFjAUBgNVBAMM\nDXJlZ2lzdHJ5LnRlc3QwIBcNMjAwNTA1MTIzNzQxWhgPMjEyMDA0MTExMjM3NDFa\nME0xCzAJBgNVBAYTAnVzMQ4wDAYDVQQIDAVUZXhhczEWMBQGA1UECgwNUmVnaXN0\ncnkgdGVzdDEWMBQGA1UEAwwNcmVnaXN0cnkudGVzdDCBnzANBgkqhkiG9w0BAQEF\nAAOBjQAwgYkCgYEAyn+GCkUJIhdXVBOPrZH+Zj2B/tQfL5TLZwVYZQt38x6GQT+4\n6ndty467IJvKSUlHej7uMpsCzC8Ffmda4cZm16jO1vUb4hXIrmeKP84zLrrUpKag\ngZR4rBDbG2+uL4SzMyy3yeQysYuTiQ4N1i4vdhvkKYPSWIht/QFvuzdFq+0CAwEA\nAaNQME4wHQYDVR0OBBYEFD6B5j6NnMCDBnfbtjBYKBJM7sCRMB8GA1UdIwQYMBaA\nFD6B5j6NnMCDBnfbtjBYKBJM7sCRMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEN\nBQADgYEArtCR6VOabD3nM/KlZTmHMZVT4ntenYlNTM9FS0RatzPmdh4REhykvmZs\nOlBcpoV5tN5Y8bHOVRqY9V2e903QEhQgoccQhbt0Py6uFwfLv+WLKAUbeGnPqK9d\ndL3wXN9BQs0hJA6IZNFyz2F/gSTURrD1zWW2na3ipRzhupW5+98=\n-----END CERTIFICATE-----\n"
md5: e6771ed5dc857a1dbcc1e0a36baa1fee
interface: api
revoked: false
15 changes: 15 additions & 0 deletions test/models/api_user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ def test_finds_user_by_id_card
assert_nil ApiUser.find_by_id_card(id_card)
end

def test_verifies_pki_status
certificate = certificates(:one)

assert @user.pki_ok?(certificate.crt, certificate.common_name, api: true)
assert_not @user.pki_ok?(certificate.crt, 'invalid-cn', api: true)

certificate.update(interface: 'registrar')

assert @user.pki_ok?(certificate.crt, certificate.common_name, api: false)
assert_not @user.pki_ok?(certificate.crt, 'invalid-cn', api: false)

certificate.update(revoked: true)
assert_not @user.pki_ok?(certificate.crt, certificate.common_name, api: false)
end

private

def valid_user
Expand Down

0 comments on commit e18942e

Please sign in to comment.