Commit graph

1177 commits

Author SHA1 Message Date
Teodora Sechkova
ed15d111aa
Merge pull request #1711 from sechkova/test-targetfile-search
Extend delegations tests
2021-12-22 13:00:07 +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
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
Martin Vrachev
8d73330f86 Address more pylint 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:13:14 +02:00
Martin Vrachev
a728717eda Fix more black warnings on test files
The changes are automatic linting fixes from black.
The target files are only those who test the new code.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-09 15:52:40 +02:00
Jussi Kukkonen
b34d1b494e tests: Refactor client bootstrap
Setting up the client (when using RepositorySimulator) can be a bit
cleaner.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-12-09 09:45:45 +02:00
Jussi Kukkonen
d3b877b38a
Merge pull request #1705 from kairoaraujo/issue#1682/repositorysimulator-fetch-tracker
Implemented fetch_tracker to RepositorySimulator
2021-12-08 15:39:00 +02:00
Jussi Kukkonen
942e6d25ab
Merge pull request #1691 from MVrachev/key-rotations
Tests: add tests for non-root key rotations
2021-12-08 11:07:59 +02:00
Kairo de Araujo
35cbc3e21e Implemented fetch_tracker to RepositorySimulator
This commit implements a feature in Repository Simulator to
track the fetch calls to the metadata and targets. This feature was
mentioned in PR #1666 that generated issue #1682.
This commit adds RepositorySimulator.fetch_tracker. It also changes
the tests/test_updater_consistent_snapshot.py to use the
fetch_tracker instead of using mock.

It implements a dataclass that stores the calls to fetch metadata
(_fetch_metadata) in fetch_tracker.metadata and targets
(_fetch_targets) in fetch_tracker.targets.

The fetch calls for metadata, and targets are stored as lists.

Signed-off-by: Kairo de Araujo <kdearaujo@vmware.com>
2021-12-08 09:57:38 +01:00
Jussi Kukkonen
9ff5bfcff8
Merge pull request #1695 from ivanayov/repository_simulator_inconsistent_metafile_hashes
Fix inconsistent behaviour of compute_metafile_hashes_length
2021-12-07 14:08:22 +02:00
Martin Vrachev
d748bd3ed9 Apply black on tests/aggregate_tests.py
All changes are automatically generated by black.
The other linters didn't find any errors in the file.
It's expected that most if not all code in aggregate_tests.py will be
useful even when we remove the tests file on the old code.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-07 11:51:23 +02:00
Martin Vrachev
028b7592a0 Apply linters on tests/simple_server.py
Apply all 4 linters on tests/simple_server.py, so we can lint it in the
future and not rename and exclude it.
As we are going to use part or most of tests/utils.py after we remove
the test files testing the old code, then we would need to keep the
simple_server.py file. It's currently used in tests/updater_ng.py
testing the new updater implementation.

Black and isort changes where automatically made.
The only manual changes are:
- pylint disable once in can_connect
- add type annotations
- simplifications around setting up the handler variable
- function docstrings

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-07 11:51:23 +02:00
Martin Vrachev
580fd4d2a8 Apply linters on tests/test_utils.py
Apply all 4 linters on tests/test_utils.py, so we can lint it in the
future and not rename and exclude it.
As we are going to use part or most of tests/utils.py after we remove
the test files testing the old code, then we would need to keep the
test file testing utils.py - test_utils.py

Black and isort changes where automatically made.
The only manual changes are:
- pylint disable once in can_connect
- remove TestServerProcess.tearDown and instead clean it manually in the
tests, so we don't have to define server_process_handler as a class
variable and assert it's type in every test
- move can_connect outside TestServerProcess as it doesn't use self
anymore
- add type annotations
- function docstrings

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-03 23:04:33 +02:00
Ivana Atanasova
71a7f11bd4 Fix inconsistent behaviour of compute_metafile_hashes_length
Previously when `compute_metafile_hashes_length` was set to `False`
`update_timestamp` did not set the hash and length values to `None`
as expected. This change fixes that, so they are not `None` when
`compute_metafile_hashes_length=True` and `None` when
`compute_metafile_hashes_length=False`

Signed-off-by: Ivana Atanasova <iyovcheva@vmware.com>
2021-12-03 18:18:58 +02:00
Martin Vrachev
d203834e5c Apply linters on tests/utils.py
Apply all 4 linters on tests/utils.py, so we can lint it in future and
not rename and exclude it.
It's expected that most if not all code in tests/utils.py will be
useful even when we remove the tests file on the old code.
Keep in mind when reviewing that type annotations where already added
in e2deff3148

Black and isort changes where automatically made.
The only manual changes are:
- pylint disables
- function docstrings
- initializations of attributes of "TestServerProcess" __init__()
- additional asserts of the attributes types

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-03 18:17:33 +02:00
Lukas Puehringer
e90acfe123 doc: basic hash bin delegation repo example + test
As 'repository_tool' and 'repository_lib' are being deprecated,
hash bin delegation interfaces are no longer available in this
implementation. The example code in this file demonstrates how to
easily implement those interfaces, and how to use them together
with the TUF metadata API, to perform hash bin delegation.

Note, the hash bin delegation logic in this example is largely
copied from repository_{lib, tool}, and modernized and simplified
for this purpose.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2021-12-03 10:33:24 +01:00
Martin Vrachev
3def667844 Tests decorator: save case name
Save the case name in the "unittest.TestCase" object when executing
test cases through the "run_sub_tests_with_dataset" decorator.
This allows dumping directories with names specific to the test case
that can be used for debugging as showed in
test_updater_key_rotations.py

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-02 15:40:30 +02:00
Martin Vrachev
8daf60d011 Tests: add tests for non-root key rotations
The amount of non-root key rotations is lower than the one for root as
the repository stores all root versions in order to be able to do
rollback check compared to timestamp, snapshot, and targets where it
stores only one version.

All of the root roles are needed in those tests again as root
delegates the keys for each of the other three top-level metadata roles.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-02 15:40:29 +02:00
Martin Vrachev
0235337119 test key-rotations: setup & teardown to class func
Make setup and teardown classmethods. There is no reason why we would
want to create the signers and keys for each test case and this only
slows the test module execution.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-02 15:39:19 +02:00
Martin Vrachev
2c03f6d1fe Rename expected_result to expected_error
Rename expected_result to expected_error as the value expected is never
a true result in the current test cases, but it's an expected error.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-02 15:39:19 +02:00
Martin Vrachev
68db62d827 Rename RootVersions to MdVersions
RootVersions can be used for key rotation tests beside root and as such
it makes sense to rename it to something more generic.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-12-02 15:39:19 +02:00
Ivana Atanasova
00589f08e3 Apply top-level rolenames constants in tests
This applies the use of constants of top-level rolenames in the
tests instead of the previously hardcoded strings.
Fixes #1648

Signed-off-by: Ivana Atanasova <iyovcheva@iyovcheva-a02.vmware.com>
2021-12-02 12:25:48 +02:00
Jussi Kukkonen
bca1e67adc
Merge pull request #1686 from ivanayov/ivanayov/remove_url_normalisation
Remove URL normalisation
2021-11-30 10:02:45 +02:00