Commit graph

107 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
Velichka Atanasova
d8b3554662 Remove use of six
Remove use of six

Signed-off-by: Velichka Atanasova <avelichka@vmware.com>

Replace the use of dict.items(mydict) with mydict.items(), dict.keys(mydict) with mydict.keys() and dict.values(mydict) with mydict.values()

Signed-off-by: Velichka Atanasova <avelichka@vmware.com>

Replace 'import urllib' and 'import urllib.x' with 'from urllib import x' for vendor compatibility

Signed-off-by: Velichka Atanasova <avelichka@vmware.com>
2021-04-09 14:07:44 +03: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
ff8819577b Adopt sslib keygen interface encryption changes
secure-systems-lab/securesystemslib#288 changes the key generation
interface functions in such a way that it is clear if a call opens
a blocking prompt, or writes the key unencrypted. To do this two
functions are added per key type:
 - `generate_and_write_*_keypair_with_prompt`
 - `generate_and_write_unencrypted_*_keypair`

The default `generate_and_write_*_keypair` function now only allows
encrypted keys and only using a passed password. This respects the
principle of secure defaults and least surprise.

sslib#288 furthermore adds a protected
`_generate_and_write_*_keypair`, which is not exposed publicly
because it does not encrypt by default, but is more flexible and
thus convenient e.g. to consume all arguments from a key generation
command line tool such as 'repo.py'.

This commit adds the new public functions to the tuf namespace and
adopts their usage accordingly.

