diff --git a/iiif_validator/tests/cors.py b/iiif_validator/tests/cors.py index d8547f4..dd6cada 100644 --- a/iiif_validator/tests/cors.py +++ b/iiif_validator/tests/cors.py @@ -1,4 +1,4 @@ -from .test import BaseTest +from .test import BaseTest, ValidatorError class Test_Cors(BaseTest): label = 'Cross Origin Headers' @@ -14,5 +14,6 @@ def run(self, result): if k.lower() == 'access-control-allow-origin': cors = v break - self.validationInfo.check('CORS', cors, '*', result, 'Failed to get correct CORS header.') + if cors != '*' and cors != result.get_request_origin(): + raise ValidatorError('cors', cors, '*', result, 'Failed to match Access-Control-Allow-Origin response header') return result diff --git a/iiif_validator/tests/format_jp2.py b/iiif_validator/tests/format_jp2.py index ba5bc12..4833206 100644 --- a/iiif_validator/tests/format_jp2.py +++ b/iiif_validator/tests/format_jp2.py @@ -30,12 +30,10 @@ def run(self, result): if wh.getcode() != 200: raise ValidatorError('format', 'http response code: {}'.format(wh.getcode()), url, result, 'Failed to retrieve jp2, got response code {}'.format(wh.getcode())) - with magic.Magic() as m: - print ('test') - info = m.id_buffer(img) - if not info.startswith('JPEG 2000'): - # Not JP2 - raise ValidatorError('format', info, 'JPEG 2000', result) - else: - result.tests.append('format') - return result + info = magic.from_buffer(img[:1024]) + if not info.startswith('JPEG 2000'): + # Not JP2 + raise ValidatorError('format', info, 'JPEG 2000', result) + else: + result.tests.append('format') + return result diff --git a/iiif_validator/tests/format_webp.py b/iiif_validator/tests/format_webp.py index 9950e04..4319ae0 100644 --- a/iiif_validator/tests/format_webp.py +++ b/iiif_validator/tests/format_webp.py @@ -25,7 +25,7 @@ def run(self, result): raise ValidatorError('format', 'http response code: {}'.format(error.code), url, result, 'Failed to retrieve webp, got response code {}'.format(error.code)) img = wh.read() wh.close() - if img[8:12] != "WEBP": + if img[8:12] != b'WEBP': raise ValidatorError('format', 'unknown', 'WEBP', result) else: result.tests.append('format') diff --git a/iiif_validator/validator.py b/iiif_validator/validator.py index 37f7210..9ea07f0 100644 --- a/iiif_validator/validator.py +++ b/iiif_validator/validator.py @@ -178,12 +178,10 @@ def parse_links(self, header): elif state == "uri": uri = [] d = data.pop(0) - while d != ";": + while d != ">": uri.append(d) d = data.pop(0) uri = ''.join(uri) - uri = uri[:-1] - data.insert(0, ';') # Not an error to have the same URI multiple times (I think!) if (uri not in links): links[uri] = {} @@ -255,9 +253,12 @@ def get_uri_for_rel(self, links, rel): return uri return None + def get_request_origin(self): + return "http://iiif.io" + def fetch(self, url): # Make it look like a real browser request - HEADERS = {"Origin": "http://iiif.io/", + HEADERS = {"Origin": self.get_request_origin(), "Referer": "http://iiif.io/api/image/validator", "User-Agent": "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3pre) Gecko/20081130 Minefield/3.1b3pre"} req = Request(url, headers=HEADERS)