summaryrefslogtreecommitdiffstats
path: root/roles/openshift_certificate_expiry/test/test_fakeopensslclasses.py
diff options
context:
space:
mode:
authorTim Bielawa <timbielawa@gmail.com>2017-02-21 12:20:44 -0800
committerGitHub <noreply@github.com>2017-02-21 12:20:44 -0800
commit21c8b00b2db05ba5a6f85ba6a5c97494152231af (patch)
treed90e623d257e1a89957c729ad03024335237838f /roles/openshift_certificate_expiry/test/test_fakeopensslclasses.py
parentdde7fc686f14f4dbd7ac93aefad4ddb7ed1269fd (diff)
parent003bc8d5b9233e61c7a2a5f0a27b66ac1babc1a0 (diff)
downloadopenshift-21c8b00b2db05ba5a6f85ba6a5c97494152231af.tar.gz
openshift-21c8b00b2db05ba5a6f85ba6a5c97494152231af.tar.bz2
openshift-21c8b00b2db05ba5a6f85ba6a5c97494152231af.tar.xz
openshift-21c8b00b2db05ba5a6f85ba6a5c97494152231af.zip
Merge pull request #3436 from tbielawa/hacky_cert_parsing
Implement fake openssl cert classes
Diffstat (limited to 'roles/openshift_certificate_expiry/test/test_fakeopensslclasses.py')
-rw-r--r--roles/openshift_certificate_expiry/test/test_fakeopensslclasses.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/roles/openshift_certificate_expiry/test/test_fakeopensslclasses.py b/roles/openshift_certificate_expiry/test/test_fakeopensslclasses.py
new file mode 100644
index 000000000..2e245191f
--- /dev/null
+++ b/roles/openshift_certificate_expiry/test/test_fakeopensslclasses.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+'''
+ Unit tests for the FakeOpenSSL classes
+'''
+
+import os
+import sys
+import unittest
+import pytest
+
+# Disable import-error b/c our libraries aren't loaded in jenkins
+# pylint: disable=import-error,wrong-import-position
+# place class in our python path
+module_path = os.path.join('/'.join(os.path.realpath(__file__).split(os.path.sep)[:-1]), 'library')
+sys.path.insert(0, module_path)
+openshift_cert_expiry = pytest.importorskip("openshift_cert_expiry")
+
+
+@pytest.mark.skip('Skipping all tests because of unresolved import errors')
+class TestFakeOpenSSLClasses(unittest.TestCase):
+ '''
+ Test class for FakeOpenSSL classes
+ '''
+
+ def setUp(self):
+ ''' setup method for other tests '''
+ with open('test/system-node-m01.example.com.crt.txt', 'r') as fp:
+ self.cert_string = fp.read()
+
+ self.fake_cert = openshift_cert_expiry.FakeOpenSSLCertificate(self.cert_string)
+
+ with open('test/master.server.crt.txt', 'r') as fp:
+ self.cert_san_string = fp.read()
+
+ self.fake_san_cert = openshift_cert_expiry.FakeOpenSSLCertificate(self.cert_san_string)
+
+ def test_FakeOpenSSLCertificate_get_serial_number(self):
+ """We can read the serial number from the cert"""
+ self.assertEqual(11, self.fake_cert.get_serial_number())
+
+ def test_FakeOpenSSLCertificate_get_notAfter(self):
+ """We can read the cert expiry date"""
+ expiry = self.fake_cert.get_notAfter()
+ self.assertEqual('20190207181935Z', expiry)
+
+ def test_FakeOpenSSLCertificate_get_sans(self):
+ """We can read Subject Alt Names from a cert"""
+ ext = self.fake_san_cert.get_extension(0)
+
+ if ext.get_short_name() == 'subjectAltName':
+ sans = str(ext)
+
+ self.assertEqual('DNS:kubernetes, DNS:kubernetes.default, DNS:kubernetes.default.svc, DNS:kubernetes.default.svc.cluster.local, DNS:m01.example.com, DNS:openshift, DNS:openshift.default, DNS:openshift.default.svc, DNS:openshift.default.svc.cluster.local, DNS:172.30.0.1, DNS:192.168.122.241, IP Address:172.30.0.1, IP Address:192.168.122.241', sans)
+
+ def test_FakeOpenSSLCertificate_get_sans_no_sans(self):
+ """We can tell when there are no Subject Alt Names in a cert"""
+ with self.assertRaises(IndexError):
+ self.fake_cert.get_extension(0)
+
+ def test_FakeOpenSSLCertificate_get_subject(self):
+ """We can read the Subject from a cert"""
+ # Subject: O=system:nodes, CN=system:node:m01.example.com
+ subject = self.fake_cert.get_subject()
+ subjects = []
+ for name, value in subject.get_components():
+ subjects.append('{}={}'.format(name, value))
+
+ self.assertEqual('O=system:nodes, CN=system:node:m01.example.com', ', '.join(subjects))
+
+ def test_FakeOpenSSLCertificate_get_subject_san_cert(self):
+ """We can read the Subject from a cert with sans"""
+ # Subject: O=system:nodes, CN=system:node:m01.example.com
+ subject = self.fake_san_cert.get_subject()
+ subjects = []
+ for name, value in subject.get_components():
+ subjects.append('{}={}'.format(name, value))
+
+ self.assertEqual('CN=172.30.0.1', ', '.join(subjects))
+
+
+if __name__ == "__main__":
+ unittest.main()