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>
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>
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>
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>
Add tests creating delegations graphs with different complexity
and successfully updating the delegated roles metadata.
Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Adds new test module that executes the basic repo example
Python script and checks that it created certain (metadata)
files.
The test module is tailored for testing similar example scripts.
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Jussi Kukkonen <jku@goto.fi>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
As a target path is a URL path it's not correct to consider it as
interchangeable with a filepath within every operation system. The
unquote is also removed as the ngclient cannot assume correctly
which encoding is intended and which not
Fixes#1483
Signed-off-by: Ivana Atanasova <iyovcheva@iyovcheva-a02.vmware.com>
This commit includes manual fixes for a lot of mypy warnings.
When there were warnings that we are calling non-annotated function
in annotated context I decided to add annotations instead of ignoring
those warnings.
That's how I end up adding annotations in the whole tests/utils.py
module.
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
In test_metadata_serialization.py "test_case_data" is actually a string
when the decorator calls the actual test functions.
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
- Add the check for empty strings in the Delegate Role name
- Remove the comprehensive lists to make the code more readable
- Remove the test for empty file name from
``test_updater_with_simulator``
Signed-off-by: Kairo de Araujo <kdearaujo@vmware.com>