Skip to content
Snippets Groups Projects
Verified Commit 0d3a0514 authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

identifiers: Raise when invalid contextual data in persistent id

Related T1104
parent 8a0cc22a
No related branches found
No related tags found
No related merge requests found
......@@ -702,6 +702,7 @@ def parse_persistent_identifier(persistent_id):
key, val = part.split('=')
persistent_id_metadata[key] = val
except Exception:
pass
msg = 'Contextual data is badly formatted, form key=val expected'
raise SWHMalformedIdentifierException(msg)
pid_data.append(persistent_id_metadata)
return dict(zip(PERSISTENT_IDENTIFIER_KEYS, pid_data))
......@@ -834,9 +834,7 @@ class SnapshotIdentifier(unittest.TestCase):
'dir', '1', '0b6959356d30f1a4e9b7f6bca59b9a336464c03d',
{
'origin': 'deb://Debian/packages/linuxdoc-tools'
}),
('swh:1:dir:0b6959356d30f1a4e9b7f6bca59b9a336464c03d;invalid;malformed', # noqa
'dir', '1', '0b6959356d30f1a4e9b7f6bca59b9a336464c03d', {})
})
]:
expected_result = {
'namespace': 'swh',
......@@ -858,6 +856,8 @@ class SnapshotIdentifier(unittest.TestCase):
'Wrong format: There should be 4 mandatory parameters'),
('swh:',
'Wrong format: There should be 4 mandatory parameters'),
('swh:1:cnt:',
'Wrong format: Identifier should be present'),
('foo:1:cnt:abc8bc9d7a6bcf6db04f476d29314f157507d505',
'Wrong format: Supported namespace is \'swh\''),
('swh:2:dir:def8bc9d7a6bcf6db04f476d29314f157507d505',
......@@ -865,8 +865,9 @@ class SnapshotIdentifier(unittest.TestCase):
('swh:1:foo:fed8bc9d7a6bcf6db04f476d29314f157507d505',
'Wrong format: Supported types are %s' % (
', '.join(PERSISTENT_IDENTIFIER_TYPES))),
('swh:1:cnt:',
'Wrong format: Identifier should be present'),
('swh:1:dir:0b6959356d30f1a4e9b7f6bca59b9a336464c03d;invalid;'
'malformed',
'Contextual data is badly formatted, form key=val expected')
]:
with self.assertRaisesRegex(
SWHMalformedIdentifierException, _error):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment