Commit graph

44 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
Martin Vrachev
946d11bca4 Make confined_target_dirs optional field
The field confined_target_dirs from the MIRROR_SCHEMA  is
a list of strings. Those strings define the accessible target
paths for that mirror. For one target to be available for that mirror,
its path should have as a prefix at least one of the strings defined
in confined_target_dirs.

That's why when confined_target_dirs is a list with one element empty
string (e.g. ['']) this means all targets files on that mirror are
available and if confined_target_dirs is empty list (e.g. []) this
would be interpreted as none of the target files is available.

This is a confusing API that could easily lead to mistakes.
That's why it's better we promote to not set confined_target_dirs
at all if a user wants targets to be available.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2020-10-16 15:35:24 +03:00
Jussi Kukkonen
2f69986e2b Remove iso8601 dependency
Our 'expires' strings are constrained by the ISO8601_DATETIME_SCHEMA
which matches regex '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z'. This can be
parsed with just a datetime.strptime(): iso8601 module is not needed.

* Add formats.expiry_string_to_datetime() helper function
* Modify the 3 locations that used iso8601 and the api/metadata.py usage
  of datetime.strptime()
* Remove related unnecessary logger setup
* Add the missing exception documentation to relevant functions (in many
  cases the exception is rather unlikely as the schema has been verified
  many times before this though...)

Fixes #1065

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2020-10-13 20:06:14 +03: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
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
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
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
Lukas Puehringer
b1365843dd Mandate semver for SPECIFICATION_VERSION_SCHEMA
Mandates Semantic Versioning format with
tuf.formats.SPECIFICATION_VERSION_SCHEMA using the regex referenced
on the official semver website. See:
https://semver.org/spec/v2.0.0.html#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
https://regex101.com/r/Ly7O1x/3/

Adopts tests accordingly:
 - removes tests that now fail earlier due to stricter format
 - adds tests to check exemplary valid and invalid version schemas

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2019-09-16 15:43:39 +02:00
Lukas Puehringer
9d201d1657 Update SPEC_VERSION to semver-compliant 1.0.0
Updates SPEC_VERSION definition in tuf/__init__.py, test files and
docstring in formats.build_dict_conforming_to_schema.

Test metadata will be updated in separate commits.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2019-09-16 15:43:39 +02:00
Lukas Puehringer
e42dffd464 Add TUF-specific schemas removed in sslib
Add schemas KEYDB_SCHEMA, SIGNATURESTATUS_SCHEMA and
VERSIONINFO_SCHEMA, removed in
secure-systems-lab/securesystemslib#165 as TUF specific, and adopt
usage accordingly.

NOTE: The usefulness of these schemas may be assessed in a
different PR.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2019-09-05 15:16:05 +02:00
Sebastien Awwad
25aa71d4c6
PR revision: test build_dict_conforming... arg for schema type
Raise an error if it's not a schema.Object instance (not just
if it's not a schema.Schema instance).

Also adds a test for this.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2019-04-03 10:30:42 -04:00
Sebastien Awwad
7ecf522698
Automatically fill _type and spec_version in build_dict_c...
in tuf.formats.build_dict_conforming_to_schema

Populate _type with the expected value for the given schema, and
populate spec_version with tuf.SPECIFICATION_VERSION.  Do this only
when the values are not provided, and support overriding them.

