Skip to content

Commit

Permalink
[fix] #76 - correct handling of wildcard identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
grindsa committed Nov 15, 2021
1 parent 0a03993 commit 98b4b31
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
3 changes: 2 additions & 1 deletion acme_srv/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ def _authz_info(self, url):
authz_info_dic['identifier'] = {'type' : auth_info[0]['type'], 'value' : auth_info[0]['value']}
if auth_info[0]['type'] == 'TNAuthList':
tnauth = True
# add fildcard flag into authoritzation response
# add fildcard flag into authoritzation response and modify identifier
if auth_info[0]['value'].startswith('*.'):
self.logger.debug('Authorization._authz_info() - adding wildcard flag')
authz_info_dic['identifier']['value'] = auth_info[0]['value'][2:]
authz_info_dic['wildcard'] = True
else:
authz_info_dic['status'] = 'pending'
Expand Down
28 changes: 14 additions & 14 deletions test/test_authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,20 @@ def test_016_authorization__authz_info(self, mock_name, mock_uts, mock_challenge
@patch('acme_srv.challenge.Challenge.new_set')
@patch('acme_srv.authorization.uts_now')
@patch('acme_srv.authorization.generate_random_string')
def test_016_authorization__authz_info(self, mock_name, mock_uts, mock_challengeset):
def test_017_authorization__authz_info(self, mock_name, mock_uts, mock_challengeset):
""" test Authorization.auth_info() - dbstore.authorization lookup raises an exception """
mock_name.return_value = 'randowm_string'
mock_uts.return_value = 1543640400
mock_challengeset.return_value = [{'key1' : 'value1', 'key2' : 'value2'}]
self.authorization.dbstore.authorization_update.return_value = 'foo'
self.authorization.dbstore.authorization_lookup.return_value = [{'type' : 'type', 'value' : '*.bar.local', 'status__name' : 'foo'}]
result = {'expires': '2018-12-02T05:00:00Z', 'status': 'foo', 'challenges': [{'key1': 'value1', 'key2': 'value2'}], 'identifier': {'type': 'type', 'value': '*.bar.local'}, 'wildcard': True}
result = {'expires': '2018-12-02T05:00:00Z', 'status': 'foo', 'challenges': [{'key1': 'value1', 'key2': 'value2'}], 'identifier': {'type': 'type', 'value': 'bar.local'}, 'wildcard': True}
self.assertEqual(result, self.authorization._authz_info('http://tester.local/acme/authz/foo'))

@patch('acme_srv.challenge.Challenge.new_set')
@patch('acme_srv.authorization.uts_now')
@patch('acme_srv.authorization.generate_random_string')
def test_017_authorization__authz_info(self, mock_name, mock_uts, mock_challengeset):
def test_018_authorization__authz_info(self, mock_name, mock_uts, mock_challengeset):
""" test Authorization.auth_info() in case auth_lookup failed """
mock_name.return_value = 'randowm_string'
mock_uts.return_value = 1543640400
Expand All @@ -210,7 +210,7 @@ def test_017_authorization__authz_info(self, mock_name, mock_uts, mock_challenge
@patch('acme_srv.challenge.Challenge.new_set')
@patch('acme_srv.authorization.uts_now')
@patch('acme_srv.authorization.generate_random_string')
def test_018_authorization__authz_info(self, mock_name, mock_uts, mock_challengeset):
def test_019_authorization__authz_info(self, mock_name, mock_uts, mock_challengeset):
""" test Authorization.auth_info() - dbstore.authorization lookup raises an exception """
mock_name.return_value = 'randowm_string'
mock_uts.return_value = 1543640400
Expand All @@ -224,7 +224,7 @@ def test_018_authorization__authz_info(self, mock_name, mock_uts, mock_challenge
@patch('acme_srv.challenge.Challenge.new_set')
@patch('acme_srv.authorization.uts_now')
@patch('acme_srv.authorization.generate_random_string')
def test_019_authorization__authz_info(self, mock_name, mock_uts, mock_challengeset):
def test_020_authorization__authz_info(self, mock_name, mock_uts, mock_challengeset):
""" test Authorization.auth_info() - dbstore.authorization lookup raises an exception """
mock_name.return_value = 'randowm_string'
mock_uts.return_value = 1543640400
Expand All @@ -236,14 +236,14 @@ def test_019_authorization__authz_info(self, mock_name, mock_uts, mock_challenge
self.assertIn('ERROR:test_a2c:acme2certifier database error in Authorization._authz_info(): exc_authz_lookup', lcm.output)

@patch('acme_srv.authorization.Authorization._config_load')
def test_020__enter__(self, mock_cfg):
def test_021__enter__(self, mock_cfg):
""" test enter """
mock_cfg.return_value = True
self.authorization.__enter__()
self.assertTrue(mock_cfg.called)

@patch('acme_srv.authorization.load_config')
def test_021_config_load(self, mock_load_cfg):
def test_022_config_load(self, mock_load_cfg):
""" test _config_load """
parser = configparser.ConfigParser()
mock_load_cfg.return_value = parser
Expand All @@ -252,7 +252,7 @@ def test_021_config_load(self, mock_load_cfg):
self.assertEqual(86400, self.authorization.validity )

@patch('acme_srv.authorization.load_config')
def test_022_config_load(self, mock_load_cfg):
def test_023_config_load(self, mock_load_cfg):
""" test _config_load """
parser = configparser.ConfigParser()
parser['Authorization'] = {'foo': 'bar'}
Expand All @@ -262,7 +262,7 @@ def test_022_config_load(self, mock_load_cfg):
self.assertEqual(86400, self.authorization.validity )

@patch('acme_srv.authorization.load_config')
def test_023_config_load(self, mock_load_cfg):
def test_024_config_load(self, mock_load_cfg):
""" test _config_load """
parser = configparser.ConfigParser()
parser['Authorization'] = {'expiry_check_disable': False}
Expand All @@ -272,7 +272,7 @@ def test_023_config_load(self, mock_load_cfg):
self.assertEqual(86400, self.authorization.validity )

@patch('acme_srv.authorization.load_config')
def test_024_config_load(self, mock_load_cfg):
def test_025_config_load(self, mock_load_cfg):
""" test _config_load """
parser = configparser.ConfigParser()
parser['Authorization'] = {'expiry_check_disable': True}
Expand All @@ -282,7 +282,7 @@ def test_024_config_load(self, mock_load_cfg):
self.assertEqual(86400, self.authorization.validity )

@patch('acme_srv.authorization.load_config')
def test_025_config_load(self, mock_load_cfg):
def test_026_config_load(self, mock_load_cfg):
""" test _config_load """
parser = configparser.ConfigParser()
parser['Authorization'] = {'validity': 60}
Expand All @@ -292,7 +292,7 @@ def test_025_config_load(self, mock_load_cfg):
self.assertEqual(60, self.authorization.validity )

@patch('acme_srv.authorization.load_config')
def test_026_config_load(self, mock_load_cfg):
def test_027_config_load(self, mock_load_cfg):
""" test _config_load """
parser = configparser.ConfigParser()
parser['Authorization'] = {'validity': 'foo'}
Expand All @@ -304,7 +304,7 @@ def test_026_config_load(self, mock_load_cfg):
self.assertIn('WARNING:test_a2c:Authorization._config_load(): failed to parse validity: foo', lcm.output)

@patch('acme_srv.authorization.load_config')
def test_027_config_load(self, mock_load_cfg):
def test_028_config_load(self, mock_load_cfg):
""" test _config_load """
parser = configparser.ConfigParser()
parser['Directory'] = {'url_prefix': 'url_prefix'}
Expand All @@ -315,7 +315,7 @@ def test_027_config_load(self, mock_load_cfg):
self.assertEqual({'authz_path': 'url_prefix/acme/authz/'}, self.authorization.path_dic)

@patch('acme_srv.authorization.Authorization._authz_info')
def test_028_new_get(self, mock_info):
def test_029_new_get(self, mock_info):
""" new get """
mock_info.return_value = 'foo'
result = {'code': 200, 'data': 'foo', 'header': {}}
Expand Down

0 comments on commit 98b4b31

Please sign in to comment.