Commit graph

741 commits

Author SHA1 Message Date
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
Sebastien Awwad
5312703fc7
Test: remove no-longer-used simple_proxy.py
as that set of tests is now redundant, and depended on Twisted,
which we need not depend on.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-25 15:36:54 -04:00
Sebastien Awwad
e5a50a6831
Test: rename proxy2.py as proxy_server.py
(from the original name in the source repository to a more useful
name here).

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-25 15:36:43 -04:00
Sebastien Awwad
75e126ac96
Test: remove redundant proxy tests and their requirements,
add more explanatory comments in test_proxy.use,
and prepare for rename of proxy2.py to proxy_server.py in next
commit (separate so that the rename can be seen as such).

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-25 15:04:08 -04:00
Sebastien Awwad
d29e4d1aad
Test: refine proxy2.py script a bit:
- move some configuration values up to the module level (proxy certs
  dir, proxy ca key and cert, general certs dir).
- add explanatory comments for these values
- create the proxy's host-specific client certificates directory
  if it does not yet exist.
- note that the module is not thread-safe
- fix a Windows-incompatible line (explicit path separator)

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-25 14:31:07 -04:00
Sebastien Awwad
34db5095aa
Test: clarify simple_proxy.py test script
and disable unused sections for clarity as well.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-25 13:55:22 -04:00
Sebastien Awwad
46fe1900b5
Test: add tests of HTTPS proxy compatibility
- client makes HTTPS connection to proxy; proxy makes HTTP
  connection to target server
- client makes HTTPS connection to proxy; proxy makes HTTPS
  connection to target server

Added functionality to the proxy2.py script to allow it to
take and use a certificate to use to validate the target
server.

Also added clarifying comments in test_proxy_use.py.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-25 13:52:03 -04:00
Sebastien Awwad
7288b71917
Test: fix a bug in arg processing for the proxy server
Fixes a typo in arg processing for test script proxy2.py.
Also removes an outdated comment and clarifies another.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-21 13:13:52 -04:00
Sebastien Awwad
2b019f65f7
Test: add proxy certs and reorganize certs in test data dir
for proxy testing. Also update the test scripts to point to
the new location of ssl certificates and ssl keys.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-21 13:13:52 -04:00
Sebastien Awwad
b7b73e592e
Test: add flag to toggle relay-only/intercept proxy behavior
in proxy2. And use it to run both relaying and intercepting proxies.

True:  normal HTTP proxy. Support HTTP & HTTPS connections to target server
False: intercepting MITM transparent HTTPS proxy. Makes own TLS connections
       and has its own cert; must be trusted by the client and is able to
       modify requests.

Also perform some cleanup of test_proxy_use.py

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-21 13:13:52 -04:00
Sebastien Awwad
46b584d8eb
Test: try download.py through via various proxies
- adds inaz2/proxy2.py, copied code.
- adds dev dependency on twisted for a simple proxy test
- adds a new test module, test_proxy_use, and runs those tests only in
Python2.7 (as proxy2 only supports Python2.7) using new logic in
aggregate_tests.py.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-21 13:13:45 -04:00