Commit graph

751 commits

Author SHA1 Message Date
lukpueh
4d7bb69a77 Fix comment in root rotation updater test
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
Co-Authored-By: Trishank K Kuppusamy <33133073+trishankatdatadog@users.noreply.github.com>
2019-10-08 09:19:36 +02:00
Lukas Puehringer
3604c38c71 Add root rotation bounds updater test
Test that client does not rotate beyond a configured upper bound,
i.e. `current_version + MAX_NUMBER_ROOT_ROTATIONS`

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2019-10-07 11:59:40 +02:00
Lukas Puehringer
b0d9f103a2 Add full root rotation updater test
Test that a client whose root is outdated by multiple versions and
who has none of the latest nor next-to-latest root keys can still
update and does so by incrementally verifying all roots until the
most recent one.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2019-10-07 11:59:40 +02:00
Lukas Puehringer
250a3f32a6 Add two ed25519 key pairs for updater tests
This commit also updates the key loader helper in
test_updater_root_rotation_integration.py to load
the new keys too.

The keys were created (at the root of the repository) like
so:

```
from tuf import repository_tool
repository_tool.generate_and_write_ed25519_keypair(
    "tests/repository_data/keystore/root_key2", "password")
repository_tool.generate_and_write_ed25519_keypair(
    "tests/repository_data/keystore/root_key3", "password")

```

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2019-10-07 11:59:40 +02:00
chentanjun
04019a1bd8 fix-up some spelling mistakes
Signed-off-by: chentanjun <2799194073@qq.com>
2019-09-26 00:52:21 +08:00
lukpueh
df1c749d56
Merge pull request #919 from lukpueh/refactor-repository-api
Streamline TUFs crypto interface
2019-09-24 17:08:18 +02:00
Lukas Puehringer
5d2898a13c Remove obsolete 'interposition' from docs
The interposition sub-package was removed in #537.
This commits removes obsolete mentions of 'interposition' from code
comments and documentation.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2019-09-24 14:31:54 +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
Lukas Puehringer
48f35fce54 Merge branch 'lixuefeng2-for_format' into develop
Locally merging #880 to fix code style issue (missing whitespace).

Note: the PR had an unwanted documentation patch that is excluded
from this merge.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2019-09-17 13:13:56 +02:00
lixuefeng (Cloud)
5f891e81c8 just format
Signed-off-by: lixuefeng (Cloud) <li.xuefeng@h3c.com>
2019-09-17 13:11:48 +02:00
lukpueh
fdc0bc12a5
Merge pull request #876 from lixuefeng2/develop
Fix code style: add missing whitespace after operators
2019-09-17 12:57:48 +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
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
2e21950c74 Re-generate projects test metadata
Re-generate metadata to adopt spec version format change, using
`generate_project_data.py`:

```
cd tests/repository_data && rm -rf project
python generate_project_data.py
```

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2019-09-16 15:43:39 +02:00
Lukas Puehringer
af1a21b05a Re-generate repository and client test metadata
Re-generate metadata to adopt spec version format change, using
`generate.py` plus some working around (see script below):

```
 # QUICKFIX: Patch add_target to pass file paths relative to targets dir
git apply - <<EOF
diff --git a/tests/repository_data/generate.py b/tests/repository_data/generate.py
index 6c263575..699ed00f 100755
--- a/tests/repository_data/generate.py
+++ b/tests/repository_data/generate.py
@@ -119,12 +119,11 @@ if not options.dry_run:
 # about the target (i.e., file permissions in octal format.)
 octal_file_permissions = oct(os.stat(target1_filepath).st_mode)[4:]
 file_permissions = {'file_permissions': octal_file_permissions}
-repository.targets.add_target(target1_filepath, file_permissions)
-repository.targets.add_target(target2_filepath)
+repository.targets.add_target('file1.txt', file_permissions)
+repository.targets.add_target('file2.txt')

-repository.targets.delegate('role1', [delegation_public],
-    [os.path.basename(target3_filepath)])
-repository.targets('role1').add_target(target3_filepath)
+repository.targets.delegate('role1', [delegation_public], ['file3.txt'])
+repository.targets('role1').add_target('file3.txt')
 repository.targets('role1').load_signing_key(delegation_private)

 repository.targets('role1').delegate('role2', [delegation_public], [])
EOF

 # Remove repository and client data
cd repository_data && rm -rf repository client
 # Generate metadata
python generate.py
 # Duplicate metadata files
cp -r client/test_repository1 client/test_repository2
 # Recover non-signed file
git checkout client/map.json
```

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
lukpueh
4fb4cb280e
Merge pull request #890 from lukpueh/fix-coveralls
Fix publishing of coverage results to coveralls.io (+ misc test config updates)
2019-09-11 11:41:58 +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
chentanjun
efbe0a3489 fix-up the the -> the
Signed-off-by: chentanjun <2799194073@qq.com>
2019-09-01 22:53:02 +08:00
chentanjun
8677b435ea fix-up tests package word spelling mistake
Signed-off-by: chentanjun <2799194073@qq.com>
2019-08-30 22:31:00 +08:00
Lukas Puehringer
478fcf7032 Move omit to run section in .coveragerc
Coverage used to be configured to omit certain directories while
reporting.

