Commit graph

1197 commits

Author SHA1 Message Date
Martin Vrachev
b47ef92833 Fix pylint warnings
New pylint warnings appeared related to changes
in urlib3:
- tests/test_fetcher_ng.py:128: error: Argument 1 to "ReadTimeoutError"
has incompatible type "None"; expected "ConnectionPool"  [arg-type]
- tests/test_fetcher_ng.py:128: error: Argument 2 to "ReadTimeoutError"
has incompatible type "None"; expected "str"  [arg-type]
I noticed these error in this CI run:
https://github.com/theupdateframework/python-tuf/runs/4764931441?check_suite_focus=true

I fixed them by creating a urllib3.HTTPConnectionPool() instance as
the first argument and replaced the second argument with an empty
string.
This seems to do the job.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2022-01-10 19:56:29 +02:00
Ivana Atanasova
d27c0fd585 Test loading of cached metadata in ngclient
After making a successful update of valid metadata which stores it
in cache and performing a second update with a new updater while
the metadata is already stored in cache, this test verifies that
timestamp, snaphot and targets are loaded from cache and not
downloaded

Fixes #1681

Signed-off-by: Ivana Atanasova <iyovcheva@vmware.com>
2022-01-07 16:02:55 +02:00
Jussi Kukkonen
3d4df876c2
Merge pull request #1741 from sechkova/remove-updater-with-sim
Remove test_updater_with_simulator.py
2022-01-07 12:54:43 +02:00
Jussi Kukkonen
d8591e78a9
Merge pull request #1742 from kairoaraujo/issue#1713/test_fast-forward_recovery_targets
test targets fast-forward attack recovery
2022-01-07 11:23:40 +02:00
Jussi Kukkonen
b12a67c047
Merge pull request #1738 from kairoaraujo/issue#1713/test_fast-forward_recovery_snapshot
test snapshot fast-forward attack recovery
2022-01-07 10:43:55 +02:00
Joshua Lock
537a0198b4
Merge pull request #1743 from lukpueh/rm-metadata-api-bump_expiration
Metadata API: Remove Signed.bump_expiration() method
2022-01-05 12:08:24 +00:00
Kairo de Araujo
5b4a47a067 test targets fast-forward attack recovery
This test simulates the targets fast-forward attack recovery.
It simulates that the targets keys were compromised, the attacker
generated a new high version of the targets.

The repository generates new key for snapshot to rollback the
targets version to the initial version.

Signed-off-by: Kairo de Araujo <kdearaujo@vmware.com>
2022-01-04 15:14:16 +01:00
Teodora Sechkova
672df74ce8
Remove test_updater_with_simulator.py
Move the remaining
test_snapshot_rollback_with_local_snapshot_hash_mismatch
to test_updater_top_level_update.py and remove the file.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-22 13:23:36 +02:00
Teodora Sechkova
aadc6fdc70
Remove test_keys_and_signatures
Key rotations and metadata update are now extesively tested in:
- test_updater_key_rotations.py
- test_updater_top_level_update.py

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-22 13:23:35 +02:00
Teodora Sechkova
1cfa249dea
Move test_not_loading_targets_twice
Move test_not_loading_targets_twice to
test_updater_top_level_update.py.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-22 13:23:35 +02:00
Teodora Sechkova
21ad93779f
Move test_fishy_rolenames
Move test_fishy_rolenames to test_updater_delegation_graphs.py
and update the test setup.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-22 13:23:33 +02:00
Teodora Sechkova
82a68a6f95
Remove TestUpdater.test_reftesh
Remove TestUpdater.test_refresh from test_updater_with_simulator.
Testing refresh() is now extensively covered in the newly added
test_updater_top_level_update.py.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-22 13:21:58 +02:00
Teodora Sechkova
e752193088
Merge pull request #1728 from sechkova/test-fetch-target
ngtests: Test fetch target
2021-12-22 13:10:31 +02:00
Teodora Sechkova
ed15d111aa
Merge pull request #1711 from sechkova/test-targetfile-search
Extend delegations tests
2021-12-22 13:00:07 +02:00
Lukas Puehringer
9f2c593813 Metadata API: Remove Signed.bump_expiration()
Remove `bump_expiration()` method, which is unlikely to be used as
is, i.e.  bump to "current expiration date plus delta". A more
realistic use case is to bump to "now plus delta" (see #1727 for
details).

Moreover, bump_expiration can either way easily be replaced by a
one-liner expression using the 'datetime' module. A corresponding
code snippet is added to the `expires` property's docstring.  Note:
`expires` became a property with a millisec-removing setter (for
spec conformance) in  #1712, which further reduces the need for a
convenience bump_expiration method.

