Commit graph

123 commits

Author SHA1 Message Date
Kainaat Singh
ec68bd9316 Remove future module #1297
Signed-off-by: Kainaat Singh <kainaatsingh93@gmail.com>

remove unwanted lines
2021-04-11 11:37:45 +02:00
Martin Vrachev
028d1bc9f7 Make "utils" import more definite
Currently, we are importing the "utils" module in tests/utils
with "import utils".
This could become a problem when there is another module with
the same general name "utils" and could lead to import mistakes.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-11-23 22:17:31 +02:00
Lukas Puehringer
846604a259 Make metadata signatures ordered by keyid
In 'repository_lib._generate_and_write_metadata' sort the set of
signing key keyids alphabetically before passing them on to signing
functions, to make the order in which signatures are added
deterministic.

This is above all beneficial for testing.

This commit also adds an exemplary test for signatures on root
metadata using the repository_tool interface to setup all the state
that required to test _generate_and_write_metadata.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-11-19 17:42:27 +01:00
Martin Vrachev
7f885d2160 Remove redundant comments from test classes
I don't see a need to leave a comment about what setupClass,
tearDownClass, setup and tearDown functions do.
There is documentation that describes that.
Additionally, the links referenced in the comments are from
Python 2 is deprecated.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-10-01 12:22:19 +03:00
Jussi Kukkonen
03b15fb4be tests: Configure logging for all test files
all test_*.py files now accept zero or more '-v' to increase tuf
logging level. The default is now ERROR.

default: ERROR
"-v":    ERROR, but unittest prints test names
"-vv":   WARNING
"-vvv":  INFO
"-vvvv": DEBUG

Example to run a single test with DEBUG level:
  python3 test_updater.py -vvvv TestUpdater.test_4_refresh

Also make test_log.py restore the log level it modifies during test.

Fixes #1093

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-09-15 21:36:50 +03:00
Jussi Kukkonen
b6661e024a tests: Remove unused imports
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-08-10 16:11:33 +03:00
Martin Vrachev
2297c4b501 Test length and hashes in create and load repo
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-07-24 19:43:51 +03:00
Martin Vrachev
5060706925 Separate targets and snapshot/timestamp schemas
This separation and refactoring is part of the change to
make length and hashes optional for timestamp and snapshot roles.

It separates FILEINFO_SCHEMA into two separate schemas:
TARGETS_FILEINFO_SCHEMA and METADATA_FILEINFO_SCHEMA.
The distinction is needed because as of version 1.0.1 of the tuf
spec targets role has mandatory length and hashes, and
snapshot and timestamp roles have a mandatory version, and optional
length and hashes.
That's why targets can't share the same schemas
as timestamp and snapshot.

Because of that schema distinction, make_fileinfo had to be too
separated into make_targets_fileinfo and make_metadata_fileinfo.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-07-24 19:43:51 +03:00
Martin Vrachev
14620b7c3c Add tests for snapshot with hashes or length
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-07-24 19:43:51 +03:00
Martin Vrachev
4742a8e335 Add tests for timestamp without hashes or length
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-07-24 14:13:34 +03:00
Jussi Kukkonen
9db013aee2 test_repository_tool: Add missing clear_all flag
Currently TestTimestamp creates custom databases but only clears the
default ones. This means next create_*db() call will fail meaning every
test after this one will fail (currently TestTimestamp happens to be
last but the effect can be seen by renaming it to TestATimestamp).

Also remove the clear_*db() calls from TestRepository::Setup(): they are
likely to be a workaround for a similar problem earlier (earlier test
failed to cleanup).

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-07-13 17:30:38 +03:00
Teodora Sechkova
73bff87b68
Update test_load_repository
Add a tests case checking if delegated Targets() objects
are loaded correctly.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-06-24 13:52:50 +03:00
Teodora Sechkova
2553dff276
Update test_load_repository
Extend test_load_repository to check if targets file info is loaded
correctly.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-06-09 16:48:53 +03:00
Joshua Lock
5d40ffa3c4
Merge pull request #1034 from joshuagl/joshuagl/abstract-files-fixes
Fix and better test abstract files and directories support
2020-06-05 13:40:21 +01:00
Joshua Lock
d9ec10e894 Test abstract storage backend support
Add a class implementing StorageBackendInterface for testhing which
mutates filenames on put()/get(), such that trying to read the expected
file paths for TUF metadata from the local filesystem doesn't find the
files.

