Skip to content

Commit

Permalink
Merge pull request #109 from IIIF/different_id
Browse files Browse the repository at this point in the history
Adding check to see if manifest id matches the published location
  • Loading branch information
glenrobson committed Dec 11, 2020
2 parents d59c7cd + 44dd672 commit 8b7aaf4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -2,9 +2,10 @@ os: linux
language: python
python:
- "2.7"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
- "3.9"
install:
- python setup.py install
- pip install coveralls
Expand Down
6 changes: 6 additions & 0 deletions iiif-presentation-validator.py
Expand Up @@ -69,6 +69,10 @@ def check_manifest(self, data, version, url=None, warnings=[]):
infojson = schemavalidator.validate(data, version, url)
for error in infojson['errorList']:
error.pop('error', None)

mf = json.loads(data)
if url and 'id' in mf and mf['id'] != url:
raise ValidationError("The manifest id ({}) should be the same as the URL it is published at ({}).".format(mf["id"], url))
except ValidationError as e:
infojson = {
'received': data,
Expand All @@ -93,6 +97,8 @@ def check_manifest(self, data, version, url=None, warnings=[]):
try:
mf = reader.read()
mf.toJSON()
if url and mf.id != url:
raise ValidationError("Manifest @id ({}) is different to the location where it was retrieved ({})".format(mf.id, url))
# Passed!
okay = 1
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_validator.py
Expand Up @@ -95,11 +95,11 @@ def test05_do_GET_test(self):
# input data works only the first time. Instead create a new request
# object to similate each web request, with data that sets request.environ
v = val_mod.Validator()
request = LocalRequest({'QUERY_STRING': 'url=https://example.org/a'})
request = LocalRequest({'QUERY_STRING': 'url=http://iiif.io/api/presentation/2.0/example/fixtures/1/manifest.json'})
v.fetch = Mock(return_value=(read_fixture('fixtures/1/manifest.json'), MockWebHandle()))
j = json.loads(v.do_GET_test())
self.assertEqual(j['okay'], 1)
self.assertEqual(j['url'], 'https://example.org/a')
self.assertEqual(j['url'], 'http://iiif.io/api/presentation/2.0/example/fixtures/1/manifest.json')
# fetch failure
v = val_mod.Validator()
request = LocalRequest({'QUERY_STRING': 'url=http://example.org/a'})
Expand Down

0 comments on commit 8b7aaf4

Please sign in to comment.