This commit is contained in:
throwsaway 2017-08-30 05:54:36 +03:00
parent dc3620b623
commit 4084f7c22c
14 changed files with 130 additions and 95 deletions

View File

@ -5,6 +5,7 @@ python:
before_install:
- sudo apt install python3-tk
- export TZ=Europe/Helsinki
install:
- pip install pytest pytest-cov pyyaml coveralls

View File

@ -39,7 +39,7 @@ dl_verify 6d93d5513f66389778262031cbba95e1e38138edaec66ced278db2c2897573247d1de7
dl_verify cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e src/ __init__.py
dl_verify cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e src/common/ __init__.py
dl_verify e8030b710ecde510330b40a00e64bee2604f63368182355774ba21ce814bbe079f7cb19d5c69ac357d28a883fc14343ee5c8d6b274ea43ccabe9b12be914ef78 src/common/ crypto.py
dl_verify 094943d26876c8e494e4ffbdaff57557004150193876b6131010e86ce098f3178bf4b813710ac176f361c42582f9b91b96a6526461b39e9080873dc4f8fd792e src/common/ crypto.py
dl_verify b4407e85a84d6e070b252f2c1c91268005d1ae6f69c9309723d2564d89b585e558fa80b7a8f1f52cc7d40e6595c3395cb5b68e3594af9d3e720a4a31ee8ba592 src/common/ db_contacts.py
dl_verify 1cc269c493969ccf98ef51a89895d0f279efdcf0e5c89c2e2e384e0cc7f1fea425566bc619e02ff0ed5ab3d28c3bd9bad93652f08f088c2915cfc3d28cd00d76 src/common/ db_groups.py
dl_verify 0c27e847aee638883928f4437adb8077de2a9444e7f06f48c45ec17e46bda43d8434934b8a04cfc6cfb4006554b5578cfba402f9a4ef96f7329a33d26fc0ac39 src/common/ db_keys.py
@ -80,7 +80,7 @@ dl_verify ba9fc6dad29b91a78d58f6a7c430e42eb75363d14de69668d293041bf36bb5eea06660
dl_verify c2f6afa281f91b88da85668dcfe0cade4af01927ac748ee1dc76c6f160149742980b3d6996c7d04e7fbbf5abca8f79100fd746e71187990d972f4b1aa2c1bf63 '' requirements.txt
dl_verify cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e src/tx/ __init__.py
dl_verify d2a9cda8e9af9d45657bf9d28d0cd53b5ae63212e20801a3cb133e15cfa5f34a6250c0620633945cfb276a90c5cde23588694045a0401d671ede7c2354c1d72e src/tx/ commands.py
dl_verify 19c6542e34e58fa8504193d71435c2f06fbb4d5d770342fcc37a27acf401aa05857733a6e364ade4cea1407762fe7340c0e4cd9d3031daf8943a13d14b1e92f1 src/tx/ commands.py
dl_verify 63bf0e11f46d8e5544e091110fd24e1241ddd650daa9cf76c39ed7db43a7062dc252a6b37ef26d55fb875fbc51314b47d23c98176d4fc1bf51fafef7a1f69763 src/tx/ commands_g.py
dl_verify e660fc6368a430a82a8a2d0e38bd4e8aaf94bc0ac5fc6b2c63eceb58f1579ce75ac3cb83382202e929da76fe3617d553732d1798beaded4f52ce0bf7e53b75bc src/tx/ contact.py
dl_verify d215e8983de808526cf9b76b0d299b7cc93a1cb15316113930028fbb0cf66bde51daa57a1e7ef6cfbd9f65e515553631943e142ab78ab89b78571f8612355b51 src/tx/ files.py
@ -111,11 +111,11 @@ dl_verify 9cba0c6eb96f5e827a669312c2c8d4d52b24ca5133d294ab946fca8d508b71f8983284
dl_verify c6432382c52a7665bf2da5ff4c6e502d46b0d29f7d8eeab2feacd77e4e4bd954227c57f9baf1251feb0f4d6923380fe64a38ca8d12d0d7cbb2b8d34c5b803b5a tests/ utils.py
dl_verify cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e tests/common/ __init__.py
dl_verify 83af707f0018df689f5b12368603308bb2a0c255e66c78b8063b8a66338c3018d7f4300074ec21e024693a9ee264f4ccb927c27dad447fbc632cc3dcbc7c0ff7 tests/common/ test_crypto.py
dl_verify 52c111cc9a956354f5f5a317cff4209003481f4f8bf3c248df529c4925202780c0c2fea3a3fe2289a2651d82c9bcbc8a2801141f2b5b2a8d4ba1b74943de6587 tests/common/ test_crypto.py
dl_verify 8e1b790d9143a7d2decd5dab97826cc3fdf85c071da95340da7a4fdc862d94099408675ad7422c8d105e988aa39eb5b5ef1a39fce9be5a6ae6877fd820e1f899 tests/common/ test_db_contacts.py
dl_verify 8190d1525f5f603293f30a07d2e8e15becad13094458d6b3e75a8f45bf7751019ed9fea8df9b366c09bef083d3eb1b4bf0e3c165912069ddfa862f86107cd420 tests/common/ test_db_groups.py
dl_verify e11f05a0193bfa013c487ff4b646f8f54b5b3ac71e136d69d38d4e572afffd0849ce3f4b0c1639b77f6506c33e6f13c65ca5b4b3f3e8a421a17f89fe2113141f tests/common/ test_db_keys.py
dl_verify 019f014bd443f1659aecc6b84e262b525f0ef990edbd47023575780da1b2a91169e15ceeb451d05115c393b055e636719277fd8272f6445388516d357b31a032 tests/common/ test_db_logs.py
dl_verify 32e6b8562a758eaa29c9e32720434915c7b32a5815203b2b4d11acd81cd9b3669e88ee41d660681d2fb7015f9f4346919e74c901a50bb8202a4f93ba316b0b3d tests/common/ test_db_logs.py
dl_verify e5c0fd0fcff438b92933e81389053b3d5a4440d0b37d5e9744a96c6a8cf5c14169ae90a2714d5490f4f920b0335235d9d5cd6f42e806698333a0ef2821b56e92 tests/common/ test_db_masterkey.py
dl_verify 19233b6f6aa19e50f36d8ca595e93b8a782c20a9f6076e966da8a7c5619ff33a0b8b02a93d16903ecc873930e0a263a79edc4a2c85e39aeaac81279ba1a65d0e tests/common/ test_db_settings.py
dl_verify 4472f5528c6c9c60b4c4dbbc6c41dbe19734710be37b9ffdb27081c84fe308230c4e5b0180c006fdf47e75bb05050e41958df25b6feb752fb7951141bd59c6fa tests/common/ test_encoding.py
@ -124,7 +124,7 @@ dl_verify 12f791c529dc447c6940049e3b9b44cfd3847c25089864820677e23446ed72d212bdf1
dl_verify 01df5269c6189a55bbed7e5894aa126d5e16d16f6b945160e63c929b397f06ef238b3a4be8fa3d5431567d1b62a0d4eb86faa320cb6df9dcfed971d98df936da tests/common/ test_input.py
dl_verify 029cc1f4cd983c32a4b2ee0b78c0f3f9e40ed3ff417ed323927325a582d5e77c52c2ca48e3ea38471fbe431d87a4e35355de0a6b17e2cb6331d04a25ecda1358 tests/common/ test_misc.py
dl_verify 7ca3a76b69a96e33ce8ef0404bbed696f3c82d63cc8940e25763ec241e7d8be2cf033c54d28a193bed911b3646bf4c111450a30d90f25af347a323e3018da04c tests/common/ test_output.py
dl_verify 7b5d4519d3cde35b25a120bf9f68219c60fb168e3dade54d2b2dc94a9eaea9c010c5391b8c85606de3a66b20f9d3cdd72e78f7ec861747e923aff3eed6ceeca6 tests/common/ test_path.py
dl_verify a17d3bd4fc7b44216a2c59789fb9322a4cdee52c9763dd8f7cc59908c42b500db51aab4681b7372fcfbe6a152055bf823073797b3f94275791b1c56f2a363395 tests/common/ test_path.py
dl_verify bdea73b00b14b8de136112e9c6e1257aca971a704bf0a104e3aefd1014a0d94ce0cd941a2568e058b27202ec595476692c22ac1244d626759965b8242fa3ea74 tests/common/ test_reed_solomon.py
dl_verify 946812a0c4e368b349b31622ddd21ed863cd2feeec1ff145c45a96a5953a47c5865eade0fbe391510cfd116fa35d9f8253e4314187884762e3ae3000dcbc9db3 tests/common/ test_statics.py
}
@ -132,7 +132,7 @@ dl_verify 946812a0c4e368b349b31622ddd21ed863cd2feeec1ff145c45a96a5953a47c5865ead
download_nh_tests () {
dl_verify cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e tests/nh/ __init__.py
dl_verify 85512170168f3fcd3f5a9e97bec6b5d8b0e4d2532347a12d13f7f284f74a68288ab40e2f69532791edd269917b169214d10a40a555cc458a66ed8072c5d92368 tests/nh/ test_commands.py
dl_verify 8a3b29d367987feae53c62a08fa3523a2e1fd032d9043f445244a9fd4026f73476daaf5fb9dbfe732b7bbfc5b4b0495f1566bb4cced9d41854a7128ccb802097 tests/nh/ test_commands.py
dl_verify 045f61820b739ad86d475a460788f27a92cfcf651ad4b4d4e798f6f3f4672e3e10fee2941057c919dac23fd1231df06b78f6be3e3a749e7b9d51504ec49044a2 tests/nh/ test_gateway.py
dl_verify 512ad346e350713bd551447e1c305d25d038a6c1a6faaf2a9880c52352255bcf5b057c89148804ec495cd5d996b832f7d139691ef9a3fc3fd65b927a3548aee9 tests/nh/ test_misc.py
dl_verify a32e36680caa2bbcb841369062996d1a1656c13c5eca6bdd75f15841a5123c6a90bf65b85acfc3d8536a888b4e41a1b591a2b44b3b871cb3f0ebe50b63509b1d tests/nh/ test_settings.py
@ -142,12 +142,12 @@ dl_verify 825f26a6baf24fc650a9e3dfc09a2361b1000e48b754273c2b0321b7c01f08f71ebb40
download_tcb_tests () {
dl_verify cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e tests/tx/ __init__.py
dl_verify 84c64ff9fc9908a5140d037e6afb7f1ce05e012f4fe3e39e446ed5468747098a4ca5f73f500cca3fe15d101cca5d5c75267c47d1887bed47c6427ac587eae7fb tests/tx/ test_commands.py
dl_verify 6eed2a31a017772c767907be7b5c825207d25d394d4517c856a882265de84c50f56ae60020e8983c2269d356fc73286bffe414c28d894d851d05bb45c3ef79f5 tests/tx/ test_commands.py
dl_verify 8be45e9c005d6ddb89d0d8a1dc3477c39e13e5b95dfac1d38f94f45a886ee0af64f9b95bf25ee26b1ad2085fbd285237b68145dba916fc56844dbb740ba0d52c tests/tx/ test_commands_g.py
dl_verify b9a27910eba3f09b09c5d88c41ec95629ec0a8cfae8cd393bbabe5ffb699b5a1db98bca825fbf320eae48c8fd9125a7d2dc64e94c992dbd4799d7f00ad0a34b0 tests/tx/ test_contact.py
dl_verify 2b15f293950ce0961e2975a20b60e7dc7e5668507941ce01bcb9147799c2b4f72a1ee35206e58f4e9d3f40f6ff758e0206c3bd6eb428c2d504aded8c254792f7 tests/tx/ test_files.py
dl_verify 1c8eb650a908f53d1ef798b31a969aa36fd19f79511697a1d71fef74460f8290a35b13284f16019fa06668f3f23dfc5744aed06b36cc5d260bff3f8c9f6a8062 tests/tx/ test_input_loop.py
dl_verify e19eb3d3bca69056ed5e93ab1e504f4ed64f49be01ffca736a59cb80269f445d92f4c21ca0ac0eb691c4ba545ef903001a12e475304f140ee26c11c37b493633 tests/tx/ test_key_exchanges.py
dl_verify a6e64b203c0c0b5a7d09e1a41e2faccaa6eeaadfd108117f1895c7120e833b79ac73166cd516c13fa9a2cf31d0196e4e2215a3d9100e26255eb57be738478efd tests/tx/ test_input_loop.py
dl_verify 783a0d0b6fc3b04abfe474b4e5829dce333bc727fe9a2dd570b37ac63dfaa0426e71b24d0b02a5254a1e2711943bb0d61516297cf3a872bd55d57728fcaf6d84 tests/tx/ test_key_exchanges.py
dl_verify 485f6ea31486b6aeceb7c6359bfb46c4a107f2f971b84c3bc36eeddf6cbec0dbbe730ca5109673d66dda61bf1ccb24dfb3f15575dfc0279b6adb6a1c504a2ce4 tests/tx/ test_packet.py
dl_verify 3967b417f32779187a9dff95187a63dc02a7c8dc314f92c029351c9be180344e560574007566050dac58b4c3f066ac9e3e11ea8047b61801f8530808d4d55ed8 tests/tx/ test_sender_loop.py
dl_verify dc783f22c8e0e48430269ef5001c7e4c361a3b555b5e48a9cff136007534f4c093f1d1cfe2b55751adc1c9145d6de08e2cd21332c75e2533d50c2fda70060d21 tests/tx/ test_traffic_masking.py
@ -155,7 +155,7 @@ dl_verify 35774f4d935ba91600b11b73b75aa12605a64297914cfd2eba793d3ebaaf4cc6ad48d8
dl_verify ba9abe1222c4bf409c00e5cbbcdcfb28753f3c0b85e52aa89e45c81a2831a461cff6ec16d1ebc7690419b6d02bf220de0ac6b30b7eabd0c040fa571fc4e61f9f tests/tx/ test_windows.py
dl_verify cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e tests/rx/ __init__.py
dl_verify 6636ec696e79f9899e8b420efdb0969d71f0782d5b3e35ce34bcc99447b6a5fa9e9da3f05631abbab039309801701a72d917b0e7e813c3981e6b577413973a23 tests/rx/ test_commands.py
dl_verify 8c4aa1d4e7df0228172c38e375682f5cdd32fd918168620a61a98d17d0ce79f30215e7793be29390e0a6a51c5daf26a2d80db56458b5d02524f7878a2849c5bd tests/rx/ test_commands.py
dl_verify 467a91fa2161c172506036ba36f8f31cbcf1b9aa1a91f1e7aef2727e3113edae8b24b26488b82b1ba1d4d00411e79944568b8d9c9e2d7e22c3b30ce759ab0137 tests/rx/ test_commands_g.py
dl_verify 081ff658de5c46327ea840038e44d1d1dd5682d31950145affc8f2536e2c06ab779f672db779a555a75a2bed9a1e323117e07bf89d20d5f2ba06a09dedd87e8f tests/rx/ test_files.py
dl_verify 7c0d97bfd5dca727ee36573cdc1b5683077524ff28236e01d8b011da8d51c09988985b76e054c2cdebf6a95fd2e68a14d7a976f1c03a1a39ab9d2a3672e89143 tests/rx/ test_key_exchanges.py
@ -163,7 +163,7 @@ dl_verify aef0fe0e208ce91002924ec2d103c4575079ca3c72544774ba904e44f99ae78aa13cb2
dl_verify b6a33ed791e6daab20ee10f304390a8bc890a984c1bf1bec4a57d04741797cfc242d1f1067a0a2854f4daf35fb1302d652fc5ed17749884b5424d700ffb32642 tests/rx/ test_output_loop.py
dl_verify 8dbd77abca3bdab031f5a2e16d5789c2359088c9817a53188a4d6b6b45d4bce087e0ec872810401f35d6cdb170b3052dc27f826e4906ab3f41bb71e49fcfb29e tests/rx/ test_packet.py
dl_verify 6b87bc6c6beaf421c8f9f27ec6ced2d3248efb7b7cd966646b41a486d82d7665f7d2bb2879e1b6baf84fdf77dbef1eba565adcafd8228e7dde5919f8a12e47d1 tests/rx/ test_receiver_loop.py
dl_verify 2b77819b9e06ce0cdc2a965c063000cd7b22e69fc3219f1885eb56f6185fcb49b0c922dcf6594a18f8909e330aa1722fa128607f74ede7ac237c10ff4294d877 tests/rx/ test_windows.py
dl_verify 96e8ad84c9cce083d8a5a85b928a2c78d4b336739a894fdfb69abdef880dbe0fc72f05515393ad576d86250d32f4fc93b65f657c5f7dd7d4aa4c7c2e8b24b62f tests/rx/ test_windows.py
}

View File

@ -1,17 +1,17 @@
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQIcBAABAgAGBQJX43T4AAoJENJrq8gPhjL0ziMP/Av2Lw82vv1xbBZcuSWHV+JZ
6vnQ0jyu4epl0y2YTdt22yN3YS6Klpy6r3xI2wCo2KJi4Uqb5lzfXRlYyqq7GHo1
jnPKgHe3kAQAdDOwD/Qmv8ZjuoaSwPxnQf1mvMTC/Sl/RnIOFDw7mHvIOotAc4O8
wtjuFzH29wDPtCgah8DtZsWp2lcIqzpgaeufs41X2kn9T5E+zRhhpK6zxDeKU9DQ
UpOJGkqs5bpnxZjmews7+OottxWN2gMW8iW2xszvwosTcqt54pJ5L9VT8y3SZ1/k
hvtHMUaaVlw8Bbvs68VTblAbbsFF4RRUxPktU8KceHUX+mNcpKzozm2VqAQRrA+x
Q/wj/KMEzdESoE1M9UiD+EcNg2YvZxMfKS1K3G3jGu1PrHkVZBrOFXcyzlmt9cnq
TNEW5mvaQ2r8Ipa0oX27pUQLDYomTqcmb9VB6zJm2kKyVgmWcO77CP8Uw+/XpneI
B3dvZQdWy/ES98qteZDZ6ACRb5xoleoB5HqEATmm5MsqFSroNA6F0DISgUh+fal+
38MJtenTvw1lBSDbChYsz38oAVRtM7Zp2kLjIfdJ9A4N0QDgFxOD95ouBWTlY26p
A13+u8xKGvpDgmw2PLH+BsH0CE7UoMX1WSRUJ4QeED5cdO7BgOyXsZl8OiqxoAAf
gxPK1esHFi5g4ImPek/V
=HFE2
iQIcBAABAgAGBQJX431gAAoJENJrq8gPhjL09I8QAK23lNDZvRrWiqipHTV8+RIB
n7MYk69FjgWnbBwLBlqfBrlGiNu5sE0j7yLGZrPUmKJv5s4exKY9Aw8iz+IDK85r
z6a4Ag84hnBwbkGwf/4qVmHFZUfvPFUgRUbPPH/PvB+N8pJbhF90UgaWcNGEJQCi
+jBMUcP9MEUcnUOA5oPwa7U9SfNim9daQEBcwvHiAJwM6kfVqv1ZY8IlhqwpT43x
6IQhhzJSzIwyZR/v1ZVNsGtGd/V33iELaJNscS81dvt8zuv8t3hPc34ea7UCu4Kp
16mdzpzApawN4cwH2CGQomBSkECI7Lo9MMl969w39LXxpq3Y8lvkFyULy1Mi34Fu
BBDzvdsOH4uLFnUML7Y0jn72xU+nsSzN7YYxRqdd+pSkNvv0jSvc/nzocCkPinBU
50toZu0fco21wAjcRaqQ487jfLBNdXvqJ6Shnb0FYl3t4YyKqLWSXnQLnQschEww
tFQ1AlnK1hG7kvdYOMhdFt/02E8/+ANuyavLixDSrOdyAwSeKdG3f6qKyI638izN
P4yF3FNdswxjXHaf1skVN0d27OUc1lezAinOWKbj0PtTQtH/tWccOvVqKStV1xiz
MUP4AX7g4M8V2QgBhDgMZFlqj9fUuqo94ZdmGGoNXeRgKybRmm32GPqll/4M2c0M
2UwA3ijKZWN3fji1jzSt
=OB/+
-----END PGP SIGNATURE-----

View File

@ -223,7 +223,12 @@ def csprng() -> bytes:
:return: Cryptographically secure 256-bit random key
"""
entropy = os.getrandom(KEY_LENGTH, flags=0)
# As Travis CI lacks GETRANDOM syscall, fallback to urandom.
if 'TRAVIS' in os.environ and os.environ['TRAVIS'] == 'true':
entropy = os.urandom(KEY_LENGTH)
else:
entropy = os.getrandom(KEY_LENGTH, flags=0)
assert len(entropy) == KEY_LENGTH
return hash_chain(entropy)

View File

@ -119,9 +119,9 @@ def process_command(user_input: 'UserInput',
def print_about() -> None:
"""Print URLs that direct to TFC's project site and documentation."""
clear_screen()
print(f"\n Tinfoil Chat {VERSION} \n\n"
" Website: https://github.com/maqp/tfc/ \n"
" Wikipage: https://github.com/maqp/tfc/wiki \n"
print(f"\n Tinfoil Chat {VERSION}\n\n"
" Website: https://github.com/maqp/tfc/\n"
" Wikipage: https://github.com/maqp/tfc/wiki\n"
" White paper: https://cs.helsinki.fi/u/oottela/tfc.pdf\n")
@ -528,7 +528,7 @@ def wipe(settings: 'Settings', queues: Dict[bytes, 'Queue']) -> None:
if settings.local_testing_mode:
time.sleep(0.8)
if settings.data_diode_sockets:
time.sleep(2.2)
time.sleep(2.2)
else:
time.sleep(settings.race_condition_delay)

View File

@ -251,15 +251,17 @@ class TestXOR(unittest.TestCase):
class TestCSPRNG(unittest.TestCase):
def setUp(self):
# Fallback to urandom on Travis' Python3.6 that currently lacks os.getrandom call.
if 'TRAVIS' in os.environ and os.environ['TRAVIS'] == 'true':
self.o_getrandom = os.getrandom
os.getrandom = lambda n, flags: os.urandom(n)
def test_travis_mock(self):
# Setup
o_environ = os.environ
os.environ = dict(TRAVIS='true')
def tearDown(self):
if 'TRAVIS' in os.environ and os.environ['TRAVIS'] == 'true':
os.getrandom = self.o_getrandom
# Test
self.assertEqual(len(csprng()), KEY_LENGTH)
self.assertIsInstance(csprng(), bytes)
# Teardown
os.environ = o_environ
def test_key_generation(self):
self.assertEqual(len(csprng()), KEY_LENGTH)

View File

@ -25,6 +25,7 @@ import struct
import threading
import unittest
from datetime import datetime
from multiprocessing import Queue
from src.common.db_contacts import ContactList
@ -138,6 +139,8 @@ class TestAccessHistoryAndPrintLogs(TFCTestCase):
self.contact_list = ContactList(self.masterkey, self.settings)
self.contact_list.contacts = list(map(create_contact, ['Alice', 'Charlie']))
self.time = datetime.fromtimestamp(struct.unpack('<L', binascii.unhexlify('08ceae02'))[0]).strftime('%H:%M')
self.group_list = GroupList(groups=['test_group'])
group = self.group_list.get_group('test_group')
group.members = self.contact_list.contacts
@ -187,11 +190,11 @@ class TestAccessHistoryAndPrintLogs(TFCTestCase):
write_log_entry(p, 'alice@jabber.org', self.settings, self.masterkey)
# Test
self.assertPrints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + """\
self.assertPrints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + f"""\
Logfile of messages to/from Alice
00:54 Alice: Hi Bob
00:54 Me: Hi Alice
{self.time} Alice: Hi Bob
{self.time} Me: Hi Alice
<End of logfile>
"""), access_logs, self.window, self.contact_list, self.group_list, self.settings, self.masterkey)
@ -208,11 +211,11 @@ Logfile of messages to/from Alice
with open("UtM - Plaintext log (Alice)") as f:
exported_log = f.read()
self.assertEqual(exported_log, """\
self.assertEqual(exported_log, f"""\
Logfile of messages to/from Alice
00:54 Alice: Hi Bob
00:54 Me: Hi Alice
{self.time} Alice: Hi Bob
{self.time} Me: Hi Alice
<End of logfile>
""")
@ -239,10 +242,10 @@ Logfile of messages to/from Alice
write_log_entry(p, 'alice@jabber.org', self.settings, self.masterkey)
# Test
self.assertPrints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + """\
self.assertPrints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + f"""\
Logfile of messages to/from Alice
00:54 Alice: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
{self.time} Alice: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
condimentum consectetur purus quis dapibus. Fusce venenatis lacus
ut rhoncus faucibus. Cras sollicitudin commodo sapien, sed bibendum
velit maximus in. Aliquam ac metus risus. Sed cursus ornare luctus.
@ -257,7 +260,7 @@ Logfile of messages to/from Alice
sem elit, fringilla id viverra commodo, sagittis varius purus.
Pellentesque rutrum lobortis neque a facilisis. Mauris id tortor
placerat, aliquam dolor ac, venenatis arcu.
00:54 Me: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
{self.time} Me: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
condimentum consectetur purus quis dapibus. Fusce venenatis lacus
ut rhoncus faucibus. Cras sollicitudin commodo sapien, sed bibendum
velit maximus in. Aliquam ac metus risus. Sed cursus ornare luctus.
@ -287,12 +290,12 @@ Logfile of messages to/from Alice
write_log_entry(p, 'charlie@jabber.org', self.settings, self.masterkey, origin=ORIGIN_CONTACT_HEADER)
# Test
self.assertPrints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + """\
self.assertPrints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + f"""\
Logfile of messages to/from test_group
00:54 Me: This is a short message
00:54 Alice: This is a short message
00:54 Charlie: This is a short message
{self.time} Me: This is a short message
{self.time} Alice: This is a short message
{self.time} Charlie: This is a short message
<End of logfile>
"""), access_logs, self.window, self.contact_list, self.group_list, self.settings, self.masterkey)
@ -331,10 +334,10 @@ Logfile of messages to/from test_group
# Test
access_logs(self.window, self.contact_list, self.group_list, self.settings, self.masterkey)
self.assertPrints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + """\
self.assertPrints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + f"""\
Logfile of messages to/from test_group
00:54 Me: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
{self.time} Me: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
condimentum consectetur purus quis dapibus. Fusce venenatis lacus
ut rhoncus faucibus. Cras sollicitudin commodo sapien, sed
bibendum velit maximus in. Aliquam ac metus risus. Sed cursus
@ -350,7 +353,7 @@ Logfile of messages to/from test_group
commodo, sagittis varius purus. Pellentesque rutrum lobortis
neque a facilisis. Mauris id tortor placerat, aliquam dolor ac,
venenatis arcu.
00:54 Alice: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
{self.time} Alice: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
condimentum consectetur purus quis dapibus. Fusce venenatis lacus
ut rhoncus faucibus. Cras sollicitudin commodo sapien, sed
bibendum velit maximus in. Aliquam ac metus risus. Sed cursus
@ -366,7 +369,7 @@ Logfile of messages to/from test_group
commodo, sagittis varius purus. Pellentesque rutrum lobortis
neque a facilisis. Mauris id tortor placerat, aliquam dolor ac,
venenatis arcu.
00:54 Charlie: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
{self.time} Charlie: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean
condimentum consectetur purus quis dapibus. Fusce venenatis lacus
ut rhoncus faucibus. Cras sollicitudin commodo sapien, sed
bibendum velit maximus in. Aliquam ac metus risus. Sed cursus
@ -394,6 +397,7 @@ class TestReEncrypt(TFCTestCase):
self.new_key = MasterKey(master_key=os.urandom(32))
self.settings = Settings()
self.o_struct_pack = struct.pack
self.time = datetime.fromtimestamp(struct.unpack('<L', binascii.unhexlify('08ceae02'))[0]).strftime('%H:%M')
struct.pack = lambda *_: binascii.unhexlify('08ceae02')
def tearDown(self):
@ -421,11 +425,11 @@ class TestReEncrypt(TFCTestCase):
write_log_entry(p, 'alice@jabber.org', self.settings, self.old_key)
# Test
self.assertPrints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + """\
self.assertPrints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + f"""\
Logfile of messages to/from Alice
00:54 Alice: This is a short message
00:54 Me: This is a short message
{self.time} Alice: This is a short message
{self.time} Me: This is a short message
<End of logfile>
"""), access_logs, window, contact_list, group_list, self.settings, self.old_key)
@ -433,11 +437,11 @@ Logfile of messages to/from Alice
self.assertIsNone(re_encrypt(self.old_key.master_key, self.new_key.master_key, self.settings))
# Test that decryption works with new key
self.assertPrints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + """\
self.assertPrints((CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + f"""\
Logfile of messages to/from Alice
00:54 Alice: This is a short message
00:54 Me: This is a short message
{self.time} Alice: This is a short message
{self.time} Me: This is a short message
<End of logfile>
"""), access_logs, window, contact_list, group_list, self.settings, self.new_key)
@ -451,7 +455,7 @@ class TestRemoveLog(TFCTestCase):
def setUp(self):
self.masterkey = MasterKey()
self.settings = Settings()
self.time = datetime.fromtimestamp(struct.unpack('<L', binascii.unhexlify('08ceae02'))[0]).strftime('%H:%M')
self.msg = ("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean condimentum consectetur purus quis"
" dapibus. Fusce venenatis lacus ut rhoncus faucibus. Cras sollicitudin commodo sapien, sed bibendu"
"m velit maximus in. Aliquam ac metus risus. Sed cursus ornare luctus. Integer aliquet lectus id ma"

View File

@ -60,6 +60,7 @@ class TestAskPathGui(TFCTestCase):
# Test
self.assertEqual(ask_path_gui('prompt_msg', self.settings, get_file=True), '/bin/mv')
@unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skip as Travis has no $DISPLAY.")
def test_get_path_to_file_gui(self):
# Setup
filedialog.askopenfilename = lambda title: 'test_path_to_file'
@ -67,6 +68,7 @@ class TestAskPathGui(TFCTestCase):
# Test
self.assertEqual(ask_path_gui('test message', self.settings, get_file=True), 'test_path_to_file')
@unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skip as Travis has no $DISPLAY.")
def test_no_path_to_file_raises_fr(self):
# Setup
filedialog.askopenfilename = lambda title: ''
@ -74,6 +76,7 @@ class TestAskPathGui(TFCTestCase):
# Test
self.assertFR("File selection aborted.", ask_path_gui, 'test message', self.settings, True)
@unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skip as Travis has no $DISPLAY.")
def test_get_path_gui(self):
# Setup
filedialog.askdirectory = lambda title: 'test_path'
@ -81,6 +84,7 @@ class TestAskPathGui(TFCTestCase):
# Test
self.assertEqual(ask_path_gui('test message', self.settings, get_file=False), 'test_path')
@unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skip as Travis has no $DISPLAY.")
def test_no_path_raises_fr(self):
# Setup
filedialog.askdirectory = lambda title: ''

View File

@ -171,6 +171,7 @@ class TestRxMImport(unittest.TestCase):
time.sleep(0.1)
self.queue_to_rxm.close()
@unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skip as Travis has no $DISPLAY.")
def test_rxm_import(self):
self.assertIsNone(rxm_import(self.settings, self.queue_to_rxm))
time.sleep(0.1)

View File

@ -179,6 +179,7 @@ class TestLogCommand(TFCTestCase):
self.settings = Settings()
self.master_key = MasterKey()
self.time = datetime.fromtimestamp(struct.unpack('<L', binascii.unhexlify('08ceae02'))[0]).strftime('%H:%M')
self.o_struct_pack = struct.pack
struct.pack = lambda *_: binascii.unhexlify('08ceae02')
@ -205,10 +206,10 @@ class TestLogCommand(TFCTestCase):
with open('UtM - Plaintext log (None)') as f:
data = f.read()
self.assertEqual(data, """\
self.assertEqual(data, f"""\
Logfile of 1 most recent message to/from None
00:54 Bob: A short message
{self.time} Bob: A short message
<End of logfile>
""")

