freedomofpress/securedrop — pull request #83 by garrettr (2013-10-15 07:27:39+00:00)
Title: Tests

These are rough, but mostly covering, unit and integration tests for the securedrop website. They pass consistently, and should be used as a basis for future changes to the website. To run them, simply `./test.py`.

There are three known issues with the tests, none of which are serious:

1. The way the code is written now, a new crypto key is generated for each source when the source sends their first message. Generating this key is async. For most of the tests, we don't use this key and so we ignore it. `test_journalist_reply` needs it, and polls until it determines the key has been created. Otherwise, the tests just run. This may result in a case where tearDown has been called before key is generated; when GPG, running in another thread, tries to write the key, it will no longer have a keyring and will die with a cryptic error. We already use 1024-bit keys for tests (ONLY), which mostly alleviates this issue, but it still pops up occasionally. Ignore, and re-run the tests.

2. There is a big in crypto.clean. It is used to check (but does not meaningfully sanitize) codenames. It does not account for punctuation (which is present in the wordlist), or the fact that some puncuation is HTML-escaped before it gets to clean. This needs to be addressed in a future bug. For now, it just spits out a warning that looks like `CryptoException: invalid input: tango thank baste tooth shell eddy o'er klein` or similar. Ignore these (the application continues even when the clean check fails, so it does not indicate breakage - although this is not a great state of affairs either).

3. Sometimes something weird happens and the polling in `test_journalist_reply` goes on forever. If the tests take more than 10 seconds, hit ctrl-c. If you see

File "./test.py", line 211, in test_journalist_reply
sleep(0.1)
KeyboardInterrupt

then you ran into that (rare) issue. Just re-run the tests. This should also be addressed in a future bug.

Closes #19.