This patch also removes a related unit test and updates another
one.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2021-12-22 11:40:36 +01:00
Kairo de Araujo
ac7a804525 remove roles names as str, snapshot order
This commit removes the role names as strings. Also do a slight
change for clarity.

Signed-off-by: Kairo de Araujo <kdearaujo@vmware.com>
2021-12-21 14:35:33 +01:00
Teodora Sechkova
d1bc20111c
Define a TestTarget dataclass
Use a dataclass for a better representation of
the target files in the test data set.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-21 13:25:51 +02:00
Teodora Sechkova
adcaf583ef
Add test_invalid_target*
Add test cases covering downloading and loading from cache
targets with non-matching hash and length.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-21 12:57:27 +02:00
Teodora Sechkova
e513460be4
Rename and simplify test_targets
Remove parts of the test case which are covered in other
tests, this way making its purpose clearer.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-21 12:57:26 +02:00
Teodora Sechkova
7af7836537
Add tests/test_updater_fetch_target.py
Add a new test file and class for testing target files
fetching.
Move test_targets from test_updater_with_simulator.py to
tests/test_updater_fetch_targets.py.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-21 12:57:26 +02:00
Teodora Sechkova
36eaffaa64
Add TestTargetCase dataclass
Use a dataclass for a better visual representation of
the test case data set.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-21 12:12:08 +02:00
lukpueh
cc2326d3ca
Merge pull request #1736 from lukpueh/rm-metadata-api-update
Metadata API: Remove 3 'update' methods + tests
2021-12-21 10:52:32 +01:00
lukpueh
1f3654fb97
Merge pull request #1712 from ivanayov/no_microseconds_in_api_for_signed_expires
Remove microseconds from metadata API Signed.expires
2021-12-21 10:14:42 +01:00
Lukas Puehringer
f22f357934 Metadata API: Remove 3 'update' methods + tests
Remove ambiguous, unspecific, opinionated and trivial 'update'
methods, which can be replaced by feasible one-liners that assign
values directly to the object attribute to be *updated*. (see #1627
for details).

Reasons to have these methods would be increased usability in terms of
- reduced work
- immediate feedback on invalid assignments

However, given above described issues, the reasons against the
methods as they are now seem to outweigh the reasons for them.
Furthermore, it seems easier to re-add similar methods, which
addressed these issues, after the upcoming 1.0.0 release than to
remove or modify them.

This patch also removes the corresponding tests as they become
irrelevant (there is no need to test object assignment).  In the
case of the timestamp test, the removal also includes redundant
test logic, which is already tested in `test_metadata_base`.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2021-12-21 09:48:31 +01:00
Kairo de Araujo
8a8fff303a test snapshot fast-forward attack recovery
This test simulates the snapshot fast-forward attack recovery.
It simulates that the snapshot keys were compromised, the attacker
generated a new high version of the snapshot.

The repository generates new keys for snapshot and timestamp and
rollbacks the snapshot version to the initial version.

Signed-off-by: Kairo de Araujo <kdearaujo@vmware.com>
2021-12-21 09:13:02 +01:00
Teodora Sechkova
d10c8e980d
Use raw string in TestTargetFileSearch docstirng
Using a raw string allows the use of backslashes
in the docstring comment whithout them being interpreted
as an escape character.

It also silences pylint W1401: anomalous-backslash-in-string.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-20 19:04:09 +02:00
Teodora Sechkova
7eea3f908b
Add tests for invalid delegated role metadata
Extend TestDelegationsGraphs with a test case for
unsigned metadata.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-20 19:04:09 +02:00
Teodora Sechkova
6fa5d3ddd2
Add TestTargetFileSearch class
Extend test_updater_delegation_graphs.py with tests
for targets metadata search.
- create a new test class TestTargetFileSearch which creates
  a single repository and pefrorms multiple file searches in
  subtests.
- group the common functionality in a base class TestDelegations.
- extend the data classes to accomodate for target_files.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-20 19:04:08 +02:00
Teodora Sechkova
4fc2c19ba4
Modify delegations traversal loop condition
Reduce the number of variables in the while loop by using
len(visited_role_names) instead of number_of_delegations.
Include equality in the comparison with config.max_delegations
to account for visiting "targets". Shorten the commit message.

Add max number of delegations test case.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-20 19:04:06 +02:00
Kairo de Araujo
76a3e6dae2 test timestamp fast-forward attack recovery
This test simulates the timestamp fast-forward attack recovery.
It simulates that the timestamp keys were compromised, the attacker
generated a new high version of the timestamp.

The repository generates a new key and rollbacks the timestamp
version to the initial version.