Also adds testing for the above and takes advantage of the above
in repository_lib's _generate metadata functions.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2019-03-29 15:23:00 -04:00
Sebastien Awwad
47e05f8b96
Kill another partially-used metadata writing func
tuf.formats.make_role_metadata concerned itself with exclusivity checks
for paths and path_hash_prefixes, but no code actually used it for
relevant data.  It's yet another custom metadata writer replaced by
build_dict_conforming_to_schema.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2019-03-29 15:22:22 -04:00
Sebastien Awwad
e7c822954b
Update testing following MetaFile(etc) class removals
Testing will now use (and test) build_dict_conforming_to_schema.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2019-03-29 11:37:31 -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
924b97d1d7
Resolve conflicts 2017-08-28 13:07:54 -04:00
Vladimir Diaz
1edc4d4b8a
Remove compression from unit tests for formats.py, keydb.py, and roledb.py 2017-08-25 15:56:41 -04:00
Vladimir Diaz
1afd968725
Remove schemeta related to compression and update unit tests 2017-08-25 12:52:11 -04:00
Vladimir Diaz
f463ad64ab
Edit schemas in formats.py 2017-08-23 12:48:40 -04:00
Vladimir Diaz
a384933195
Edit the format of _type entries, which are now lowercase 2017-07-12 15:05:17 -04:00
Vladimir Diaz
a15c413975 Move tuf-related schemata from securesystemslib to tuf.formats.py 2017-01-11 11:32:08 -05:00
Vladimir Diaz
ea63aafec6 Use SCHEMA.AnyString() rather than SCHEMA.String('')
Also update test_formats.py
2016-12-01 11:24:14 -05:00
Vladimir Diaz
ddde0d700b Remove tufformats from test_formats.py 2016-11-09 15:58:29 -05:00
Vladimir Diaz
5d14de8a61 Merge branch 'tuf_merge' of https://github.com/baloyan/tuf into baloyan-tuf_merge
Conflicts:
	tests/test_formats.py
	tests/test_updater.py
	tuf/client/updater.py
	tuf/formats.py
	tuf/repository_lib.py
2016-11-09 14:32:59 -05:00
Vladimir Diaz
e6a4b5eef0 Rename TARGETFILE_SCHEMA to TARGETINFO_SCHEMA 2016-11-07 11:41:34 -05:00
Artiom Baloian
812a85c393 Finish splitinf formats.py file, now there is formats.py for commons
and tufformats which is TuF specific
2016-10-31 20:02:29 -04:00
Artiom Baloian
b07d9a5d0f Move some part of tufformats into the common formats 2016-10-31 19:04:14 -04:00
Artiom Baloian
8247a02737 Moved TuF exceptions and schem into the ssl_commons 2016-10-31 11:58:05 -04:00
Artiom Baloian
7098cdbc3a Move _vendor dir and split formats into the formats and tufformats 2016-10-28 18:37:28 -04:00
Vladimir Diaz
e0a4f18223 Improve code coverage 2016-07-21 10:28:46 -04:00
Vladimir Diaz
65d23fa5a7 Reference all metadata in <version>.rolename.json format 2016-07-14 10:31:16 -04:00
Vladimir Diaz
b8ce4bbfcd Implement changes to write and load the new format of snapshot.json
The repository tools should properly write and load consistent versions of root.json and snapshot.json.  Version numbers were previously prepended to these two roles.
2016-04-14 08:13:50 -04:00
Vladimir Diaz
0912495b2b Review 'test_formats.py' 2015-10-27 16:55:51 -04:00
Vladimir Diaz
4cb851ca0a Fix remaining issues with unit tests after implementing version numbers in snapshot.json 2015-10-27 16:11:11 -04:00
Vladimir Diaz
47471db40f Add import statements for unvendored dependencies in the unit tests 2015-06-02 10:28:02 -04:00
vladdd
c5fd17ab3e Merge branch 'develop' of https://github.com/theupdateframework/tuf into develop
Conflicts:
	tests/test_hash.py
	tests/test_keydb.py
	tuf/formats.py
	tuf/keydb.py
	tuf/repository_tool.py
2014-05-10 20:26:06 -04:00
Vladimir Diaz
d831187949 Improve test coverage. 2014-05-01 12:59:34 -04:00
Vladimir Diaz
ab95a4b3aa [WIP] Python 2+3 support.
Python 2+3 unicode.
libraries.
The following modules (and their tests) work in PY2.7+3.3:
keydb, hash, formats, mirrors
2014-04-29 14:27:34 -04:00
Vladimir Diaz
a7f28b9af4 [WIP] Python 2+3 support.
Add six, convert PY <=2.5 exception handling, dictionary iteration, libraries, 1/2 the tests.
2014-04-22 15:03:42 -04:00
vladdd
5f94d5be0d Support ISO 8601, vendor iso8601, clean codebase. 2014-04-19 14:27:53 -04:00
Renamed from tests/unit/test_formats.py (Browse further)