Commit graph

703 commits

Author SHA1 Message Date
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
Vladimir Diaz
dc5f3ec753
Test only the integration tests
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 16:19:15 -04:00
Vladimir Diaz
a1ab4bb620
Load only test_updater.py in aggregate_tests.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 16:14:04 -04:00
Vladimir Diaz
fae3453c49
Test unit tests that uses subprocess
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 16:09:59 -04:00
Vladimir Diaz
74837951fa
Test only test_sig.py in aggregate_tests.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 16:06:47 -04:00
Vladimir Diaz
321fbcd0cd
Test sys.exit(0) after loading tests
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 15:42:18 -04:00
Vladimir Diaz
3d3a780c1d
Kill subprocess in a few unit tests
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 15:31:06 -04:00
Vladimir Diaz
46b6be0d6d
Remove test_script.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 14:39:33 -04:00
Vladimir Diaz
0c0cf36bd1
Test whether the sys.exit() are being called in aggregate_tests.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 14:12:36 -04:00
Vladimir Diaz
0cf374e725
Add test_script.py (for testing purposes)
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 14:05:46 -04:00
Vladimir Diaz
e9c81b1271
Try adding explicit sys.exit(0) to aggregate_tests.py
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-05-02 11:28:20 -04: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
9048b793f4
Modify test condition for OSError
Signed-off-by: Vladimir Diaz <vladimir.v.diaz@gmail.com>
2018-04-27 13:36:16 -04:00