def test_set_ca_certificate_settings(self): Configuration().create_new_configuration(self.config_filename) Configuration().set_ca_key_filename("examplefilename.key") Configuration().set_ca_certificate_filename("examplefilename.crt") assert Configuration().get_ca_certificate_filename( ) == "examplefilename.crt" assert Configuration().get_ca_key_filename() == "examplefilename.key" os.unlink(self.config_filename)
def test_read_ca_certificate_existent_default(self): Configuration() # create a manager manager = CertManager() self.assertEquals("certslayer.net.crt", Configuration().get_ca_certificate_filename()) self.assertEquals("certslayer.net.key", Configuration().get_ca_key_filename()) self.assertEquals("certslayer.net", manager.CA_CERT.get_issuer().CN)
def test_create_new_configuration(self): Configuration().create_new_configuration(config_filename="test.ini") Configuration().set_ca_certificate_filename("test.crt") self.assertEquals("test.crt", Configuration().get_ca_certificate_filename()) Configuration().set_ca_certificate_filename("certslayer.net.crt") self.assertEquals("certslayer.net.crt", Configuration().get_ca_certificate_filename()) os.unlink("test.ini")
def request(cls, url, method="GET"): import urllib3 ca_certs = os.path.join(Configuration().get_ca_certificate_folder(), Configuration().get_ca_certificate_filename()) http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=ca_certs) try: r = http.request(method, url) except urllib3.exceptions.SSLError as e: pass
def test_local_server_up_self_signed(self): attribs = {"self-signed": True} crt_file, key_file = self.cert_manager.generate_certificate(attribs) crt_file = os.path.join(Configuration().get_temp_certificate_folder(), crt_file) key_file = os.path.join(Configuration().get_temp_certificate_folder(), key_file) worker1 = WebServerSetup(keyfile=key_file, certfile=crt_file, server_address=("127.0.0.1", 4444), callback=self.callback_test.increment) worker1.start() AuxiliarHTTPSClient.request("https://127.0.0.1:4444/") worker1.kill() self.assertEquals(0, self.callback_test.track)
def test_describe_certificate(self): manager = CertManager() x509 = manager.load_certificate( filename=Configuration().get_ca_certificate_file()) description = manager.describe_certificate(x509) description = description.split("\n")[0] self.assertEquals("Subject CN: certslayer.net", description)
def test_defaults(self): """ self.set_ca_certificate_filename("certslayer.net.crt") self.set_ca_key_filename("certslayer.net.key") self.set_ca_certificate_folder("ca_cert") self.set_temp_certificate_folder("certificates") """ Configuration().create_new_configuration(self.config_filename) self.assertEquals("certslayer.net.crt", Configuration().get_ca_certificate_filename()) self.assertEquals("certslayer.net.key", Configuration().get_ca_key_filename()) self.assertEquals("ca_cert", Configuration().get_ca_certificate_folder()) self.assertEquals("certificates", Configuration().get_temp_certificate_folder()) os.unlink(self.config_filename)
def test_sign_with_root_ca(self): Configuration().create_new_configuration("config.ini") manager = CertManager() crt, key = manager.sign_with_root_ca( x509=manager.get_domain_certificate("www.google.com", 443)) x509 = manager.load_certificate(filename=crt) self.assertEquals("certslayer.net", x509.get_issuer().CN) os.unlink(crt) os.unlink(key)
def test_read_ca_certificate_non_existent(self): Configuration().create_new_configuration("temp.ini") Configuration().set_ca_certificate_filename("trav.crt") Configuration().set_ca_key_filename("trav.key") manager = CertManager() self.assertEquals("trav.crt", Configuration().get_ca_certificate_filename()) self.assertEquals("trav.key", Configuration().get_ca_key_filename()) self.assertEquals("certslayer.net", manager.CA_CERT.get_issuer().CN) os.unlink(Configuration().get_ca_key_file()) os.unlink(Configuration().get_ca_certificate_file()) os.unlink("temp.ini")
def tearDown(self): target_folder = Configuration().get_temp_certificate_folder() for f in os.listdir(target_folder): os.remove(os.path.join(target_folder, f))
def test_fake_server_address(self): Configuration().create_new_configuration(self.config_filename) Configuration().fake_server_address = ("127.0.0.1", 0) self.assertEquals(("127.0.0.1", 0), Configuration().fake_server_address) os.unlink(self.config_filename)
def test_set_ca_certificate_folder(self): Configuration().create_new_configuration(self.config_filename) Configuration().set_ca_certificate_folder("tempfolder") self.assertEquals("tempfolder", Configuration().get_ca_certificate_folder()) os.unlink(self.config_filename)
def test_config_file_creation(self): Configuration(config_filename=self.config_filename) self.assertEquals(True, os.path.isfile(self.config_filename)) os.unlink(self.config_filename)