From ac9bd8dee76ad39a54965a132b59dfc4d0ea2b1f Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 19 Jul 2021 08:56:48 -0400 Subject: [PATCH] Tests: Remove two extra calls to encrypt_string() Calls to encrypt_string() result in calls to pyAesCrypt.encryptStream(). These calls are very slow (about .150ms). Modifying these tests to use static ciphertext instead of encrypting the file each time saves approximately 300ms when running the unit test suite. --- .../utils/ciphertexts_for_encryption_test.py | 58 +++++++++++++++++++ .../services/utils/test_config_encryption.py | 13 ++--- 2 files changed, 64 insertions(+), 7 deletions(-) diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/utils/ciphertexts_for_encryption_test.py b/monkey/tests/unit_tests/monkey_island/cc/services/utils/ciphertexts_for_encryption_test.py index b35513a2a..0fa7131e0 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/utils/ciphertexts_for_encryption_test.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/utils/ciphertexts_for_encryption_test.py @@ -1,3 +1,61 @@ +VALID_CIPHER_TEXT = ( + "QUVTAgAAG0NSRUFURURfQlkAcHlBZXNDcnlwdCA2LjAuMACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPzzL7yzdvBdhwJiYrRRb/0f4hmQSN9OaYNfqcXKk/c0vnzqWh1Yo7AAjODs2D" + "nZU7bp1VxM3OE/iHLK8+YOD6TVcJMMSk5TdaHyuo/oCcWSA5xHGhSUPQEXk+sPglNv/PO1qyHFQl9m2nAvwdfsJpdYi5Fi" + "6euP9XBy3mViu70IrxqNAgc8DdWqAII4Y9UW+x2jnLgnBT6NBk0DWXMyWZ3+aji+D1hb9DTwAn+/5HQWviFASwEwMaoYFV" + "/Guy3M7NG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phYK6eVO5FbClmc+w7np2ugFZ231isdHYaMRe4VaXA7YkVqMuiBY4ZXrnA" + "vtBZRzNGgSoFMmHQ0WebwipLXjJpLoQDktWItFbY1AI5MeJDu1fLR6EK9c5opCk/doK9RozfPfyinh9oBfZ3ZmSdY1WOxj" + "LGc3QmCXFbxapAFNdzS8satGjn/VV1ZbhZBU7fzW1auiRxk1H0/CjWK0w1g2KQ2DRPG2vPpLAJVjy3cyNn0oS6YgDStDN2" + "fUtRYH1oBt6cIeW4K8Mp7I1fD+Wa45ZFonmeeuBj53S6k+Ov2aX5cIUeRrB4tvmkBosYdL9N+lr1wORZLj2us8IWmnlKh4" + "nmV0tcZxh5kBZW1vgP+LWHEN4ialItBPmsggRWqyBSVTr8tbtLEaJrlZ2NXiUFhcVJkggItwU02Ueesvjpjngfd/UluO/d" + "5pnm3dizp6Q=" +) + MALFORMED_CIPHER_TEXT_CORRUPTED = ( "QUVTAgAAGM0NKEYTESTURfQlkAcHlBZXNDcnlwdCA2LjAuMACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/utils/test_config_encryption.py b/monkey/tests/unit_tests/monkey_island/cc/services/utils/test_config_encryption.py index 23b399cc5..086b30109 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/utils/test_config_encryption.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/utils/test_config_encryption.py @@ -1,6 +1,7 @@ import pytest from tests.unit_tests.monkey_island.cc.services.utils.ciphertexts_for_encryption_test import ( MALFORMED_CIPHER_TEXT_CORRUPTED, + VALID_CIPHER_TEXT, ) from monkey_island.cc.services.utils.encryption import ( @@ -20,18 +21,16 @@ def test_encrypt_decrypt_string(monkey_config_json): assert decrypt_ciphertext(encrypted_config, PASSWORD) == monkey_config_json -def test_encrypt_decrypt_string__wrong_password(monkey_config_json): - encrypted_config = encrypt_string(monkey_config_json, PASSWORD) +def test_decrypt_string__wrong_password(monkey_config_json): with pytest.raises(InvalidCredentialsError): - decrypt_ciphertext(encrypted_config, INCORRECT_PASSWORD) + decrypt_ciphertext(VALID_CIPHER_TEXT, INCORRECT_PASSWORD) -def test_encrypt_decrypt_string__malformed_corrupted(): +def test_decrypt_string__malformed_corrupted(): with pytest.raises(ValueError): decrypt_ciphertext(MALFORMED_CIPHER_TEXT_CORRUPTED, PASSWORD) -def test_encrypt_decrypt_string__decrypt_no_password(monkey_config_json): - encrypted_config = encrypt_string(monkey_config_json, PASSWORD) +def test_decrypt_string__no_password(monkey_config_json): with pytest.raises(InvalidCredentialsError): - decrypt_ciphertext(encrypted_config, "") + decrypt_ciphertext(VALID_CIPHER_TEXT, "")