Use this class when creating a repository and writing metadata to test
abstract files and directories support for metadata writing.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-06-03 14:16:47 +01:00
William Woodruff
1e532e825a
tests: Fill in more returned role name use
Signed-off-by: William Woodruff <william@trailofbits.com>
2020-06-01 14:22:29 -04:00
William Woodruff
4327a980cd
tests: Use newly returned role name
Signed-off-by: William Woodruff <william@trailofbits.com>
2020-06-01 14:01:46 -04:00
Joshua Lock
a187377533 Make absence of fundamental roles fatal
The specification lists four fundamental roles: root, targets, snapshot
and timestamp. Loading a repository where those roles are not present
should not be supported, therefore convert debug messages on the absence
of metadata files for these fundamental roles into a RepositoryError
exception.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-05-19 22:36:17 +01:00
Joshua Lock
0c0aaa97eb Port to new securesystemslib w abstract filesystem
Switch to using the new abstract files and directories support in
securesystemslib by taking an object which implements
securesystemslib.storage.StorageBackendInterface in the Repository
constructor, passed in by tuf.repository_tool.create_new_repository() and
tuf.repository_tool.load_repository()

The Updater class in tuf.client.updater does not specify a storage backend
and instead allows the functions in securesystemslib to perform the
default action of instantiating a LocalFilesystemBackend, that is the
updater does not currently support abstract filesystem backends and always
defaults to using local storage.

Finally we drop support for tuf.settings.CONSISTENT_METHOD as it's not as
clear how different copying modes should work when the details of the
underlying storage are abstracted away.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-05-12 22:16:50 +01:00
Teodora Sechkova
f035cf4e34
Replace os.sep with '/' in _check_path()
Use a hard-coded unix separator ('/') so that an
exception is also raised for paths starting with '/'
when executing on Windows systems.

Update test_check_path to explicitly test invalid paths
starting with Windows style separator.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-04-08 18:58:27 +03:00
Teodora Sechkova
57b40518c8
Update test_delegate_hashed_bins()
Test is updated to include checks for incorrect target paths.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-04-08 18:58:26 +03:00
Teodora Sechkova
77f5f730f3
Add and update tests for _check_path() method
- add a test for _check_path() method of Targets class.
- update all tests calling _check_path() respectively
- update test_tutorial

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-04-08 18:58:26 +03:00
Joshua Lock
c8174f5a9f Use consistent default value for num of hashed bins
delegate_hashed_bins() has a number_of_bins parameter which defaults to
1024. add_target_to_bin() and remove_target_from_bin() both have a
number_of_bins parameter with no default. This means that in the
(somewhat) unlikely case that someone is using the default
number_of_bins when creating hashed bins they will need know what that
default value is and pass it to add_target_to_bin() and
remove_target_from_bin().

In order to be consistent and simpler to use define the default number
of bins as a module level constant and use it as the default value for
the number_of_bins argument for each of:
* delegate_hashed_bins()
* add_target_to_bin()
* remove_target_from_bin()

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-04-02 21:26:24 +01:00
Joshua Lock
62e4364c59 Add a test for add_target_to_bin that adds a fileinfo
Add some additional checks to test_add_target_to_bin to ensure the code
to add a target passing a fileinfo is tested.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-04-01 12:10:58 +01:00
Joshua Lock
694da236ba Test at least one delegated bin has path_hash_prefixes
When testing delegate_hashed_bins to ensure that hash_path_prefixes
map to the generated name of the bin, also check to ensure that at least
one of the delegations contains one or more path_hash_prefixes.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-04-01 12:09:27 +01:00
Joshua Lock
01498049da Add test for repo without access to target files
Test the newly added functionality to:
* add a target to the repository without access to the target file on disk
* write targets metadata without access to target files on disk, by using
  the existing fileinfo data from the roledb

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-04-01 12:09:27 +01:00
Joshua Lock
6c69daefa2 Enable passing a fileinfo to add_target[_to_bin]()
Add an additional optional parameter to add_target() and
add_target_to_bin() which is a fileinfo object matching
tuf.formats.FILEINFO_OBJECT

This parameter and the custom parameter are mutually exclusive and
thus cannot be passed at the same time.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-04-01 12:09:18 +01:00
Joshua Lock
095fd40dcb Do not check target file exists in add_target[s]()
The file isn't strictly needed on-disk at the time add_target() and
add_targets() are called and this duplicates the check for the file's
presence in write[_all]()

By removing this check we allow extra versatility in adding targets.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-04-01 12:06:50 +01:00
Joshua Lock
ab788e306a Refactor add_target_to_bin & remove_target_from_bin
Vastly simplify the implementation, using the _get_hash() and
_find_bin_for_hash() helpers added in earlier commits.

Furthermore, enable passing of the custom parameter to
add_target_to_bin() to better match add_target()

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-04-01 12:06:50 +01:00
Joshua Lock
40d1dcfa6c Add _find_bin_for_hash() helper to repository_tool
Add a helper function to determine the name of a bin that a hashed
targetfile will be delegated to.

