Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/tests/test_converters.py
# Copyright (C) 2015-2018 The Software Heritage developers | # Copyright (C) 2015-2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import copy | import copy | ||||
import datetime | import datetime | ||||
import os | import os | ||||
import shutil | import shutil | ||||
▲ Show 20 Lines • Show All 546 Lines • ▼ Show 20 Lines | def test_dulwich_tag_to_release_signature(self): | ||||
target=hash_to_bytes(target.decode()), | target=hash_to_bytes(target.decode()), | ||||
target_type=ObjectType.REVISION, | target_type=ObjectType.REVISION, | ||||
) | ) | ||||
assert actual_release == expected_release | assert actual_release == expected_release | ||||
@pytest.mark.parametrize("attribute", ["name", "message", "signature"]) | @pytest.mark.parametrize("attribute", ["name", "message", "signature"]) | ||||
def test_corrupt_tag(self, attribute): | def test_corrupt_tag(self, attribute): | ||||
# has a signature | |||||
sha = hash_to_bytes("46fff489610ed733d2cc904e363070dadee05c71") | sha = hash_to_bytes("46fff489610ed733d2cc904e363070dadee05c71") | ||||
target = b"641fb6e08ddb2e4fd096dcf18e80b894bf7e25ce" | target = b"641fb6e08ddb2e4fd096dcf18e80b894bf7e25ce" | ||||
message = b"some release message" | message = b"some release message" | ||||
tag = dulwich.objects.Tag() | tag = dulwich.objects.Tag() | ||||
tag.name = b"blah" | tag.name = b"blah" | ||||
tag.object = (dulwich.objects.Commit, target) | tag.object = (dulwich.objects.Commit, target) | ||||
tag.message = message | tag.message = message | ||||
tag.signature = GPGSIG | tag.signature = GPGSIG | ||||
Show All 12 Lines | def test_corrupt_tag(self, attribute): | ||||
converters.dulwich_tag_to_release(tag) | converters.dulwich_tag_to_release(tag) | ||||
if attribute == "signature": | if attribute == "signature": | ||||
setattr(tag, attribute, None) | setattr(tag, attribute, None) | ||||
tag.sha() # reset tag._needs_serialization | tag.sha() # reset tag._needs_serialization | ||||
tag._sha = original_sha # force the wrong hash | tag._sha = original_sha # force the wrong hash | ||||
with pytest.raises(converters.HashMismatch): | with pytest.raises(converters.HashMismatch): | ||||
converters.dulwich_tag_to_release(tag) | converters.dulwich_tag_to_release(tag) | ||||
def test_weird_tag(self): | |||||
"""Checks raw_manifest is set when the tag cannot fit the data model""" | |||||
# Well-formed manifest | |||||
raw_manifest = ( | |||||
b"object 641fb6e08ddb2e4fd096dcf18e80b894bf7e25ce\n" | |||||
b"type commit\n" | |||||
b"tag blah\n" | |||||
b"tagger Foo <foo@example.org> 1640191027 +0200\n\n" | |||||
b"some release message" | |||||
) | |||||
tag = dulwich.objects.Tag.from_raw_string(b"tag", raw_manifest) | |||||
assert converters.dulwich_tag_to_release(tag) == Release( | |||||
name=b"blah", | |||||
message=b"some release message", | |||||
target=hash_to_bytes("641fb6e08ddb2e4fd096dcf18e80b894bf7e25ce"), | |||||
target_type=ObjectType.REVISION, | |||||
synthetic=False, | |||||
author=Person.from_fullname(b"Foo <foo@example.org>",), | |||||
date=TimestampWithTimezone( | |||||
timestamp=Timestamp(seconds=1640191027, microseconds=0), | |||||
offset=120, | |||||
negative_utc=False, | |||||
offset_bytes=b"+0200", | |||||
), | |||||
raw_manifest=None, | |||||
) | |||||
# Mess with the offset | |||||
raw_manifest2 = raw_manifest.replace(b"+0200", b"+200") | |||||
tag = dulwich.objects.Tag.from_raw_string(b"tag", raw_manifest2) | |||||
assert converters.dulwich_tag_to_release(tag) == Release( | |||||
name=b"blah", | |||||
message=b"some release message", | |||||
target=hash_to_bytes("641fb6e08ddb2e4fd096dcf18e80b894bf7e25ce"), | |||||
target_type=ObjectType.REVISION, | |||||
synthetic=False, | |||||
author=Person.from_fullname(b"Foo <foo@example.org>",), | |||||
date=TimestampWithTimezone( | |||||
timestamp=Timestamp(seconds=1640191027, microseconds=0), | |||||
offset=120, | |||||
negative_utc=False, | |||||
offset_bytes=b"+200", | |||||
), | |||||
) | |||||
# Mess with the rest of the manifest | |||||
raw_manifest2 = raw_manifest.replace( | |||||
b"641fb6e08ddb2e4fd096dcf18e80b894bf7e25ce", | |||||
b"641FB6E08DDB2E4FD096DCF18E80B894BF7E25CE", | |||||
) | |||||
tag = dulwich.objects.Tag.from_raw_string(b"tag", raw_manifest2) | |||||
assert converters.dulwich_tag_to_release(tag) == Release( | |||||
name=b"blah", | |||||
message=b"some release message", | |||||
target=hash_to_bytes("641fb6e08ddb2e4fd096dcf18e80b894bf7e25ce"), | |||||
target_type=ObjectType.REVISION, | |||||
synthetic=False, | |||||
author=Person.from_fullname(b"Foo <foo@example.org>",), | |||||
date=TimestampWithTimezone( | |||||
timestamp=Timestamp(seconds=1640191027, microseconds=0), | |||||
offset=120, | |||||
negative_utc=False, | |||||
), | |||||
raw_manifest=b"tag 136\x00" + raw_manifest2, | |||||
) |