Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[tool.black]
force-exclude="""
(tests/aggregate_tests.py|
tests/fast_server_exit.py|
tests/simple_https_server.py|
tests/simple_server.py|
tests/slow_retrieval_server.py|
tests/utils.py|
tests/test_utils.py|
tests/test_repository_lib.py|
tests/test_arbitrary_package_attack.py|
tests/test_developer_tool.py|
tests/test_download.py|
tests/test_endless_data_attack.py|
tests/test_extraneous_dependencies_attack.py|
tests/test_formats.py|
tests/test_indefinite_freeze_attack.py|
tests/test_key_revocation_integration.py|
tests/test_keydb.py|
tests/test_log.py|
tests/test_mirrors.py|
tests/test_mix_and_match_attack.py|
tests/test_multiple_repositories_integration.py|
tests/test_repository_tool.py|
tests/test_replay_attack.py|
tests/test_roledb.py|
tests/test_root_versioning_integration.py|
tests/test_sig.py|
tests/test_slow_retrieval_attack.py|
tests/test_tutorial.py|
tests/test_unittest_toolbox.py|
tests/test_updater.py|
tests/test_updater_root_rotation_integration.py|
tests/repository_data/generate_project_data.py|
tests/repository_data/generate.py)
"""
11 changes: 8 additions & 3 deletions tests/repository_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@

SPEC_VER = ".".join(SPECIFICATION_VERSION)


@dataclass
class RepositoryTarget:
"""Contains actual target data and the related target metadata"""

data: bytes
target_file: TargetFile


class RepositorySimulator(FetcherInterface):
def __init__(self):
self.md_root: Metadata[Root] = None
Expand Down Expand Up @@ -186,7 +189,7 @@ def fetch(self, url: str) -> Iterator[bytes]:
elif spliturl.path.startswith("/targets/"):
# figure out target path and hash prefix
path = spliturl.path[len("/targets/") :]
dir_parts, sep , prefixed_filename = path.rpartition("/")
dir_parts, sep, prefixed_filename = path.rpartition("/")
prefix, _, filename = prefixed_filename.partition(".")
target_path = f"{dir_parts}{sep}{filename}"

Expand All @@ -208,7 +211,9 @@ def _fetch_target(self, target_path: str, hash: Optional[str]) -> bytes:
logger.debug("fetched target %s", target_path)
return repo_target.data

def _fetch_metadata(self, role: str, version: Optional[int] = None) -> bytes:
def _fetch_metadata(
self, role: str, version: Optional[int] = None
) -> bytes:
"""Return signed metadata for 'role', using 'version' if it is given.

If version is None, non-versioned metadata is being requested
Expand Down Expand Up @@ -253,7 +258,7 @@ def _compute_hashes_and_length(
data = self._fetch_metadata(role)
digest_object = sslib_hash.digest(sslib_hash.DEFAULT_HASH_ALGORITHM)
digest_object.update(data)
hashes = {sslib_hash.DEFAULT_HASH_ALGORITHM: digest_object.hexdigest()}
hashes = {sslib_hash.DEFAULT_HASH_ALGORITHM: digest_object.hexdigest()}
return hashes, len(data)

def update_timestamp(self):
Expand Down
Loading