Based sketches by Lukas Puehringer in issues #994 & #995

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-30 19:03:52 +01:00
Joshua Lock
e2407a1f66 Simplify delegated hash bin tests
As we are adding and removing items from the hashed bins and checking
for their presence/absence it's simplest if we being with the hashed
bins initially empty.

If we pass a list of targets when we call delgate_hashed_bins() the
delegated roles have an initial set of targets delegated to them,
which complicates testing of adding then removing a target to a
delegated bin.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-26 11:10:56 +00:00
Joshua Lock
790f21fefe Test to ensure delegated bin names match prefixes
Add test to ensure delegated bin names are consistent with the hash
prefixes that are delegated to the role.

This is an implicit assumption of the current implementation, the
testing of which will enable us to modify the code with greater
confidence.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-26 11:10:50 +00:00
Joshua Lock
292b18926b Use __name__ for loggers, per convention
Replace hard-coded logger names with __name__. For the most part this just uses
the standard conventions to create the same logger hierarchy as existed before.
The only real difference is that loggers created for printing during tests are
no longer part of the 'tuf' hierarchy.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-03 10:36:39 +00:00
Lukas Puehringer
647f712f06 roledb: Make get_dirty_roles() return sorted list
roledb.get_dirty_roles(repo_name) returns the list representation
of the global _dirty_roles[repo_name] set. To make the return value
deterministic this commit sorts the list before returning it.

The commit also removes calls to sorted on the return value of
get_dirty_roles in test_roledb.py and test_repository_tool.py.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2019-12-16 15:16:24 +01:00
Sebastien Awwad
a9d7053d78 Use TUF exceptions instead of SSL exceptions where appropriate
Removal of securesystemslib exceptions that are TUF-specific
occurs in securesystemslib PR #165
https://github.com/secure-systems-lab/securesystemslib/pull/165

This commit adapts to those changes.  Exceptions that are specific
to TUF should be in TUF and not in securesystemslib.  This commit
uses those already-existing TUF exceptions instead of pointing to
securesystemslib exceptions that will be removed.

For example, securesystemslib has no notion of repositories, so
it's ridiculous to have a RepositoryError in securesystemslib and
ridiculous for TUF to use
securesystemslib.exceptions.RepositoryError.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2019-09-17 11:19:04 +02:00
Sebastien Awwad
b8828aebd7
Fix test that failed to detect issue with get_filepaths_in_directory
The test for repository_tool.get_filepaths_in_directory now expects
absolute paths, and also now tests the *results* of the function's use when
the recursive flag is on.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-08-21 12:30:25 -04:00
Vladimir Diaz
623fe6f4f3
Minor changes to indentation in test_repository_tool.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-26 11:55:33 -04:00
Vladimir Diaz
eee1ee7089
Catch errno.ENOENT raised in Windows
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-20 15:20:17 -04:00
Vladimir Diaz
cccd58484a
Fix test failure following change to add_targets()
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-13 16:58:59 -04:00
Vladimir Diaz
24a0cec633
Update unit tests affected by change to target filepaths
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-06 13:18:33 -04:00
Vladimir Diaz
3549aaaf5d
Add/edit test conditions for consistent snapshot repo
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-03-16 14:35:38 -04:00
Trishank K Kuppusamy
2f4de169e2
try fixing test per @vladimir-v-diaz
Signed-off-by: Trishank K Kuppusamy <trishank.kuppusamy@datadoghq.com>
2018-03-15 17:05:41 -04:00
Trishank K Kuppusamy
d452739017
try fixing test
Signed-off-by: Trishank K Kuppusamy <trishank.kuppusamy@datadoghq.com>
2018-03-15 16:57:14 -04:00
Vladimir Diaz
b7cb025eae
Remove test condition for delegation to 2+ roles
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-03-06 10:15:22 -05:00
Vladimir Diaz
25a8eb1312
Update test cases affected by change to delegating paths
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-02-12 17:32:29 -05:00
Vladimir Diaz
8f65fa4154
Rename license files in modules
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-02-05 11:31:19 -05:00
Vladimir Diaz
8a5475eb88
Remove or edit remaining instances of 'restricted paths'
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-01-19 14:20:38 -05:00
Vladimir Diaz
e05bcdf64c
Fix 'is' typo and revise comment about paths located in the targets dir
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-01-19 10:16:09 -05:00
Vladimir Diaz
f278d1f304
Clarify comment for delegated paths in test_repository_tool.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-01-18 16:48:25 -05:00
Vladimir Diaz
ee9a653cde
Add test conditions for non-default repoository names
Make sure non-default repository names exist before creating and loading repositories

Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-01-09 14:24:09 -05:00