Skip to content

Commit

Permalink
Merge branch 'ari' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
grindsa committed Feb 4, 2024
2 parents c8f7e58 + 28c47af commit efc07db
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 41 deletions.
2 changes: 1 addition & 1 deletion test/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2182,7 +2182,7 @@ def test_284_aki_get(self, mock_load, mock_aki):
self.assertTrue(mock_aki.called)

@patch('OpenSSL.crypto.load_certificate')
def test_281_aki_get(self, mock_load):
def test_285_aki_get(self, mock_load):
""" test cert_aki_get() """
cert = 'cert'
mock_load.get_extension_count.return_value = 2
Expand Down
93 changes: 53 additions & 40 deletions test/test_renewalinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_011_config_enter(self, mock_load_cfg):

@patch('acme_srv.renewalinfo.Renewalinfo._renewalinfo_generate')
@patch('acme_srv.renewalinfo.Renewalinfo._cert_dic_lookup')
def test_019_renewalinfo_get(self, mock_lookup, mock_gen):
def test_012_renewalinfo_get(self, mock_lookup, mock_gen):
""" test _renewalinfo_get() """
mock_gen.return_value = {'foo': 'bar'}
self.assertEqual({'foo': 'bar'}, self.renewalinfo._renewalinfo_get('1a2b3c4d5e6f'))
Expand All @@ -170,54 +170,67 @@ def test_019_renewalinfo_get(self, mock_lookup, mock_gen):
@patch('acme_srv.renewalinfo.Renewalinfo._renewalinfo_get')
@patch('acme_srv.renewalinfo.Renewalinfo._renewalinfo_string_get')
@patch('acme_srv.renewalinfo.Renewalinfo._cert_table_update')
def test_020_get(self, mock_update, mock_renstr_get, mock_renget):
def test_013_get(self, mock_update, mock_renstr_get, mock_renget):
""" test get() """
mock_renget.return_value = {'foo': 'bar'}
mock_renstr_get.return_value = 'mock_renstr_get'
self.renewalinfo.dbstore.hkparameter_get.return_value = None
self.assertEqual({'code': 200, 'data': {'foo': 'bar'}, 'header': {'Retry-After': '86400'}}, self. renewalinfo.get('url'))
self.assertTrue(mock_update.called)

@patch('acme_srv.renewalinfo.Renewalinfo._renewalinfo_get')
@patch('acme_srv.renewalinfo.Renewalinfo._renewalinfo_string_get')
@patch('acme_srv.renewalinfo.Renewalinfo._cert_table_update')
def test_022_get(self, mock_update, mock_renstr_get, mock_renget):
def test_014_get(self, mock_update, mock_renstr_get, mock_renget):
""" test get() """
mock_renget.return_value = {'foo': 'bar'}
mock_renstr_get.return_value = 'mock_renstr_get'
self.renewalinfo.dbstore.hkparameter_get.return_value = {'foo': 'bar'}
self.assertEqual({'code': 200, 'data': {'foo': 'bar'}, 'header': {'Retry-After': '86400'}}, self. renewalinfo.get('url'))
self.assertFalse(mock_update.called)

@patch('acme_srv.renewalinfo.Renewalinfo._renewalinfo_get')
@patch('acme_srv.renewalinfo.Renewalinfo._renewalinfo_string_get')
@patch('acme_srv.renewalinfo.Renewalinfo._cert_table_update')
def test_015_get(self, mock_update, mock_renstr_get, mock_renget):
""" test get() """
mock_renget.return_value = None
self.renewalinfo.dbstore.hkparameter_get.return_value = None
self.assertEqual({'code': 404, 'data': 'urn:ietf:params:acme:error:malformed'}, self. renewalinfo.get('url'))
self.assertTrue(mock_update.called)
self.assertTrue(mock_renstr_get.called)