Signed-off-by: Kairo de Araujo <kdearaujo@vmware.com>
2021-12-20 16:58:20 +01:00
Jussi Kukkonen
0f1fc6e33c
Merge pull request #1689 from sechkova/test_delegated_roles
Test delegation graphs
2021-12-16 11:20:20 +02:00
Ivana Atanasova
c5ace07c58 Remove miscroseconds from metadata API Signed.expires
This change removes microseconds from expiry in order to fit TUF
specification

Fixes #1678

Signed-off-by: Ivana Atanasova <iyovcheva@vmware.com>
2021-12-15 22:55:47 +02:00
Jussi Kukkonen
2a6e773323 ngclient: Rename constructor arg
metadata_dir matches metadata_base_url better.

This is an API break for anyone using named arguments.

Fixes #1638

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-12-15 13:22:24 +02:00
Teodora Sechkova
2562aff00b
Fix linter errors in tests
Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-15 12:14:20 +02:00
Teodora Sechkova
26a5f81977
Use fetch_tracker in test_graph_traversal
Replace the use of "patch" in test_graph_traversal
with the newly added fetch_tracker from RepositorySimulator.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-15 12:14:18 +02:00
Teodora Sechkova
1ba93015c3
Add --dump option to tests
Extend updater tests with the option to dump repository
metadata locally.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-15 12:12:34 +02:00
Teodora Sechkova
db0e0d6de4
Add test_updater_deleagation_graphs.py
Add tests creating delegations graphs with different complexity
and successfully updating the delegated roles metadata.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-15 12:12:32 +02:00
Jussi Kukkonen
551a10ca05
Merge pull request #1702 from MVrachev/dump-dirs
Sanitize repo simulator role names when writing
2021-12-15 11:23:06 +02:00
Martin Vrachev
181b1a7e6d Metadata API: remove dateutil requirement
I added "dateutil" as a possible argument type for
`Metadata.bump_expiration()` as we are already testing for this and
implying it should be supported.
The problem is that "dateutil" is not added as a nontest requirement
and after a discussion, we decided we don't want to add it as well.

That's why we decided to remove "dateutil" mentions from the code
and not confuse our users we support it.

We will create a separate issue discussing the validity of
`Metadata.bump_expiration()`.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-14 11:23:40 +02:00
Martin Vrachev
3a00db02a3 Sanitize repo simulator role names when writing
Sanitize the delegated rolenames in the repo simulator when dumping in
a directory the same way the ngclient does.
That's necessary because when testing fishy role names leads to an
error:
"PermissionError: [Errno 13] Permission denied: '/.json'"

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-13 14:20:38 +02:00
Teodora Sechkova
74dddf02c3
Improve clean up in subtests
Use a "try" block to catch exceptions during failing
subtests and always execute the subtest clean up code.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-10 16:04:51 +02:00
Teodora Sechkova
c77b47ee82
Modify RepositorySimulator.add_delegation
Reduce the number of function arguments and use
DelegatedRole instead.

When adding a list of delegations to the repository,
move the Targets creation inside the loop to create
a separate Targets object for each delegation.

Create a new Metadata obgect only for delegated roles
which do not exist yet in the repository.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-10 16:04:48 +02:00
Teodora Sechkova
568580701c
tests: move _cleanup_dir to utils.py
Make the method _cleanup_dir public and move it
to tests/utils.py.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-12-10 15:59:51 +02:00
Teodora Sechkova
bdf1cbbbb5
Merge pull request #1715 from jku/tests-sim-updater-bootstrap
tests: Refactor client bootstrap
2021-12-10 13:06:53 +02:00
Lukas Puehringer
d8b23f1d55 test: add missing return type hint in test method
Following parallel merges of #1700 (added new test method),
and #1710 (started running mypy on tests), ci/cd fails in the
develop branch. This is fixed in this patch.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2021-12-10 10:48:36 +01:00
lukpueh
8209189a44
Merge pull request #1700 from lukpueh/repo-examples-hbd
doc:  basic hash bin delegation repo example + test
2021-12-10 10:33:04 +01:00
Martin Vrachev
a37df2eab4 Simulator: make _fetch_{metadata,target} public
Make _fetch_metadata and _fetch_taget public by renaming them to
fetch_metadata and fetch_target.
This will allow the removal of multiple pylint disables because of
"accessing private members".

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-09 16:44:25 +02:00
Martin Vrachev
d5d0b94f62 Add logging configuration in tests/test_examples
Logging configuration is part from each test file begging from commit
03b15fb4be
We should that as well for tests/test_examples.py

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-09 16:44:25 +02:00
Martin Vrachev
22fe1e69e4 Rename old test files by adding old suffix
Rename test files testing the old code by adding an "old" suffix.
This is done, so we can easily exclude them from linting.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-09 16:44:25 +02:00
Martin Vrachev
5aa547d6b6 Address more mypy warnings on tests files
All of the changes are made manual.
The target files are only those who test the new code.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-09 16:44:24 +02:00