diff --git a/swh/web/common/utils.py b/swh/web/common/utils.py --- a/swh/web/common/utils.py +++ b/swh/web/common/utils.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2019 The Software Heritage developers +# Copyright (C) 2017-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -23,7 +23,7 @@ from swh.model.exceptions import ValidationError from swh.model.identifiers import ( persistent_identifier, parse_persistent_identifier, - CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT + CONTENT, DIRECTORY, ORIGIN, RELEASE, REVISION, SNAPSHOT ) from swh.web.common.exc import BadInputExc @@ -286,6 +286,10 @@ browse_url = reverse('browse-snapshot', url_args={'snapshot_id': object_id}, query_params=query_dict) + elif object_type == ORIGIN: + raise BadInputExc(('Origin PIDs (Persistent Identifiers) are not ' + 'publicly resolvable because they are for ' + 'internal usage only')) except ValidationError as ve: raise BadInputExc('Error when parsing identifier. %s' % ' '.join(ve.messages)) diff --git a/swh/web/tests/api/views/test_identifiers.py b/swh/web/tests/api/views/test_identifiers.py --- a/swh/web/tests/api/views/test_identifiers.py +++ b/swh/web/tests/api/views/test_identifiers.py @@ -1,4 +1,4 @@ -# Copyright (C) 2018-2019 The Software Heritage developers +# Copyright (C) 2018-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -88,3 +88,10 @@ resp = api_client.get(url) assert resp.status_code == 404, resp.data + + +def test_swh_origin_id_not_resolvable(api_client): + ori_pid = 'swh:1:ori:8068d0075010b590762c6cb5682ed53cb3c13deb' + url = reverse('api-1-resolve-swh-pid', url_args={'swh_id': ori_pid}) + resp = api_client.get(url) + assert resp.status_code == 400, resp.data diff --git a/swh/web/tests/browse/views/test_identifiers.py b/swh/web/tests/browse/views/test_identifiers.py --- a/swh/web/tests/browse/views/test_identifiers.py +++ b/swh/web/tests/browse/views/test_identifiers.py @@ -1,4 +1,4 @@ -# Copyright (C) 2018-2019 The Software Heritage developers +# Copyright (C) 2018-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -160,3 +160,12 @@ assert resp.status_code == 302 assert resp['location'] == content_browse_url + + +@given(release()) +def test_origin_id_not_resolvable(client, release): + swh_id = 'swh:1:ori:8068d0075010b590762c6cb5682ed53cb3c13deb' + url = reverse('browse-swh-id', + url_args={'swh_id': swh_id}) + resp = client.get(url) + assert resp.status_code == 400