Commit graph

716 commits

Author SHA1 Message Date
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
Sebastien Awwad
8d64b5a2e1
Test: test download.py w/ untrusted or bad-hostname SSL certs
Rewrite test_https_connection to do a more thorough test, including
the use of an unknown certificate and the use of a good certificate
which lists a hostname not matching that expected in the connection.

In the process, made some small changes to the simple_https_server
module used in tests (takes an extra argument: certificate file to
use). Given the extent of the changes to test_https_connection, I
also made some style adjustments to better match our code style
guidelines.

I also reduced the length of a delay after the https servers
started from 1s to 0.2s, as part of a general campaign to speed up
the TUF tests. 200ms should do to start the servers, and if not,
I'll adjust it upward.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-13 12:22:37 -04:00
Sebastien Awwad
a5416d4baa
Raise helpful error in download.py if cannot parse URL
to extract hostname. After commit
"use a different session per hostname",
the code no longer raises MissingSchema if a URL is malformed in
certain cases. Since it parses URLs to extract the hostname and
would have raised securesystemslib.exceptions.FormatError, so the
test would have to check for that error instead of requests's
MissingSchema.

However, it's best to use a different error type, since while that
would be, true enough, a formatting error, FormatError is customarily
reserved for the automatic detection based on schemas in formats.py
(using <SCHEMA>.check_match()), and in any case it is not a
securesystemslib error.

So this commit adds error type tuf.exceptions.URLParsingError and
raises it if the hostname cannot be isolated in a URL, and checks
for it in test_download.py.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-10 16:30:32 -04:00
Sebastien Awwad
d199610f94
DOC: Clarify and correct comments on download timeouts
and call out need for more testing in a comment.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-10 16:30:32 -04:00
Sebastien Awwad
2f87821136
Test: mark slow retrieval test failure as expected...
until a fix has been provided. This results from PR 781. See
comments: https://github.com/theupdateframework/tuf/pull/781

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-10 16:30:32 -04:00
Sebastien Awwad
a8debd7cc6
Test: improve failure behavior of test_slow_retrieval_attack
and also clarify setup workflow in test_slow_retrieval_attack.

Because the test was written incorrectly, the test was failing
with a bad hash error after 31 seconds, when it should instead
have been failing because the slow retrieval attack was not
averted.

In particular, a target file was updated, but metadata was not
correctly updated on the repository and, further, the client's
copy of the metadata was never updated. (The client continued
to expect 31 bytes of target file instead of 400 or 800.)

The way the test used to run, the target file change
previously had no purpose.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-10 16:30:32 -04:00
Sebastien Awwad
411c0de33e
minor: better use of junk variable in test_slow_retrieval_attack
Also halves the duration of a failed test (from 800s to 400s).
Otherwise, this is a code-style-only change.

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-09-10 16:30:31 -04:00
Trishank K Kuppusamy
b9bc8602c2
Update TUF to handle HTTPS proxies
Signed-off-by: Trishank K Kuppusamy <trishank.kuppusamy@datadoghq.com>
2018-08-31 13:18:35 -04: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
996cce82ad
Make sure the default log file doesn't exist prior to test condition
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-18 10:42:09 -04:00
Vladimir Diaz
8a62facacd
Add test for disable_file_logging() in test_log.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-15 17:02:01 -04:00
Vladimir Diaz
c8621a785f
Add test condition for invalid arguments to enable_file_logging()
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-15 16:03:30 -04:00
Vladimir Diaz
0c941fd340
Add test_enable_file_logging() in test_log.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-15 15:50:22 -04:00
Vladimir Diaz
afd1d930a0
Fix test_log.py failure after change to default file logging behavior
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-15 14:59:12 -04:00
Vladimir Diaz
b48c974021
Merge branch 'develop' into edit_comment_test_indefinite 2018-06-12 09:19:26 -04:00
Vladimir Diaz
bc35b8ac3e
Add test 3 to the summary of conducted tests
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-12 09:18:47 -04:00
Sebastien Awwad
e9cd01e18a
DOC: Clarify comment on freeze attack test
to indicate the source of the freeze issue

Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
2018-06-11 16:10:21 -04:00
Vladimir Diaz
621ec3a76b
Add test condition for the persistent freeze attack
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-11 11:48:14 -04:00
Vladimir Diaz
e92680f850
Fix test_multiple_repositories_integration and edit whitespace in updater.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-06-11 10:02:11 -04:00
Vladimir Diaz
229009c870
Try to run all of the unit tests in aggregate_tests.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 17:04:39 -04:00
Vladimir Diaz
b6006e385b
Remove unneeded line of code in test_download
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 17:03:00 -04:00
Vladimir Diaz
0ee6ce29ec
Kill https_server_process in test_download.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 16:58:15 -04:00
Vladimir Diaz
eae79a5642
Test only test_download.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 16:46:20 -04:00
Vladimir Diaz
a91f81c017
Test only test_exceptions.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 16:43:53 -04:00
Vladimir Diaz
ccf56c06a7
Test only test_developer_tool.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 16:40:10 -04:00
Vladimir Diaz
b4d726c514
Test only the attack unit tests
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 16:26:57 -04:00