@patch('acme_srv.message.Message.check')
def test_023_update(self, mock_mcheck):
def test_016_update(self, mock_mcheck):
""" test update() """
mock_mcheck.return_value = (400, 'message', 'detail', 'protected', 'payload', 'account_name')
self.assertEqual({'code': 400}, self.renewalinfo.update('content'))

@patch('acme_srv.message.Message.check')
def test_024_update(self, mock_mcheck):
def test_017_update(self, mock_mcheck):
""" test update() """
mock_mcheck.return_value = (200, 'message', 'detail', 'protected', {'certid': 'certid'}, 'account_name')
self.assertEqual({'code': 400}, self.renewalinfo.update('content'))

@patch('acme_srv.renewalinfo.Renewalinfo._cert_dic_lookup')
@patch('acme_srv.message.Message.check')
def test_025_update(self, mock_mcheck, mock_lookup):
def test_018_update(self, mock_mcheck, mock_lookup):
""" test update() """
mock_mcheck.return_value = (200, 'message', 'detail', 'protected', {'certid': 'certid', 'replaced': True}, 'account_name')
mock_lookup.return_value = None
self.assertEqual({'code': 400}, self.renewalinfo.update('content'))

@patch('acme_srv.renewalinfo.Renewalinfo._cert_dic_lookup')
@patch('acme_srv.message.Message.check')
def test_026_update(self, mock_mcheck, mock_lookup):
def test_019_update(self, mock_mcheck, mock_lookup):
""" test update() """
mock_mcheck.return_value = (200, 'message', 'detail', 'protected', {'certid': 'certid', 'replaced': False}, 'account_name')
mock_lookup.return_value = {'foo': 'bar'}
self.assertEqual({'code': 400}, self.renewalinfo.update('content'))

@patch('acme_srv.renewalinfo.Renewalinfo._cert_dic_lookup')
@patch('acme_srv.message.Message.check')
def test_027_update(self, mock_mcheck, mock_lookup):
def test_020_update(self, mock_mcheck, mock_lookup):
""" test update() """
mock_mcheck.return_value = (200, 'message', 'detail', 'protected', {'certid': 'certid', 'replaced': True}, 'account_name')
mock_lookup.return_value = {'foo': 'bar'}
Expand All @@ -226,28 +239,28 @@ def test_027_update(self, mock_mcheck, mock_lookup):

@patch('acme_srv.renewalinfo.Renewalinfo._cert_dic_lookup')
@patch('acme_srv.message.Message.check')
def test_028_update(self, mock_mcheck, mock_lookup):
def test_021_update(self, mock_mcheck, mock_lookup):
""" test update() """
mock_mcheck.return_value = (200, 'message', 'detail', 'protected', {'certid': 'certid', 'replaced': True}, 'account_name')
mock_lookup.return_value = {'foo': 'bar'}
self.renewalinfo.dbstore.certificate_add.return_value = 1
self.assertEqual({'code': 200}, self.renewalinfo.update('content'))

def test_029_renewalinfo_string_get(self):
def test_022_renewalinfo_string_get(self):
""" test update() """
self.renewalinfo.server_name = 'http://server.name'
self.renewalinfo.path_dic = {'renewalinfo': '/renewalinfo'}
input_string = 'http://server.name/renewalinfo/foo'
self.assertEqual('foo', self.renewalinfo._renewalinfo_string_get(input_string))

def test_030_renewalinfo_string_get(self):
def test_023_renewalinfo_string_get(self):
""" test update() """
self.renewalinfo.server_name = 'http://server.name'
self.renewalinfo.path_dic = {'renewalinfo': '/renewalinfo'}
input_string = 'http://server.name/renewalinfofoo'
self.assertEqual('foo', self.renewalinfo._renewalinfo_string_get(input_string))