This commit slightly optimizes coverage to already omit those
directories while measuring coverage.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2019-07-11 14:32:49 +02:00
Lukas Puehringer
e8420483e2 Install TUF in editable mode in tox builds
This commit partially reverts the workaround introduced by
157167e0cc. Instead of patching the
path, we configure tox to install TUF in editable mode, which makes
the tests run against the same files as if the path were patched.
This makes it so that coverage records paths that it can then
normalize when sending them to coveralls.io (see .travis.yml).

See af22701140
for detailed background information.

As a consequence we can now skip building of sdist and installing it
into a virtual env directory in tox.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2019-07-11 14:32:49 +02:00
Lukas Puehringer
157167e0cc Fix coverage file paths by patching sys.path
This replicates behavior of unittest's `discover` method, and
allows `coverage` and the tool that posts coverage reports to
coveralls.io, i.e. `coveralls`, to record the correct paths and
left-strip the parts leading to the project directory.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2019-06-26 18:22:46 +02:00
lixuefeng (Cloud)
4ff5f2fedb just format
Signed-off-by: lixuefeng (Cloud) <li.xuefeng@h3c.com>
2019-05-25 15:47:27 +08: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
3ac174f597
Use build_dict... instead of make_role_... in test_sig.py
since make_role_metadata is being replaced by
build_dict_conforming_to_schema

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2019-03-29 15:38:30 -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
Sebastien Awwad
d58bcf9c62
spec version support code cleanup
Specification version now only lives in tuf/__init__.py, and will only be
derived from there.

Specification version info is no longer in tuf.formats, where it was
previously moved from tuf.updater, since this was redundant.

Also finally corrects spec version testing in test_updater.py.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2019-03-29 11:08:43 -04:00
Sebastien Awwad
2c1ca1e5c1
test: Patch some holes in testing due to bad try/except/else
syntax/understanding.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2019-03-28 19:03:46 -04:00
Sebastien Awwad
18ef3b419d
Improve the way specification version is checked in metadata
and generate more friendly errors.  Prior to this, a test in
test_updater.py was written in such a way to not actually be
testing whether or not specification version checking was
working correctly -- the error updater.py raised if a specification
version number was not supported was the same as would be raised
if a role version was not the expected version, and, amusingly,
the test could not distinguish between these two scenarios and
was providing the wrong role version......

Specification version mismatch now raises a particular error:
UnsupportedSpecificationError.

The specification version supported by this code is now also all
in one place, tuf.formats rather than tuf.updater.

Related error messages and testing were improved (with some
edge cases closed).

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2019-03-28 18:30:03 -04:00
Nguyen Hai Truong
d36a4e5621 Remove redundant words in comment
Although it is spelling mistakes, it might make an affects
while reading.

Signed-off-by: Nguyen Hai Truong <truongnh@vn.fujitsu.com>
2019-02-26 14:35:30 +07:00
Sebastien Awwad
eb60084ebe
Reduce test spam by using unittest output buffering
Thanks go to @lukpueh for this helpful tip.

After merge, stdout should only appear if a test has failed. This
functionality is provided by `unittest.TextTestRunner` argument `buffer=True`.
This functions like the `--buffer` command line argument listed here:
https://docs.python.org/3/library/unittest.html#command-line-options

std out is discarded if a test succeeds.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2019-02-19 13:38:10 -05:00
Sebastien Awwad
fffc53321b
Merge pull request #803 from theupdateframework/test_delay_increases
test: Remove port collison chance and lengthen delays for AppVeyor
2018-11-14 13:39:23 -05:00
Sebastien Awwad
90a1b77a46
DOC: correct outdated comments in test_proxy_use.py
relevant to the version of Python required for the proxy tests.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-11-14 11:39:31 -05:00
Sebastien Awwad
8866abbb83
test: remove port collison chance and lengthen delays for AppVeyor
Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-11-14 10:54:02 -05:00
Sebastien Awwad
dad9f9f11b
test: extend sleep in testing after spawning server processes
This adds to PR #799; please see that for details.  In short,
tests sometimes fail on slow test systems (primarily on AppVeyor)
if we don't have long enough delays.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-11-06 09:59:24 -05:00
Sebastien Awwad
e99ff85b2c
test: extend a delay in testing after spawning server processes
This adds to PR #799; please see that for details.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-11-05 16:28:59 -05:00
Sebastien Awwad
375ef4bd0d
test: Delay more when spawning test servers to avoid rare failures
on AppVeyor during automatic testing.  Also explains a bit better
the reason for those delays, in the comments adjacent to them.