NOTE regarding repo.py:
This commit does not fix any problematic password behavior of
'repo.py' like default passwords, etc. (see #881). It only adopts
the sslib#288 changes to maintain the current behvior, plus
removing one glaringly obsolete password prompt.

NOTE regarding key import:
The securesystemslib private key import functions were also changed
to no longer auto-prompt for decryption passwords , TUF, however,
only exposes custom wrappers (see repository_lib) that do
auto-prompt. sslib#288 changes to the prompt texts are nevertheless
propagated to tuf and reflected in this commit.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-11-11 10:27:56 +01:00
Teodora Sechkova
27388833e8
Update test_repository_lib and test_formats
Modify test cases which use unsigned metadata.
Update test_sign_metadata to check for empty key list.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-10-02 16:05:12 +03:00
Joshua Lock
fb2eaa5f23
Merge pull request #1104 from MVrachev/silence-log-with-temp-files
Log subproceses stdout and stderr in temp files
2020-10-01 12:40:23 +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
lukpueh
e06e8e1afc
Merge pull request #1078 from joshuagl/joshuagl/existing-fileinfo
Minor error message clarifications and greater testing for generating targets metadata with existing fileinfo
2020-09-29 17:19:24 +02: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
Teodora Sechkova
b3b0c041fe
Add test for delegations update
Add a new test case in test_generate_targets_metadata
to check if targets metadata is up-to-date with its delegated
roles.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-08-26 13:53:51 +03:00
Teodora Sechkova
05a70085b2
Update failing tests for generate_targets_metadata
Tests logic is modified to accommodate for the update of the
delegations during generate_targets_metadata().

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-08-26 13:53:51 +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
5f6d1ae9c9 Fix snapshot_filename inconsistency usage
First in the generate_timestamp_metadata both "snapshot_filename"
and the constant SNAPSHOT_FILENAME are used which is redundant
and possibly confusing. There should be only one input
for the snapshot file name.

Second, when calling the generate_timestamp_metadata there are
cases when "snapshot_filename" is in reality "snapshot_file_path".
That's what led to the need for the addition of SNAPSHOT_FILENAME
when populating the "meta" field from the TIMESTAMP_SCHEMA.
For the same reason, it seems logical to me to rename snapshot_filename
to snapshot_file_path and explicitly take the snapshot file name
from it.

Third, in the _generate_and_write_metadata function the argument
"filenames" is by default None, but at the same time without check
it's considered that filenames is a dictionary which has a key
"snapshot". This is could be okay if the default "filenames" value
was not None, but in the current situation it's easy to call
"_generate_and_write_metadata" with rolename = timestamp
and forget to populate the filenames dictionary.

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
66a1f3f9e6 Remove redundant targets_filename argument
The argument targets_filename in the generate_snapshot_metadata
is redundant because the places where we are calling
generate_snapshot_metadata is by using the constant
TARGETS_FILENAME or by creating a variable with the same value
of "targets.json".

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
Joshua Lock
fe8bb1c90c Add extra tests for using existing fileinfo
Add more granular testing of positive and negative cases when generating
targets metadata with existing fileinfo dictionaries

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-07-13 22:38:41 +01:00
Teodora Sechkova
a69208c1c7
Rename get_*_metadata_filenames functions
Rename repository_lib.get_metadata_filenames() and
get_delegations_filenames() to better match their
functionality and tuf terminology.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2020-06-29 13:43:20 +03:00
Joshua Lock
5e5c598769 Support abstract storage for timestamp metadata
This was erroneously absent in PR 1024, which added support for abstract
files and directories. Resolve by adding a storage_backend argument to
generate_timestamp_metadata() and using it so that the fileinfo (hashes
and length) for the snapshot file can be generated for a snapshot
metadata file on any supported storage.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-06-03 14:16:47 +01:00
Joshua Lock
4e7b7b40ea Allow generating targets metadata for non-local storage
Utilise the abstract files and directories support to enable generating
targets metadata for files which aren't necessarily locally accessible,
rather than requiring that metadata for non-local files be provided via
existing fileinfo structures.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-05-19 22:36:17 +01: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
Joshua Lock
4487a98020 Remove redundant test logic
Support for compressed files was removed in tuf v0.10.x leaving behind
some vestiges like the test logic in test_repository_lib, which is
duplicated below and carries a redundant comment, and setting compression
on in generate_project_data.py

Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-05-12 22:16:38 +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
lukpueh
1cf085a360
Merge pull request #988 from joshuagl/joshuagl/issue-933
Remove root from snapshot
2020-03-11 14:34:09 +01:00
Joshua Lock
8f13fe5add Update tests for removal of root.json from snapshot.json
Signed-off-by: Joshua Lock <jlock@vmware.com>
2020-03-11 11:15:06 +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
1a826cb4b0 Fix tests that use non-public sslib module
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-02-06 17:40:29 +01:00
Joshua Lock
f5c168d4e6 Explicitly encode data passed to securesystemslib.keys
securesystemslib PR #162 removed implicit encoding of data to bytes
in securesystemslib.keys.[create_signature|verify_signature]

Update to encode data where required.

Signed-off-by: Joshua Lock <jlock@vmware.com>
2019-10-14 12:26:31 +02:00
Lukas Puehringer
2e6a8cd03b Remove some repository_lib wrappers for sslib
Remove only wrappers and corresponding tests that don't add any
new functionality, but blindly forward the caller to sslib, where
the same function exists and is tested.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2019-09-18 18:08:54 +02:00
lukpueh
f6bd090960
Merge pull request #912 from joshuagl/joshuagl/sslcompat
Use TUF specific formats as they have been removed from securesystemslib
2019-09-17 12:20:26 +02:00
Joshua Lock
ecb6d26206 Remove deprecated securesystemslib.formats schemas
TUF specific schemas have moved to tuf.formats, ensure they are used
throughout and remove stray references to no longer supported schemas
in securesystemslib.format

Signed-off-by: Joshua Lock <jlock@vmware.com>
2019-09-17 10:28:10 +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
chentanjun
efbe0a3489 fix-up the the -> the
Signed-off-by: chentanjun <2799194073@qq.com>
2019-09-01 22:53:02 +08:00
Vladimir Diaz
b10c9bec46
Do not test for an invalid consistent method in Windows
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-27 15:43:55 -04:00
Vladimir Diaz
6c0007d845
Replace os.stat().st_ino calls in test_repository_lib.py
os.stat().st_ino does not work as expected in Windows.

Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-27 15:04:45 -04:00
Vladimir Diaz
e6c9e441c3
Add RepositoryError exception for the unexpected Travis behavior
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-20 13:36:49 -04:00
Vladimir Diaz
52aeeec8db
Use alternative way of testing for non-EEXIST exceptions
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-20 11:27:08 -04: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
f2514bdc4d
Add copyright and license to test-related files
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2017-11-30 13:33:11 -05:00
Vladimir Diaz
3b38a268dc
Remove obsolete calls to SSL functions in unit tests
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2017-11-09 10:54:46 -05:00
Vladimir Diaz
72d7ebfd8d
Remove py26 conditional import statements 2017-09-21 17:16:29 -04:00
Vladimir Diaz
36042c1ff9
Add test condition for invalid metadata extension 2017-08-29 15:03:28 -04:00
Vladimir Diaz
60cd55229f
Remove compression logic from repository_lib.py and edit its unit tests 2017-08-25 15:38:40 -04:00
Vladimir Diaz
e4f597d2fa
Attempt to fix irregular build failure
Occasionally, the roledb and keydb modules unexpectedly encounter an already existing repository
2017-08-23 12:52:23 -04:00
Vladimir Diaz
467a1af5e9
Include missing argument to format_keyval_to_metadata() in test_repository_lib.py 2017-08-23 10:55:38 -04:00
Vladimir Diaz
4cc7c17232
Test that root.json.gz can be loaded 2017-07-13 14:40:52 -04:00
Vladimir Diaz
077313f0cb Edit remaining test cases for repository_lib.py 2017-02-08 15:15:07 -05:00
Vladimir Diaz
f9660b4797 More import statementment replacements to various modules 2017-01-10 17:05:12 -05:00