def test_031_renewalinfo_string_get(self):
def test_024_renewalinfo_string_get(self):
""" test update() """
self.renewalinfo.server_name = 'http://server.name'
self.renewalinfo.path_dic = {'renewalinfo': '/renewalinfo/'}
Expand All @@ -258,7 +271,7 @@ def test_031_renewalinfo_string_get(self):
@patch('acme_srv.renewalinfo.Renewalinfo._draft01_lookup')
@patch('acme_srv.renewalinfo.certid_hex_get')
@patch('acme_srv.renewalinfo.Renewalinfo._serial_aki_get')
def test_032_cert_dic_lookup(self, mock_aki, mock_certid, mock_draft01, mock_draft02):
def test_025_cert_dic_lookup(self, mock_aki, mock_certid, mock_draft01, mock_draft02):
""" test _cert_dic_lookup() """
mock_aki.return_value = ('serail', 'aki')
mock_draft01.return_value = {'foo': 'draft01'}
Expand All @@ -273,7 +286,7 @@ def test_032_cert_dic_lookup(self, mock_aki, mock_certid, mock_draft01, mock_dra
@patch('acme_srv.renewalinfo.Renewalinfo._draft01_lookup')
@patch('acme_srv.renewalinfo.certid_hex_get')
@patch('acme_srv.renewalinfo.Renewalinfo._serial_aki_get')
def test_033_cert_dic_lookup(self, mock_aki, mock_certid, mock_draft01, mock_draft02):
def test_026_cert_dic_lookup(self, mock_aki, mock_certid, mock_draft01, mock_draft02):
""" test _cert_dic_lookup() """
mock_aki.return_value = ('serail', 'aki')
mock_certid.return_value = ('mda', 'certid')
Expand All @@ -285,31 +298,31 @@ def test_033_cert_dic_lookup(self, mock_aki, mock_certid, mock_draft01, mock_dra
self.assertTrue(mock_draft01.called)
self.assertFalse(mock_draft02.called)

def test_034_draft01_lookup(self):
def test_027_draft01_lookup(self):
""" test _draft01_lookup() """
self.renewalinfo.dbstore.certificate_lookup.return_value = {'foo': 'bar'}
self.assertEqual({'foo': 'bar'}, self.renewalinfo._draft01_lookup('certid_hex'))

def test_035_draft01_lookup(self):
def test_028_draft01_lookup(self):
""" test _draft01_lookup() """
self.renewalinfo.dbstore.certificate_lookup.side_effect = Exception('cert_lookup')
with self.assertLogs('test_a2c', level='INFO') as lcm:
self.assertFalse(self.renewalinfo._draft01_lookup('certid_hex'))
self.assertIn('CRITICAL:test_a2c:acme2certifier database error in Renewalinfo._draft01_lookup(): cert_lookup', lcm.output)

def test_036_draft02_lookup(self):
def test_029_draft02_lookup(self):
""" test _draft02_lookup() """
self.renewalinfo.dbstore.certificates_search.return_value = [{'foo': 'bar01', 'aki': 'aki01'}, {'foo': 'bar02', 'aki': 'aki02'}]
self.assertEqual({'aki': 'aki01', 'foo': 'bar01'}, self.renewalinfo._draft02_lookup('serial', 'aki01'))

def test_037_draft02_lookup(self):
def test_030_draft02_lookup(self):
""" test _draft02_lookup() """
self.renewalinfo.dbstore.certificates_search.return_value = [{'foo': 'bar01', 'aki': 'aki01'}, {'foo': 'bar02', 'aki': 'aki02'}]
self.assertEqual({'aki': 'aki02', 'foo': 'bar02'}, self.renewalinfo._draft02_lookup('serial', 'aki02'))

@patch('acme_srv.renewalinfo.cert_aki_get')
@patch('acme_srv.renewalinfo.cert_serial_get')
def test_038_cert_table_update(self, mock_serial, mock_aki):
def test_031_cert_table_update(self, mock_serial, mock_aki):
""" test _cert_table_update() """
self.renewalinfo.dbstore.certificates_search.return_value = [{'foo': 'bar', 'cert_raw': 'cert_raw', 'name': 'name', 'cert': 'cert'}]
self.assertFalse(self.renewalinfo._cert_table_update())
Expand All @@ -318,7 +331,7 @@ def test_038_cert_table_update(self, mock_serial, mock_aki):

@patch('acme_srv.renewalinfo.cert_aki_get')
@patch('acme_srv.renewalinfo.cert_serial_get')
def test_039_cert_table_update(self, mock_serial, mock_aki):
def test_032_cert_table_update(self, mock_serial, mock_aki):
""" test _cert_table_update() """
self.renewalinfo.dbstore.certificates_search.return_value = [{'foo': 'bar', 'cert_raw': None, 'name': 'name', 'cert': 'cert'}]
self.assertFalse(self.renewalinfo._cert_table_update())
Expand All @@ -327,37 +340,37 @@ def test_039_cert_table_update(self, mock_serial, mock_aki):

@patch('acme_srv.renewalinfo.cert_aki_get')
@patch('acme_srv.renewalinfo.cert_serial_get')
def test_040_cert_table_update(self, mock_serial, mock_aki):
def test_033_cert_table_update(self, mock_serial, mock_aki):
""" test _cert_table_update() """
self.renewalinfo.dbstore.certificates_search.return_value = [{'foo': 'bar', 'name': 'name', 'cert': 'cert'}]
self.assertFalse(self.renewalinfo._cert_table_update())
self.assertFalse(mock_serial.called)
self.assertFalse(mock_aki.called)

def test_034_draft02_lookup(self):
""" test _draft02_lookup() """
self.renewalinfo.dbstore.certificates_search.return_value = [{'foo': 'bar01', 'aki': 'aki01'}, {'foo': 'bar02', 'aki': 'aki02'}]
self.assertFalse(self.renewalinfo._draft02_lookup('serial', 'aki03'))

@patch('acme_srv.renewalinfo.cert_aki_get')
@patch('acme_srv.renewalinfo.cert_serial_get')
def test_041_cert_table_update(self, mock_serial, mock_aki):
def test_035_cert_table_update(self, mock_serial, mock_aki):
""" test _cert_table_update() """
self.renewalinfo.dbstore.certificates_search.return_value = Exception('certificates_search')
self.renewalinfo.dbstore.certificates_search.side_effect = Exception('certificates_search')
with self.assertLogs('test_a2c', level='INFO') as lcm:
self.assertFalse(self.renewalinfo._cert_table_update())
self.assertIn('CRITICAL:test_a2c:acme2certifier database error in Renewalinfo._cert_table_update(): certificates_search', lcm.output)
self.assertFalse(mock_serial.called)
self.assertFalse(mock_aki.called)

def test_038_draft02_lookup(self):
""" test _draft02_lookup() """
self.renewalinfo.dbstore.certificates_search.return_value = [{'foo': 'bar01', 'aki': 'aki01'}, {'foo': 'bar02', 'aki': 'aki02'}]
self.assertFalse(self.renewalinfo._draft02_lookup('serial', 'aki03'))

def test_039_draft02_lookup(self):
def test_036_draft02_lookup(self):
""" test _draft02_lookup() """
self.renewalinfo.dbstore.certificates_search.return_value = [{'foo': 'bar01', }, {'foo': 'bar02', 'aki': 'aki02'}]
with self.assertLogs('test_a2c', level='INFO') as lcm:
self.assertFalse(self.renewalinfo._draft02_lookup('serial', 'aki03'))
self.assertIn("CRITICAL:test_a2c:acme2certifier database error in Renewalinfo._draft02_lookup(): 'aki'", lcm.output)
self.assertIn('CRITICAL:test_a2c:acme2certifier database error in Renewalinfo._draft02_lookup(): certificates_search', lcm.output)

def test_040_draft02_lookup(self):
def test_037_draft02_lookup(self):
""" test _draft02_lookup() """
self.renewalinfo.dbstore.certificates_search.side_effect = Exception('certificates_search')
with self.assertLogs('test_a2c', level='INFO') as lcm:
Expand All @@ -366,7 +379,7 @@ def test_040_draft02_lookup(self):

@patch('acme_srv.renewalinfo.b64_url_recode')
@patch('acme_srv.renewalinfo.b64_decode')
def test_041_serial_aki_get(self, mock_dec, mock_rec):
def test_038_serial_aki_get(self, mock_dec, mock_rec):
""" test _serial_aki_get() """
mock_dec.side_effect = [b'aki', b'serial']
mock_rec.side_effect = ['foo1', 'foo2']
Expand All @@ -376,7 +389,7 @@ def test_041_serial_aki_get(self, mock_dec, mock_rec):

@patch('acme_srv.renewalinfo.b64_url_recode')
@patch('acme_srv.renewalinfo.b64_decode')
def test_042_serial_aki_get(self, mock_dec, mock_rec):
def test_039_serial_aki_get(self, mock_dec, mock_rec):
""" test _serial_aki_get() """
mock_dec.side_effect = [b'aki', b'serial']
mock_rec.side_effect = ['foo1', 'foo2']
Expand All @@ -386,43 +399,43 @@ def test_042_serial_aki_get(self, mock_dec, mock_rec):

@patch('acme_srv.renewalinfo.b64_url_recode')
@patch('acme_srv.renewalinfo.b64_decode')
def test_043_serial_aki_get(self, mock_dec, mock_rec):
def test_040_serial_aki_get(self, mock_dec, mock_rec):
""" test _serial_aki_get() """
mock_dec.side_effect = [b'aki', b'serial']
mock_rec.side_effect = ['foo1', 'foo2']
self.assertEqual((None, None), self.renewalinfo._serial_aki_get('renewalinfo'))
self.assertFalse(mock_dec.called)
self.assertFalse(mock_rec.called)

def test_014_renewalinfo_generate(self):
def test_041_renewalinfo_generate(self):
""" test _renewalinfo_generate() """
self.assertFalse(self.renewalinfo._renewalinfo_generate({}))

def test_015_renewalinfo_generate(self):
def test_042_renewalinfo_generate(self):
""" test _renewalinfo_generate() """
cert_dic = {'foo': 'bar'}
self.assertFalse(self.renewalinfo._renewalinfo_generate(cert_dic))

def test_016_renewalinfo_generate(self):
def test_043_renewalinfo_generate(self):
""" test _renewalinfo_generate() """
cert_dic = {'expire_uts': 0}
self.assertFalse(self.renewalinfo._renewalinfo_generate(cert_dic))

def test_017_renewalinfo_generate(self):
def test_044_renewalinfo_generate(self):
""" test _renewalinfo_generate() """
cert_dic = {'expire_uts': 1000, 'issue_uts': 100}
self.assertEqual({'suggestedWindow': {'start': '1970-01-01T00:14:25Z', 'end': '1970-01-01T00:16:40Z'}}, self.renewalinfo._renewalinfo_generate(cert_dic))

@patch('acme_srv.renewalinfo.uts_now')
def test_018_renewalinfo_generate(self, mock_uts):
def test_045_renewalinfo_generate(self, mock_uts):
""" test _renewalinfo_generate() """
mock_uts.return_value = 100
cert_dic = {'expire_uts': 1000}
self.assertEqual({'suggestedWindow': {'start': '1970-01-01T00:14:25Z', 'end': '1970-01-01T00:16:40Z'}}, self.renewalinfo._renewalinfo_generate(cert_dic))
self.assertTrue(mock_uts.called)

@patch('acme_srv.renewalinfo.uts_now')
def test_019_renewalinfo_generate(self, mock_uts):
def test_046_renewalinfo_generate(self, mock_uts):
""" test _renewalinfo_generate() """
mock_uts.return_value = 86400000
cert_dic = {'expire_uts': 1000, 'issue_uts': 200}
Expand Down

0 comments on commit efc07db

Please sign in to comment.