Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ngclient to coverage report #1564

Merged
merged 4 commits into from
Sep 8, 2021
Merged
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
14 changes: 14 additions & 0 deletions tests/test_fetcher_ng.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ def test_http_error(self):
self.fetcher.fetch(self.url)
self.assertEqual(cm.exception.status_code, 404)

# Read timeout error
def test_read_timeout(self):
# Reduce the read socket timeout to speed up the test
# while keeping the connect timeout
default_socket_timeout = self.fetcher.socket_timeout
self.fetcher.socket_timeout = (default_socket_timeout, 0.1)
# Launch a new "slow retrieval" server sending one byte each 40s
slow_server_process_handler = utils.TestServerProcess(log=logger, server='slow_retrieval_server.py')
self.url = f"http://{utils.TEST_HOST_ADDRESS}:{str(slow_server_process_handler.port)}/{self.rel_target_filepath}"
with self.assertRaises(exceptions.SlowRetrievalError):
next(self.fetcher.fetch(self.url))

slow_server_process_handler.clean()

# Simple bytes download
def test_download_bytes(self):
data = self.fetcher.download_bytes(self.url, self.file_length)
Expand Down
30 changes: 17 additions & 13 deletions tests/test_trusted_metadata_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,24 @@ def test_out_of_order_ops(self):
self.metadata["role1"], "role1", "targets"
)

def test_root_with_invalid_json(self):
# Test loading initial root and root update
for test_func in [TrustedMetadataSet, self.trusted_set.update_root]:
# root is not json
with self.assertRaises(exceptions.RepositoryError):
test_func(b"")

def test_update_with_invalid_json(self):
# root.json not a json file at all
with self.assertRaises(exceptions.RepositoryError):
TrustedMetadataSet(b"")
# root.json is invalid
root = Metadata.from_bytes(self.metadata["root"])
root.signed.version += 1
with self.assertRaises(exceptions.RepositoryError):
TrustedMetadataSet(root.to_bytes())
# root is invalid
root = Metadata.from_bytes(self.metadata["root"])
root.signed.version += 1
with self.assertRaises(exceptions.UnsignedMetadataError):
test_func(root.to_bytes())

# update_root called with the wrong metadata type
with self.assertRaises(exceptions.RepositoryError):
self.trusted_set.update_root(self.metadata["snapshot"])
# metadata is of wrong type
with self.assertRaises(exceptions.RepositoryError):
test_func(self.metadata["snapshot"])

def test_top_level_md_with_invalid_json(self):
top_level_md = [
(self.metadata["timestamp"], self.trusted_set.update_timestamp),
(self.metadata["snapshot"], self.trusted_set.update_snapshot),
Expand All @@ -186,9 +189,10 @@ def test_update_with_invalid_json(self):
# metadata is not json
with self.assertRaises(exceptions.RepositoryError):
update_func(b"")

# metadata is invalid
md.signed.version += 1
with self.assertRaises(exceptions.RepositoryError):
with self.assertRaises(exceptions.UnsignedMetadataError):
update_func(md.to_bytes())

# metadata is of wrong type
Expand Down
Loading