diff --git a/swh/deposit/api/private/deposit_check.py b/swh/deposit/api/private/deposit_check.py
--- a/swh/deposit/api/private/deposit_check.py
+++ b/swh/deposit/api/private/deposit_check.py
@@ -79,7 +79,8 @@
return True
def _check_deposit_metadata(self, deposit):
- """Given a deposit, check each deposit request of type metadata.
+ """Given a deposit, check each deposit request of type metadata,
+ by aggregating all metadata requests one bundle.
Args:
The deposit to check metadata for.
@@ -91,11 +92,10 @@
metadata = {}
for dr in self._deposit_requests(deposit, request_type=METADATA_TYPE):
metadata.update(dr.metadata)
-
return self._check_metadata(metadata)
def _check_metadata(self, metadata):
- """Check to execute on all metadata.
+ """Check to execute on all metadata and keeps metadata_url for url validation.
Args:
metadata (): Metadata to actually check
@@ -113,8 +113,18 @@
for field in metadata
for name in possible_names)
for possible_names in required_fields)
+ urls = []
+ for field in metadata:
+ if 'url' in field:
+ urls.append(metadata[field])
+ self.metadata_url = urls
return result
+ def _check_url(self, client_url, metadata_urls):
+ validatation = any(client_url in url
+ for url in metadata_urls)
+ return validatation
+
def process_get(self, req, collection_name, deposit_id):
"""Build a unique tarball from the multiple received and stream that
content to the client.
@@ -129,6 +139,8 @@
"""
deposit = Deposit.objects.get(pk=deposit_id)
+ client_url = deposit.client.url
+ self.metadata_url = None # created in _check_metadata
problems = []
# will check each deposit's associated request (both of type
# archive and metadata) for errors
@@ -140,7 +152,11 @@
if not metadata_status:
problems.append('metadata')
- deposit_status = archives_status and metadata_status
+ url_status = self._check_url(client_url, self.metadata_url)
+ if not url_status:
+ problems.append('url')
+
+ deposit_status = archives_status and metadata_status and url_status
# if any problems arose, the deposit is rejected
if not deposit_status:
diff --git a/swh/deposit/tests/api/test_deposit_check.py b/swh/deposit/tests/api/test_deposit_check.py
--- a/swh/deposit/tests/api/test_deposit_check.py
+++ b/swh/deposit/tests/api/test_deposit_check.py
@@ -72,7 +72,8 @@
data = json.loads(response.content.decode('utf-8'))
self.assertEqual(data['status'], DEPOSIT_STATUS_REJECTED)
self.assertEqual(data['details'],
- 'Some archive(s) and metadata failed the checks.')
+ 'Some archive(s) and metadata and url ' +
+ 'failed the checks.')
deposit = Deposit.objects.get(pk=deposit.id)
self.assertEquals(deposit.status, DEPOSIT_STATUS_REJECTED)
diff --git a/swh/deposit/tests/api/test_deposit_read_metadata.py b/swh/deposit/tests/api/test_deposit_read_metadata.py
--- a/swh/deposit/tests/api/test_deposit_read_metadata.py
+++ b/swh/deposit/tests/api/test_deposit_read_metadata.py
@@ -45,7 +45,8 @@
expected_meta = {
'origin': {
- 'url': 'https://hal.test.fr/some-external-id',
+ 'url': 'https://hal-test.archives-ouvertes.fr/' +
+ 'some-external-id',
'type': 'deposit'
},
'origin_metadata': {
@@ -56,7 +57,7 @@
'provider': {
'provider_name': '',
'provider_type': 'deposit_client',
- 'provider_url': 'https://hal.test.fr/',
+ 'provider_url': 'https://hal-test.archives-ouvertes.fr/',
'metadata': {}
},
'tool': {
@@ -125,7 +126,8 @@
expected_meta = {
'origin': {
- 'url': 'https://hal.test.fr/some-external-id',
+ 'url': 'https://hal-test.archives-ouvertes.fr/' +
+ 'some-external-id',
'type': 'deposit'
},
'origin_metadata': {
@@ -136,7 +138,7 @@
'provider': {
'provider_name': '',
'provider_type': 'deposit_client',
- 'provider_url': 'https://hal.test.fr/',
+ 'provider_url': 'https://hal-test.archives-ouvertes.fr/',
'metadata': {}
},
'tool': {
diff --git a/swh/deposit/tests/common.py b/swh/deposit/tests/common.py
--- a/swh/deposit/tests/common.py
+++ b/swh/deposit/tests/common.py
@@ -101,7 +101,7 @@
1785io25c695
2017-10-07T15:17:08Z
some awesome author
- http://test.test.fr
+ https://hal-test.archives-ouvertes.fr
"""
def tearDown(self):
@@ -187,7 +187,7 @@
deposit_request_types[deposit_request_type] = drt
_name = 'hal'
- _url = 'https://hal.test.fr/'
+ _url = 'https://hal-test.archives-ouvertes.fr/'
# set collection up
_collection = DepositCollection(name=_name)
_collection.save()
@@ -261,14 +261,14 @@
1785io25c695
2017-10-07T15:17:08Z
some awesome author
- http://test.test.fr
+ https://hal-test.archives-ouvertes.fr/id
"""
self.codemeta_entry_data0 = b"""
Awesome Compiler
- http://test.test.fr
+ https://hal-test.archives-ouvertes.fr/1785io25c695
urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a
1785io25c695
2017-10-07T15:17:08Z