AppVeyor was occasionally laggy enough that spawning a separate
server process didn't happen fast enough for the included delays,
so connection attempts in the tests occasionally failed.

This lengthens a few 0.3s delays that I've seen pop up in test
failures to 2s delays, along with a few others for good measure.
Sadly, this slows testing a bit.... I'll keep an eye out for more
of these.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-11-05 16:14:33 -05:00
Sebastien Awwad
01d8d9e780
Test: tighten test-skip conditions and lengthen a subprocess sleep
After seeing some AppVeyor failures, I've increased the wait after
starting test HTTP, HTTPS, and proxy servers from 0.5s to 1s, to make
it less likely that tests will fail because the servers weren't done
starting up yet.

After some review comments by @aaaaalbert, I've tightened the logic
in aggregate_tests.py around which tests to skip unless a certain
Python version is running, and added some consistency checks.
This also involved a bit of clarification of comments and variable
names.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-10-02 17:06:20 -04:00
Sebastien Awwad
ebcb17bbef
Test: clear requests sessions when updating expected ssl certs
to make sure that the test uses the intended certificate. (There's some
indirect indication that the updated environment variable might not always
have been used.)

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-10-02 15:49:39 -04:00
Sebastien Awwad
e8a1ab1395
Test: simplify env variable overwrite/restore code in test_proxy_use
Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-10-02 15:31:55 -04:00
Sebastien Awwad
15b33b8277
Test: modularize: add func that spawns Python intepreter process
that draws from sys.executable (the currently running Python interpreter)
instead of assuming 'python' is correct. Use this function instead of having
many individual subprocess calls written out. Slightly simplifies code, too.

This should eventually be moved to a common test module instead of appearing
in two places in the test code.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-10-02 15:31:51 -04:00
Sebastien Awwad
ec27630a48
minor: PR tweaks based on review: doc, casing, typos, updates
- two reversions to unnecessary changes
- some typo fixes
- capitalization of HTTP/S where reasonable
- commenting out code section with ''' rather than #

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-10-02 15:01:38 -04:00
Sebastien Awwad
b163caa29b
Test: add https test with expired server certificate
in test_download.py. In the process, added another test cert
and generalized the server process killer in test_download.py.

Additionally, I added another expected-to-be-good certificate
that was generated in the same way as the new bad certificates
(but for their individual flaws of course). This is because
the new certs aren't exactly like the old good cert, so that
we have another cert to test against in case the way the
certs were generated turns out to matter at some point in the
future.

Also slightly increased a start-servers delay in the test
in response to one test system taking too long and seeing
connection issues. Probably not helped by the number of
processes. Clarified a related comment in the test code.

Also made a note that environment variable cleanup would be
good to add to test_download.py, either copied from or moved
somewhere accessible from test_proxy_use.py

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-26 14:15:36 -04:00
Sebastien Awwad
2b97c0e59c
Test: adjust proxy_server.py argument handling:
- if it is provided, don't require the certificate filename to be
  provided as an absolute path
- raise an error if the provided certificate filename does not
  point to an existing file, rather than just printing and
  ignoring (to avoid possible future diagnostic headaches)

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-26 13:10:17 -04:00
Sebastien Awwad
d69f9a2160
Test: changed target server cert checking in test proxy script
Added Python version checking and changed behavior
in Python2.7.9+ to use custom certificate for target server
inherited from command line argument.

In Python versions < 2.7.9, proxy_server.py does not perform certificate
validation of the target server. As that is not part of what the current
tests using this script require, that is currently OK. In Python
versions > 2.7.9 (SSLContext was added in 2.7.9), the same code actually does
check the certificate, using the system's trusted CAs. As a result, since we
are using custom certificates, we need to either disable certificate
checking in 2.7.9 or load the specific CA for target test server, using the
SSLContext and create_default_context functionality also added in 2.7.9. It
is easier to do the latter, so the behavior in 2.7.9+ is to check the cert
and below 2.7.9 is not to. Note that we do not support Python < 2.7.
SSLContext is also available in all Python3 versions that we support.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-26 12:46:14 -04:00