diff --git a/swh/web/api/views/identifiers.py b/swh/web/api/views/identifiers.py --- a/swh/web/api/views/identifiers.py +++ b/swh/web/api/views/identifiers.py @@ -109,12 +109,13 @@ # group swhids by their type swhids_by_type = group_swhids(swhids) # search for hashes not present in the storage - missing_hashes = set( - map(hash_to_bytes, archive.lookup_missing_hashes(swhids_by_type)) - ) + missing_hashes = { + k: set(map(hash_to_bytes, archive.lookup_missing_hashes({k: v}))) + for k, v in swhids_by_type.items() + } for swhid in swhids: - if swhid.object_id not in missing_hashes: + if swhid.object_id not in missing_hashes[swhid.object_type]: response[str(swhid)]["known"] = True return response 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 @@ -140,6 +140,26 @@ } +def test_api_known_swhid_same_hash(api_client, content): + content_ = gen_swhid(ObjectType.CONTENT, content["sha1_git"]) + # Reuse hash to make invalid directory SHWID + directory_ = gen_swhid(ObjectType.DIRECTORY, content["sha1_git"]) + + input_swhids = [ + content_, + directory_, + ] + + url = reverse("api-1-known") + + resp = check_api_post_responses(api_client, url, data=input_swhids, status_code=200) + + assert resp.data == { + content_: {"known": True}, + directory_: {"known": False}, + } + + def test_api_known_invalid_swhid(api_client): invalid_swhid_sha1 = ["swh:1:cnt:8068d0075010b590762c6cb5682ed53cb3c13de;"] invalid_swhid_type = ["swh:1:cnn:8068d0075010b590762c6cb5682ed53cb3c13deb"]