View File

@ -38,6 +38,7 @@ class TestRxWindow(TFCTestCase):
self.settings = Settings()
self.packet_list = PacketList()
self.ts = datetime.fromtimestamp(1502750000)
self.time = self.ts.strftime('%H:%M')
group = self.group_list.get_group('test_group')
group.members = list(map(self.contact_list.get_contact, ['Alice', 'Bob', 'Charlie']))
@ -150,7 +151,7 @@ class TestRxWindow(TFCTestCase):
window.handle_dict = {LOCAL_ID: LOCAL_ID}
# Test
self.assertEqual(window.get_handle(self.ts, LOCAL_ID, ORIGIN_USER_HEADER, False), "01:33 -!- ")
self.assertEqual(window.get_handle(self.ts, LOCAL_ID, ORIGIN_USER_HEADER, False), f"{self.time} -!- ")
def test_get_contact_handle(self):
# Setup
@ -159,12 +160,12 @@ class TestRxWindow(TFCTestCase):
window.handle_dict = {'alice@jabber.org': 'Alice'}
# Test
self.assertEqual(window.get_handle(self.ts, 'alice@jabber.org', ORIGIN_USER_HEADER, False), "01:33 Me: ")
self.assertEqual(window.get_handle(self.ts, 'alice@jabber.org', ORIGIN_CONTACT_HEADER, False), "01:33 Alice: ")
self.assertEqual(window.get_handle(self.ts, 'alice@jabber.org', ORIGIN_USER_HEADER, False), f"{self.time} Me: ")
self.assertEqual(window.get_handle(self.ts, 'alice@jabber.org', ORIGIN_CONTACT_HEADER, False), f"{self.time} Alice: ")
window.is_active = False
self.assertEqual(window.get_handle(self.ts, 'alice@jabber.org', ORIGIN_USER_HEADER, False), "01:33 Me (private message): ")
self.assertEqual(window.get_handle(self.ts, 'alice@jabber.org', ORIGIN_CONTACT_HEADER, False), "01:33 Alice (private message): ")
self.assertEqual(window.get_handle(self.ts, 'alice@jabber.org', ORIGIN_USER_HEADER, False), f"{self.time} Me (private message): ")
self.assertEqual(window.get_handle(self.ts, 'alice@jabber.org', ORIGIN_CONTACT_HEADER, False), f"{self.time} Alice (private message): ")
def test_get_group_contact_handle(self):
# Setup
@ -176,12 +177,12 @@ class TestRxWindow(TFCTestCase):
'eric@jabber.org': 'eric@jabber.org'}
# Test
self.assertEqual(window.get_handle(self.ts, 'alice@jabber.org', ORIGIN_USER_HEADER, False), "01:33 Me: ")
self.assertEqual(window.get_handle(self.ts, 'charlie@jabber.org', ORIGIN_CONTACT_HEADER, False), "01:33 Charlie: ")
self.assertEqual(window.get_handle(self.ts, 'alice@jabber.org', ORIGIN_USER_HEADER, False), f"{self.time} Me: ")
self.assertEqual(window.get_handle(self.ts, 'charlie@jabber.org', ORIGIN_CONTACT_HEADER, False), f"{self.time} Charlie: ")
window.is_active = False
self.assertEqual(window.get_handle(self.ts, 'alice@jabber.org', ORIGIN_USER_HEADER, False), "01:33 Me (group test_group): ")
self.assertEqual(window.get_handle(self.ts, 'charlie@jabber.org', ORIGIN_CONTACT_HEADER, False), "01:33 Charlie (group test_group): ")
self.assertEqual(window.get_handle(self.ts, 'alice@jabber.org', ORIGIN_USER_HEADER, False), f"{self.time} Me (group test_group): ")
self.assertEqual(window.get_handle(self.ts, 'charlie@jabber.org', ORIGIN_CONTACT_HEADER, False), f"{self.time} Charlie (group test_group): ")
def test_print_to_inactive_window_preview_on_short_message(self):
# Setup
@ -192,7 +193,7 @@ class TestRxWindow(TFCTestCase):
msg_tuple = (self.ts, "Hi Bob", 'bob@jabber.org', ORIGIN_USER_HEADER, False)
# Test
self.assertPrints(f"{BOLD_ON}01:33 Me (private message): {NORMAL_TEXT}Hi Bob\n{CURSOR_UP_ONE_LINE}{CLEAR_ENTIRE_LINE}",
self.assertPrints(f"{BOLD_ON}{self.time} Me (private message): {NORMAL_TEXT}Hi Bob\n{CURSOR_UP_ONE_LINE}{CLEAR_ENTIRE_LINE}",
window.print, msg_tuple)
def test_print_to_inactive_window_preview_on_long_message(self):
@ -210,7 +211,7 @@ class TestRxWindow(TFCTestCase):
msg_tuple = (self.ts, long_message, 'bob@jabber.org', ORIGIN_USER_HEADER, False)
# Test
self.assertPrints(f"{BOLD_ON}01:33 Me (private message): {NORMAL_TEXT}Lorem ipsum dolor sit "
self.assertPrints(f"{BOLD_ON}{self.time} Me (private message): {NORMAL_TEXT}Lorem ipsum dolor sit "
f"amet, consectetur adipisc...\n{CURSOR_UP_ONE_LINE}{CLEAR_ENTIRE_LINE}",
window.print, msg_tuple)
@ -223,7 +224,7 @@ class TestRxWindow(TFCTestCase):
msg_tuple = (self.ts, "Hi Bob", 'bob@jabber.org', ORIGIN_USER_HEADER, False)
# Test
self.assertPrints(f"{BOLD_ON}01:33 Me (private message): {NORMAL_TEXT}{BOLD_ON}1 unread message{NORMAL_TEXT}\n"
self.assertPrints(f"{BOLD_ON}{self.time} Me (private message): {NORMAL_TEXT}{BOLD_ON}1 unread message{NORMAL_TEXT}\n"
f"{CURSOR_UP_ONE_LINE}{CLEAR_ENTIRE_LINE}", window.print, msg_tuple)
def test_print_to_active_window_no_date_change(self):
@ -236,7 +237,7 @@ class TestRxWindow(TFCTestCase):
msg_tuple = (self.ts, "Hi Alice", 'bob@jabber.org', ORIGIN_CONTACT_HEADER, False)
# Test
self.assertPrints(f"{BOLD_ON}01:33 Bob: {NORMAL_TEXT}Hi Alice\n",
self.assertPrints(f"{BOLD_ON}{self.time} Bob: {NORMAL_TEXT}Hi Alice\n",
window.print, msg_tuple)
def test_print_to_active_window_with_date_change_and_whisper(self):
@ -247,11 +248,12 @@ class TestRxWindow(TFCTestCase):
window.handle_dict = {'bob@jabber.org': 'Bob'}
window.settings = Settings(new_message_notify_preview=False)
msg_tuple = (self.ts, "Hi Alice", 'bob@jabber.org', ORIGIN_CONTACT_HEADER, True)
self.time = self.ts.strftime('%H:%M')
# Test
self.assertPrints(f"""\
{BOLD_ON}00:00 -!- Day changed to 2017-08-15{NORMAL_TEXT}
{BOLD_ON}01:33 Bob (whisper): {NORMAL_TEXT}Hi Alice
{BOLD_ON}{self.time} Bob (whisper): {NORMAL_TEXT}Hi Alice
""", window.print, msg_tuple)
def test_print_to_active_window_with_date_change_and_whisper_empty_message(self):
@ -266,7 +268,7 @@ class TestRxWindow(TFCTestCase):
# Test
self.assertPrints(f"""\
{BOLD_ON}00:00 -!- Day changed to 2017-08-15{NORMAL_TEXT}
{BOLD_ON}01:33 Bob (whisper): {NORMAL_TEXT}
{BOLD_ON}{self.time} Bob (whisper): {NORMAL_TEXT}
""", window.print, msg_tuple)
def test_print_new(self):
@ -287,7 +289,7 @@ class TestRxWindow(TFCTestCase):
# Test
self.assertPrints(f"""\
{CLEAR_ENTIRE_SCREEN}{CURSOR_LEFT_UP_CORNER}{BOLD_ON}01:33 Bob: {NORMAL_TEXT}Hi Alice
{CLEAR_ENTIRE_SCREEN}{CURSOR_LEFT_UP_CORNER}{BOLD_ON}{self.time} Bob: {NORMAL_TEXT}Hi Alice
""", window.redraw)
self.assertEqual(window.unread_messages, 0)

View File

@ -74,13 +74,12 @@ class TestProcessCommand(TFCTestCase):
class TestPrintAbout(TFCTestCase):
def test_print_about(self):
print_about()
self.assertPrints(CLEAR_ENTIRE_SCREEN + CURSOR_LEFT_UP_CORNER + """\
Tinfoil Chat {}
Tinfoil Chat {}
Website: https://github.com/maqp/tfc/
Wikipage: https://github.com/maqp/tfc/wiki
Website: https://github.com/maqp/tfc/
Wikipage: https://github.com/maqp/tfc/wiki
White paper: https://cs.helsinki.fi/u/oottela/tfc.pdf
""".format(VERSION), print_about)
@ -312,6 +311,7 @@ class TestExportFile(TFCTestCase):
self.assertFR("Error: Command is disabled during traffic masking.",
export_file, Settings(session_traffic_masking=True), None)
@unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skip as Travis has no $DISPLAY.")
def test_unknown_file_raises_fr(self):
# Setup
tkinter.filedialog.askopenfilename = lambda title: 'unknown_file'

View File

@ -36,8 +36,9 @@ from tests.mock_classes import ContactList, Gateway, GroupList, MasterKey, Setti
class TestInputLoop(unittest.TestCase):
def setUp(self):
if 'TRAVIS' not in os.environ or not os.environ['TRAVIS'] == 'true':
self.o_getrandom = os.getrandom
self.o_input = builtins.input
self.o_getrandom = os.getrandom
self.o_urandom = os.urandom
self.gateway = Gateway()
self.settings = Settings(disable_gui_dialog=True)
@ -72,15 +73,18 @@ class TestInputLoop(unittest.TestCase):
'/exit'] # Enter exit command
gen = iter(input_list)
builtins.input = lambda _: str(next(gen))
os.getrandom = lambda n, flags: n * b'a'
if 'TRAVIS' not in os.environ or not os.environ['TRAVIS'] == 'true':
os.getrandom = lambda n, flags: n * b'a'
os.urandom = lambda n: n * b'a'
self.o_exit_tfc = src.tx.commands.exit_tfc
src.tx.commands.exit_tfc = lambda *_: (_ for _ in ()).throw(SystemExit)
def tearDown(self):
if 'TRAVIS' not in os.environ or not os.environ['TRAVIS'] == 'true':
os.getrandom = self.o_getrandom
builtins.input = self.o_input
os.getrandom = self.o_getrandom
os.urandom = self.o_urandom
src.tx.commands.exit_tfc = self.o_exit_tfc

View File

@ -40,7 +40,9 @@ class TestLocalKey(TFCTestCase):
def setUp(self):
self.o_input = builtins.input
self.o_urandom = os.urandom
self.o_getrandom = os.getrandom
if 'TRAVIS' not in os.environ or not os.environ['TRAVIS'] == 'true':
self.o_getrandom = os.getrandom
self.contact_list = ContactList()
self.settings = Settings()
@ -51,7 +53,9 @@ class TestLocalKey(TFCTestCase):
def tearDown(self):
builtins.input = self.o_input
os.urandom = self.o_urandom
os.getrandom = self.o_getrandom
if 'TRAVIS' not in os.environ or not os.environ['TRAVIS'] == 'true':
os.getrandom = self.o_getrandom
for key in self.queues.keys():
while not self.queues[key].empty():
@ -72,7 +76,9 @@ class TestLocalKey(TFCTestCase):
self.settings.nh_bypass_messages = False
self.settings.session_traffic_masking = False
os.getrandom = lambda n, flags: n * b'\xff'
if 'TRAVIS' not in os.environ or not os.environ['TRAVIS'] == 'true':
os.getrandom = lambda n, flags: n * b'\xff'
os.urandom = lambda n: n * b'\xff'
input_list = ['bad', 'resend', 'ff']
gen = iter(input_list)
@ -204,27 +210,32 @@ class TestKeyExchange(TFCTestCase):
class TestPSK(TFCTestCase):
def setUp(self):
self.o_input = builtins.input
self.o_getrandom = os.getrandom
self.o_getpass = getpass.getpass
if 'TRAVIS' not in os.environ or not os.environ['TRAVIS'] == 'true':
self.o_getrandom = os.getrandom
self.o_input = builtins.input
self.o_getpass = getpass.getpass
self.contact_list = ContactList()
self.settings = Settings(disable_gui_dialog=True)
self.queues = {COMMAND_PACKET_QUEUE: Queue(),
KEY_MANAGEMENT_QUEUE: Queue()}
os.getrandom = lambda n, flags: n * b'\x00'
if 'TRAVIS' not in os.environ or not os.environ['TRAVIS'] == 'true':
os.getrandom = lambda n, flags: n * b'\x00'
getpass.getpass = lambda _: 'test_password'
input_list = ['/root/', # Invalid directory
'.'] # Valid directory
'.'] # Valid directory
gen = iter(input_list)
builtins.input = lambda _: str(next(gen))
def tearDown(self):
builtins.input = self.o_input
os.getrandom = self.o_getrandom
getpass.getpass = self.o_getpass
if 'TRAVIS' not in os.environ or not os.environ['TRAVIS'] == 'true':
os.getrandom = self.o_getrandom
with ignored(OSError):
os.remove('user@jabber.org.psk - Give to alice@jabber.org')