Skip to content

Commit 89f6282

Browse files
committedOct 27, 2017
[auth] Added test cases for expired CAs and client certs
1 parent 19e212c commit 89f6282

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed
 

‎tests/src/python/test_qgsauthsystem.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,35 @@ def mkPEMBundle(client_cert, client_key, password, chain):
684684
# Test invalid with intermediates and trusted root
685685
self.assertEqual(QgsAuthCertUtils.validatePKIBundle(bundle, True, True), ['Private key does not match client certificate public key.'])
686686

687-
# TODO: Wrong root CA
688-
# TODO: expired/not-yet-valid cert
689-
# TODO: expired/not-yet-valid intermediate (is it possible to build a cert from one of those?)
687+
# Expired root CA
688+
bundle = mkPEMBundle('piri_cert.pem', 'piri_key.pem', 'password', 'chain_issuer3-root3-EXPIRED.pem')
689+
self.assertEqual(QgsAuthCertUtils.validatePKIBundle(bundle), ['The root certificate of the certificate chain is self-signed, and untrusted', 'The certificate has expired'])
690+
self.assertEqual(QgsAuthCertUtils.validatePKIBundle(bundle, False), ['The issuer certificate of a locally looked up certificate could not be found', 'No certificates could be verified'])
691+
self.assertEqual(QgsAuthCertUtils.validatePKIBundle(bundle, True, True), ['The root certificate of the certificate chain is self-signed, and untrusted', 'The certificate has expired'])
692+
693+
# Expired intermediate CA
694+
bundle = mkPEMBundle('marinus_cert-EXPIRED.pem', 'marinus_key_w-pass.pem', 'password', 'chain_issuer2-root2.pem')
695+
self.assertEqual(QgsAuthCertUtils.validatePKIBundle(bundle), ['The root certificate of the certificate chain is self-signed, and untrusted', 'The certificate has expired'])
696+
self.assertEqual(QgsAuthCertUtils.validatePKIBundle(bundle, False), ['The issuer certificate of a locally looked up certificate could not be found', 'No certificates could be verified'])
697+
self.assertEqual(QgsAuthCertUtils.validatePKIBundle(bundle, True, True), ['The certificate has expired'])
698+
699+
# Expired client cert
700+
bundle = mkPEMBundle('henricus_cert.pem', 'henricus_key_w-pass.pem', 'password', 'chain_issuer4-EXPIRED-root2.pem')
701+
self.assertEqual(QgsAuthCertUtils.validatePKIBundle(bundle), ['The root certificate of the certificate chain is self-signed, and untrusted', 'The certificate has expired'])
702+
self.assertEqual(QgsAuthCertUtils.validatePKIBundle(bundle, False), ['The issuer certificate of a locally looked up certificate could not be found', 'No certificates could be verified'])
703+
self.assertEqual(QgsAuthCertUtils.validatePKIBundle(bundle, True, True), ['The certificate has expired'])
704+
705+
# Untrusted root, positive test before untrust is applied
706+
bundle = mkPEMBundle('nicholas_cert.pem', 'nicholas_key.pem', 'password', 'chain_issuer2-root2.pem')
707+
# Test valid with intermediates and trusted root
708+
self.assertEqual(QgsAuthCertUtils.validatePKIBundle(bundle, True, True), [])
709+
# Untrust this root
710+
root2 = QgsAuthCertUtils.certFromFile(PKIDATA + '/' + 'root2_ca_cert.pem')
711+
QgsApplication.authManager().storeCertAuthority(root2)
712+
self.assertTrue(QgsApplication.authManager().storeCertTrustPolicy(root2, QgsAuthCertUtils.Untrusted))
713+
QgsApplication.authManager().rebuildCaCertsCache()
714+
# Test valid with intermediates and untrusted root
715+
self.assertEqual(QgsAuthCertUtils.validatePKIBundle(bundle, True, True), ['The issuer certificate of a locally looked up certificate could not be found'])
690716

691717

692718
if __name__ == '__main__':

0 commit comments

Comments
 (0)
Please sign in to comment.