Improved exceptions thrown in configuration decryption and unit tests.
This commit is contained in:
parent
321dd2c55e
commit
9fcfaac781
|
@ -1,14 +1,17 @@
|
|||
import base64
|
||||
import io
|
||||
import json
|
||||
from typing import Dict
|
||||
import logging
|
||||
from typing import Dict, Union
|
||||
|
||||
import pyAesCrypt
|
||||
|
||||
from common.utils.exceptions import FailedDecryption, NoCredentialsError
|
||||
from common.utils.exceptions import InvalidCredentialsError, NoCredentialsError
|
||||
|
||||
BUFFER_SIZE = pyAesCrypt.crypto.bufferSizeDef
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def encrypt_config(config: Dict, password: str) -> str:
|
||||
plaintext_config_stream = io.BytesIO(json.dumps(config).encode())
|
||||
|
@ -19,15 +22,20 @@ def encrypt_config(config: Dict, password: str) -> str:
|
|||
)
|
||||
|
||||
ciphertext_b64 = base64.b64encode(ciphertext_config_stream.getvalue())
|
||||
logger.info("Configuration encrypted.")
|
||||
|
||||
return ciphertext_b64.decode()
|
||||
|
||||
|
||||
def decrypt_config(cyphertext: str, password: str) -> Dict:
|
||||
def decrypt_config(cyphertext: Union[str, dict], password: str) -> Dict:
|
||||
if not password:
|
||||
raise NoCredentialsError
|
||||
|
||||
try:
|
||||
cyphertext = base64.b64decode(cyphertext)
|
||||
except TypeError:
|
||||
logger.info("Configuration doesn't require decryption.")
|
||||
return cyphertext
|
||||
|
||||
ciphertext_config_stream = io.BytesIO(cyphertext)
|
||||
dec_plaintext_config_stream = io.BytesIO()
|
||||
|
@ -43,7 +51,11 @@ def decrypt_config(cyphertext: str, password: str) -> Dict:
|
|||
len_ciphertext_config_stream,
|
||||
)
|
||||
except ValueError as ex:
|
||||
raise FailedDecryption(str(ex))
|
||||
|
||||
if str(ex).startswith("Wrong password"):
|
||||
logger.info("Wrong password for configuration provided.")
|
||||
raise InvalidCredentialsError
|
||||
else:
|
||||
logger.info("Configuration is corrupted.")
|
||||
raise ex
|
||||
plaintext_config = json.loads(dec_plaintext_config_stream.getvalue().decode("utf-8"))
|
||||
return plaintext_config
|
||||
|
|
|
@ -0,0 +1,206 @@
|
|||
MALFORMED_CYPHER_TEXT_TOO_SHORT = (
|
||||
b"AES\x02\x00\x00\x1bCREATED_BY\x00pyAesCrypt "
|
||||
b"6.0.0\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
)
|
||||
|
||||
MALFORMED_CYPHER_TEXT_CORRUPTED = (
|
||||
b"AES\x02\x00\x00\x1bCREATED_BY\x00pyAesCrypt "
|
||||
b"6.0.0\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
b"\x00\x00\x00\x00\x00\xc2\xc3w0\xe5\x06\xd2\xb9\x05b\xce\xb2\xc7"
|
||||
b"\x18f\x87j|y\xcd\xbd\\("
|
||||
b"V\xfa!%\xcc@\x11\x98>\x9c^\x11\xa1\x82\xe9@\x89\xde\xe9\xb2)h\xb2"
|
||||
b"`\x07y\x01\xa8zr\xd0\xe2\xb9m\xb1&\xb5f\x95\x80\x98\xac\xa6\x04.8"
|
||||
b"\xf0\xbf\xee\x18!\xf5T\x04a\xb5\xb2Q\xb0|\xff\xe7\xdd)F\xd5E\xa6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92\x19*~\x93b\x13\xed"\xd2\xcaV\x05R.&D\xb0m'
|
||||
b"\x93rb\x15\xe2=\xfb\xb9\xcc+\x0f\x9c\x1c\xff\xe4\x18a\x85\xe4\xd0s"
|
||||
b"\xed\xc3H\x88\x07P\xbed\x0c\xf7\x97j\x1d\xf2'\xce&\xbe1A\xca\x0e"
|
||||
b"\xb3H\x08\x01\xc5\x87F#\xf6TB\xc5\x9f\\\x9ex\x06\xd3\x85&\xdf\x9a"
|
||||
b"\\X\x1d\x9bm\xe60\xf3;\x06\xa9o7\x99\xa3:\xce\xbb\xba\xe3\xc4\xe5"
|
||||
b"\xa9\x01\xfbJ\x11tJ\xd4\xc7\xc7\xf1s=8k\xc29c\x8c\xdfdA\xf76\xdd"
|
||||
b"\xdd\xf8\x16\xf3\x8d\x96gP\xad\xd4\r1\xd3\x1d@\xbb#o\x98\x13\x9d"
|
||||
b"'\xb2\xb5\x1dl\xe5\x01\xce\x0f\x80\x7f5\x80\x1dp>\xee_\xc2OK\x95"
|
||||
b"\xd5\x16E\xea\x82\xf5\xa8\x88A\xa2\x1e\x0c\xc8\x05\x81\xda\xfe\xb6"
|
||||
b"\xe5\x8f\xd8W\xb4\xbeS\xcd\x130\x0c\xa4\xd9\x1d\xf6\x96\xa3\xee"
|
||||
b"\xb30\xbd "
|
||||
b"\t\\\xd6\xa1\x8b\x85\x16\xf6dJ4\xd7\x85\x96|3\xae\xab\xb7>\xf8\xf9"
|
||||
b"\xf7h\x8f\xcc\x9b=B]G\xd5L3g\xbd%\x84\xbe\xf4\x8a\x07\xb3\x863"
|
||||
b"\xc2uz\x84-\xe436\x14\xbd\xda\xc74.\xdan\x8e\x04VJq\xcdo\x8a\x05"
|
||||
b"\xe6\xec\x84\xdc\xa9\x84\xb3\xa5T\xa7M\x05\xfc\xc3\x04\xd6p\xb0y"
|
||||
b"\x83\xc2\xc7i\x9at.\x1dh\x99\xfe}(\x98\xa7){"
|
||||
b"\xa9\xa6\xa63\xcc'0A\xd9Q\x99-\xd0$)\xbda\xa0\xbf#\x9e\x19\xe5"
|
||||
b"\xb7q\x89\xda\xbaj\x1b\xe3\x8aW\xb6\xd0\xc5\x819\xfa\x8d\x9a\x14"
|
||||
b"\xaf\xb1\x08\x97>*\x7f("
|
||||
b"\x9c\xd3\x99o3\xbew'/\x14\x9e\x9f#_\xaaDgg\xa6\xc7\xa6}8J\x14\xa8"
|
||||
b"\xcb\xbf\xdeQ,"
|
||||
b"zHze\xbfe\xdfr|\xbd\x9dd\xfb\xccq\x18\x9dw\x01\xe5JY\x1b\xca\x12"
|
||||
b"\xaed]\xadi\x7f\x0c`6\xb6X\xbe0\x83b\xc6\xc5>\x1e\xab\xfa\xb7\x0c"
|
||||
b"\x08\xf6\xa9\xed\x14\xc9(\xf1m\xc6\x90w\xe9\x85\x9d{"
|
||||
b"\xba\x93x\x00\xf7\x8d\x0f\xa2\xef\xc5\xfexp\xb2\xa9\xf4\xbb\x80"
|
||||
b"\x13\x8e2bm\xf0U2\x1a\xa7\xa4PK\x11\xc7\xab3\n\xe5("
|
||||
b"y\x05\x1a\x07\x0e\x8cO\xee\xc9\x83\x84L\xae\x19\xc1\xab\xbf\xc9"
|
||||
b'\xae\x8a\xe3\xbb\x19c\x0f0\xa9\xe8\x1e\xfe\xcb\xa3T"p\r\xe8b}Y\x86'
|
||||
b"\xc0s\x9d\x1bc\xd6\xec\xab6\xd5\xcf\xfaw\x7f\xa8K\xe4Z4Sj\xe8\xda"
|
||||
b"`\xe9\x8e\xf0M\xee5G\xc6\xb6\xef\x97\r&C\xa60\xcc\xf4\xb8\xd0a\x16"
|
||||
b"!\xda=\xd4\xb4\x84\xc6\x99\xf4\x9c["
|
||||
b"\xda'R\x80\xf1\xa2m\xe0\x14\x1b\xe2\xee\xd6\x81\xf2\x19\xe6\x9aC"
|
||||
b"\xac6\xb8\xe9\x89\xe9\xb4UM\x027\xc4("
|
||||
b"\n\xe3\x8a\x85a\xad7~\xa71\xd1w065a\x87T\xbc\x89v\xca\xe4\x80\x9f"
|
||||
b"\xe1\x10p\x1c\x14\xc2\x0c-\xd4q\x0e'\xcf["
|
||||
b"\xe0\x163Jj\xd1\x03u%B:\xda\xc9\x08*\xf1\x1d,\x80,,"
|
||||
b"I\xcc\x8c\xe9\xb8<SeV\xfd\x89\x15\xbd\x85\x14d'\xd1<\xc6\xd0\xe9"
|
||||
b"\r\xc0r\x05\xe7\xb3\x190\x99\xae*\xfa\xc0\xcam2\xe2\xf4ZK\xe6\x99"
|
||||
b"\xc5s1Y\x9f\x05\xdc\xdb\xb2\xf3;\xf8\r\xdd\xe1A\x9b/|\x07\x08\xb9P"
|
||||
b'+W\xe1c]\x93\x12\xaa{"ra\xf08['
|
||||
b"R\xec\xe8m\x8a\xdf\xc6z\x84\xdd4\xb87\xc4\x9d\x9e\xd0\xde\x10\x00"
|
||||
b"\xd1\x00\xb8\xae\xb8#uQ=c\x12\x1c\xef\x96\xec\x1a\xfe.I\x14\x8f"
|
||||
b"\xf8\x07\xb8E<\xac\xf5q\xb6\xcd\x94v\xe7\x86\xa8\r\xdf\xdb\x93\x9a"
|
||||
b"\x9c\xfb\xbf^\x9eg\xa2\xb9\xb1\x8e\xbe*\xd5\xea\xcd\xc1\xfbt\xc0"
|
||||
b"\x98t\xfa>U{"
|
||||
b"\xcb\xde\x8b\x1dB\xd9\xa1\xf1\xcfY\x14\x16\x86\xd9\xe4\x8d\xc0\xc5"
|
||||
b'<^\xce"\n\xdd\xdf\x1cb\xf1M\xb8\x10$\xcf\x04\x1bU*\xe9\x19\x8c\xf7'
|
||||
b"\xff\xfdl\xaf\x92\x11\xdb{"
|
||||
b"\x1c\\<Dr\xea\x94\xd8*!\x15\x80!\x8b\xb57\xe9\xb9cW\xdc\x0c\xf9"
|
||||
b"\x8f\xdfUe4\xa95\xba\xe0B\x1c\xf4v\x11\xd0u\x0c\x13t\xbc\xec>\r"
|
||||
b"\x90\x0fva,"
|
||||
b"\xcc\x18j\xab\"4'\xd3\xcfo|yE\xb8\xa1\xc0\x927\xa7\x1dh\xba\xab"
|
||||
b"|\x8b\xeb\xf2G\xcc\xd2a2al\xa55\xb6\xd5\xc5\xc1\xa6q\t\xca\xf4\xdc"
|
||||
b"\x9b\x00\x9b\xe2\xa3\xd7\xd4\x19\x88\x05\xb2\x0e\xc8\xf3\x0b>\x18"
|
||||
b"\xcfd\x05m\x85\nB*\xa2$\xf6I'\xe4\xa2_w1*\xe2z4#\n\xcf\xd9J\xa3"
|
||||
b'\xf9q\xc4\xc1"\xf9\xbd\xb3J,'
|
||||
b"J\xd4v+U\x8c\xafG\x86\xae\xce/w\xee\x94x\xb1h7z\xbd\x02\x12\xc6"
|
||||
b"\x16\xcb\x14\x80(\xab\xfb\x16{"
|
||||
b"\xb2\xd1\xe9\xd9\xd7\xd9\x9bq`\xdfRB5\x04t\x8d\nq\x1a\r@k\xec\x04"
|
||||
b"\xb2\x8c\x00\x00\xe4\x86;\xae\xbe\x9b\x0ccp\xdd\xb8~\xb6\x9b1\xf1"
|
||||
b"'\x12\x99<j\xe4\t\x0b\x14\xb6.\xc4^\\\x9d\x1axJ*\xcc\x9b\xce\xff "
|
||||
b"\xa4G\x03\xd7_#\x87Q\x1b\xce\x99\xbb\xf5\x114\x82\x0b\xe5,"
|
||||
b"\x15\xc6\x1b\xb3\xeer#6\xd9\x1f\x14\x7f\xba\xd57\xfe\x06\xf5\x01"
|
||||
b'\x03\xed\xda\x81"_\xb6o\xf2 '
|
||||
b'|!r\x9b\xdd\xd0\xb7%\xf4&\x8b\x81\xd08L\xf8\xc1"U|g\xf3\xc2\x98'
|
||||
b"\x10;!b\x8e\xebF\xf2\x08\xc3\xafZ\x9b\xed\x81\x9eg\x1e\x98G@\xb3"
|
||||
b"\xc2\xdb\xe07\x9e\xa9\xd3\x1a(\xc5\xca\x95\x89\x01&\xfb^\xe6$,"
|
||||
b"\x14o#\xba\x85\xcc?O9 "
|
||||
b"s\x14p\x02\xf8\xd3v\xeb.+/L\xde\x05\xcd\xb4\xae\x81A\x9a\xb9\xc9"
|
||||
b"\x1a+<\x81\xcew\xd1\xa9~3c]\xbe;>\xab\xcah\xd1i\xa9r\x18\xfc\x93"
|
||||
b"\x86W{{\x92\xa9("
|
||||
b'\xee"C\xa3uG\xc3s\xb8\xc6\xb7\xb9\x17\xf3\xe3n;\x16\x08\x9e,'
|
||||
b"\xbd\x0f\xbe.\xd9\xc3F\xa0\xfe\x84\x1f\x8a\x97\xc9T\xea\x08_\xc5I"
|
||||
b"\xf9v\tI\xf0\x0e\xbex\xd9\x9f\xe7Z\xd6\x1a]\xc1\xbb\x97 "
|
||||
b"\x8a\x8f\x00\x1f\x92.\xc1WC\xd8\xe3\x86\x98PV\xfbWV\xbd\xdf\xd5"
|
||||
b">1yo\xf1\xabV\xb2\xdf\x97\x82$0\xc8#\xbe\xbb\xe1\xed\x08\x8c@7\xab"
|
||||
b"~\xdf\x8c\xf9\xbb\x9e\xc6\xa0Q\x85}\xe7\x00|\xe7'\x00{"
|
||||
b"\xd9v1\xd5\x8a-C,"
|
||||
b"\xa7S\xfc\xc3\x83\xef\xadV\x1b\n\x1b\xb3\x0bK\xa0\xc6\x02i\xf6\x80"
|
||||
b"\x06F>\x01\x01\xef\xe3\x19\xbf\xb1\xe0S~9\x88\xc5\x9a{"
|
||||
b"K\x9e8rFp\xa3\xcclX,"
|
||||
b"\xe5\xf1o\x90\xa3\x13\x9c\xf0\xcd\xf3l@\xb60\xde\x19\xcen\x19\x80w"
|
||||
b"\x0b\xfd\xa8\xafuP\xef-/\x92*\xdd\x93\xdc=9\x90\x0f-\xc4wxa\xc1"
|
||||
b"\xb7SSe\x0fY\xc3!\xee\x16\xdc\xf8\x93\x03<\x1d?\xec\xce\xcf\xd5"
|
||||
b"|)\xabu;Y!\xd6M\xcc\xbd\xcc\xec\xa6J\xb7\xbci\x91)\x14h\xec\xc3R"
|
||||
b"\xb6/\xfcA\xab\x9f\xb8.W\x92\xc4\x8b\xa3D\x91\x8a\xb1\xbc\tJ\xd5"
|
||||
b"\xb98\xe6c\xcc\xa6'\xb7NK\xf8\xdal\xabd\xc4\xde\xea\xd4~\t\xd9"
|
||||
b"\xd3\x7f\xb8\xe1J\x8e\xf9X\xe4\xcd\x04\xa0\xc0vp\xe9\xe7\x8e\xd0["
|
||||
b"m\xe2\x8dY\x8c\xcd\x81Ny\xac\xbb`\x10ky\x1c\xe3\x9a\x1b\x88G\x1d"
|
||||
b"\xdc\xc8\xa6\xf7\x1f\xbf\x87\xe9\xac\xfc5/\x8c\xf7k\x85\xb8\xc7d"
|
||||
b"\x11\xe2\xd8T\x0c\x1a\x85\xc5\x93-\xfe\x85\x87\x03\xb4\x97\x97"
|
||||
b"~\xb5\xcf|\x05\xf4SE1\xddf?\xae\xe5\xfd\x8c\xf0qu\x92sPz`\xa2\xb6"
|
||||
b")\xa1\x08A\x18\xb0>\xc4\t\x17|\xac\xccH\x7f\x85\xd2zCK\xf7\xf5"
|
||||
b'\x12{\x7f_\xc2"\xd6XQ>\x12W1\x06\xbe\xa1\x0f\xf0K\xd9\xaa\x1a\x90'
|
||||
b"\xee\x90U\xf0\xec$\x1a\xc4\xe07\x92\x1f\xc4\xb5g\xebz\x900\x04\xb6"
|
||||
b"\xec\xdd\x19iG\xfc=\xef\x0f\xaap\xb4h\xda\xcak\xf9\xc2\xdf%]\xad"
|
||||
b"\xf5|\x19\xd2\xe46\xb6\x11k#\xf6\xa7t\xc1\xf4\x13B\x08\xeej\xe89"
|
||||
b"\xbe\xfc\xbds\x19\xcf\xe5'\x84P\xf5\xd5\x88\x18\x1d`k\t%\xb9{"
|
||||
b'\xa1\xec&\x9f\xee$R"\x81(\xe25V8m\x84\xa3Qb=CZ\x1d\xc6\xc7{'
|
||||
b'\xc9"\xfcSW\xdb\xce\xd5\x0f%\xff\x85\xbb\xcbS\x83+\x9aA\x1e\xe6uf'
|
||||
b"\xf9\xa8K\xc3(\xaa/\xe8["
|
||||
b"\xa9U|M\x0f\xdb\xea\\\xf5\x06\xbeK\xb67>~\x8a-\x8b\x08\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5\x89\x85\x9c\x1a\r.\xcc\xe1x\x9f\xc3\x10\x7fc"
|
||||
b"\x00'\x10h\x1f\x82\x1e\xcel\xc1\xe3\xe5R<O\x18\xc1f\xee}\xef\xbd"
|
||||
b"\xc5\xe0("
|
||||
b"VjO\x874+\xf2X\x0fWTo\x82\\\x9d/_\x894\xfb6#\xa5\xb4`\xe7\x90O\xf8"
|
||||
b"\xad\xc4R\x97\xe1\x18h\xe5\xb40.\xf7Y\xf3Bp\x82\xf3\x13\xdc\x06"
|
||||
b"/1yB\xe5\xbc_\x016\x00\xf8\xd22\x80\x9d\x94\x08)\xd2\x8d\xf3s2\xa1"
|
||||
b"\x88\xe7\xfbu3Ak\x98\xf3\xf0\x89\x80\xc1\xe1\xa6y\xb4\xe6\xb9\xce"
|
||||
b"\x08&\xef\xd0\x10\xd59\xa3!YS\x9d\x98\x1b\x08\xd7\x8f\xdcA\xb9\xfa"
|
||||
b"\xf6(\xb7Xf\xbbB7\x1a\x9e\xab\x1f\xd7\x01\x9a7\xbe\xe5a\x17\xd2"
|
||||
b"\x9e1+tS "
|
||||
b"\x12\x7f\xc7\xaf\x1d\x95f\xbc\x83\xbb\x86\xff\xac\x8ap\xd0y\xaf$r"
|
||||
b'\x08sh\x81\xd4\x85\xfe\x04\xe3-\xfe?\xa1"\x83m\x19\\u\x13~\xfc\x12'
|
||||
b"\xd3\xa8\x88%\xc9\xc7G\xa2.OH\x133`K)_\xe3\xcd\xfaC*R\xaf\x16\xcf"
|
||||
b"\xb9\x0f\xb7\xb8\xd0\x95\x91\x11\x89o\x16\xdd{"
|
||||
b"E\x01\xa6\xa2\x8d\x8b\xd2\x877`\xd0\xacB\x93e5C\x9d\xcer\x16\xa6"
|
||||
b'\x80\xdfx\x0f\x15\xf0\xc9\x9c\xaey\x8b\x13\x1dE"\xe8^\x9f\x96n'
|
||||
b";\xa8\xf9\x08\x93\xa8\x1fQ\xfa\xa5e\xa2e\xd9\xed\xdfH\x1f\x99\xe6t"
|
||||
b";R\xe5=\xff\x81\xab\xd0\x8d\x85\xc8\x9f\x82\x11 "
|
||||
b"\x03\xa0\x92\xb0\x17\xeb\xda\x14\xeb\x11\xd9\x08b\x0b\xba\x86\xb3U"
|
||||
b"\xf2\xf3\xbdr\t\xc6\x0f\xa8\xd5\x98\xf7\xe5N\xc6\x8d\x8c\x11\xe36"
|
||||
b"\x8c\x10/\x7fG\xd5\x96\x1f\x9d\xdfm\xbd\xcf\x9a:\x0ec\x1d\x88\x94s"
|
||||
b"\x90A\x94\xd0\xde\xe9\xfd\x7f\xf3\xb2\x0b\x16\xeb\x15v "
|
||||
b"A\xa6A\xa9:\xaa>q\x10\xa2=\xe2\x1f\x93\xff\x04\xd8\xd3\x1eL\x8e8W"
|
||||
b"\xef!\x8e\xdb\x14\x1c\xa1tz\xee\xca\x89dA\xe1\xa9K\x96/\x96\xc9YS"
|
||||
b"\xcc\x07vM\xaeCi\xfc\xfdA\x01,"
|
||||
b"\xb0\x06J\xb7\xf5\x84\xf7\x1e\xc6\x05\xc5\tw\x9e\xf4\x0bH~.ah\x04"
|
||||
b"\xce%\xbdK\xc4\xbbM\x82\x0c\xcd\xf4\x99\x9c\xa5^\x97\xfcj\xbe"
|
||||
b'"_\x01\xec('
|
||||
b"\xd4\xb8\xddmF\xe9S\xaa\x92\xdc\xa4a\xee\x02\x84N\xe6\xb1\xc8\x1b"
|
||||
b"\xb0\xb6\x90#>\xaeKk:\xf6\xef\x10\xe8\x03q\xac\\\x19\x1f\x17r\xc7"
|
||||
b"\xdf\xce\x8fC\xd8\xb3C\xf8\x99\xb5\x15\x8a\x9b\xdc\xc0\xd1U\xa7.B"
|
||||
b"\x9c\xb3\xe0G\x90Qf|\x9d\x97v\xfbD\x95B\xf3\xa1\xa6=\x08\xea\xee"
|
||||
b"\xfd\xa9\xaa:\x80\xeb\x992\xcf\x9ed\x16\xd2\x92\xdaW\xd1\xb4P"
|
||||
b'\\\x9e\x9d"\xcb\xc3\xf0Q\xeb\x96\x90*\xaf\xe2{'
|
||||
b"\xf6y\xf6\xc6\x87jM'G\xcb,"
|
||||
b"\x9c\xbb\xcc\xf3\xab\xf4\xd0\xd7\x0c\x98H\n\xbb\xf0\xc2\x16\xe6"
|
||||
b"\xcd\xd8\xa0\x02@6\xcbg\x1a\xc7\x16\xd4r\x0f\xbb\x04\xad\x1dY\xa0"
|
||||
b":\x086d\x10V\xd5\x1cbKA\xb0\xbcjd\x9d8\xfc\xbc~\xeb!\xf8\xf0\xf4"
|
||||
b"\xd2\x06\x9c<\xdcK\xda\xdbi\x1b\xf3\x9d\xdb\x97\xfe\xdfq("
|
||||
b"'\xb8\x8b(\x06o\x06\xba\x9a\x1d\xc6U_<9\x820,~\x92Z^\xf1 "
|
||||
b"\xa0\xa5\xd1\xd4h\xae\x90u\xf5\xe8\x87&\xe9\x94\xec\xa9\xaa\xc7"
|
||||
b"\x7fW\xd5\x99\x86\xa3\xf5rWa\x9f\xbb]D("
|
||||
b"zF\xa9\x04\xa2PZ\\\xe5\xff\xac\xa0\x93xV\x93\x9d\x0e\xe8?\x9d\xa1w"
|
||||
b":m~\x92a\x98I\xdf\xe8\xf3\xae\xed\xf5\xfd("
|
||||
b"rj\xb2\x86\n7@\xe6=\xed\x1b\x91\xe3No\xdf:c\\_\xb4z\xdej\x98\xf4G"
|
||||
b"\xaeES)\xcb\xbeu\xb7\xec\x00t1W("
|
||||
b"J\x85L\xa7\xf8B\x14\xc4w\x99\xbe~\xef\xabp\xf3\x02\xbf!\xd4\xca"
|
||||
b"\xc1U\x13\xf2\xc0k&\xb3V\xc1Bu:\x1f\x910k&*\x84\\r\x1f0\xdc\xd8"
|
||||
b"\x05Kg\xc1e\x125["
|
||||
b"q\x9b\xe9;Hb\x19S\xfcP\xb3\xa7\x88\xcb)P\x1c\xe1\x06F\xc3\xeb\x08"
|
||||
b"\xbd"
|
||||
)
|
|
@ -2,13 +2,18 @@ import json
|
|||
import os
|
||||
|
||||
import pytest
|
||||
from tests.unit_tests.monkey_island.cc.services.utils.cyphertexts_for_encryption_test import (
|
||||
MALFORMED_CYPHER_TEXT_CORRUPTED,
|
||||
MALFORMED_CYPHER_TEXT_TOO_SHORT,
|
||||
)
|
||||
|
||||
from common.utils.exceptions import InvalidCredentialsError
|
||||
from monkey_island.cc.services.utils.config_encryption import decrypt_config, encrypt_config
|
||||
|
||||
MONKEY_CONFIGS_DIR_PATH = "monkey_configs"
|
||||
STANDARD_PLAINTEXT_MONKEY_CONFIG_FILENAME = "monkey_config_standard.json"
|
||||
|
||||
PASSWORD = "hello123"
|
||||
INCORRECT_PASSWORD = "goodbye321"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -22,5 +27,21 @@ def plaintext_config(data_for_tests_dir):
|
|||
|
||||
def test_encrypt_decrypt_config(plaintext_config):
|
||||
encrypted_config = encrypt_config(plaintext_config, PASSWORD)
|
||||
encrypted_config = encrypted_config
|
||||
assert decrypt_config(encrypted_config, PASSWORD) == plaintext_config
|
||||
|
||||
|
||||
def test_encrypt_decrypt_config__wrong_password(plaintext_config):
|
||||
encrypted_config = encrypt_config(plaintext_config, PASSWORD)
|
||||
with pytest.raises(InvalidCredentialsError):
|
||||
decrypt_config(encrypted_config, INCORRECT_PASSWORD)
|
||||
|
||||
|
||||
def test_encrypt_decrypt_config__malformed():
|
||||
with pytest.raises(ValueError):
|
||||
decrypt_config(MALFORMED_CYPHER_TEXT_TOO_SHORT, PASSWORD)
|
||||
with pytest.raises(ValueError):
|
||||
decrypt_config(MALFORMED_CYPHER_TEXT_CORRUPTED, PASSWORD)
|
||||
|
||||
|
||||
def test_decrypt_config__unencrypted(plaintext_config):
|
||||
assert plaintext_config == decrypt_config(plaintext_config, PASSWORD)
|
||||
|
|
|
@ -169,6 +169,7 @@ build_from_config_file_contents # unused method 'build_from_config_file_content
|
|||
mock_port_in_env_singleton # monkey\tests\unit_tests\monkey_island\cc\services\test_config.py:26:
|
||||
ISLAND # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:14)
|
||||
MONKEY_LINUX_RUNNING # unused variable (monkey/monkey_island/cc/services/utils/node_states.py:26)
|
||||
import_status # \monkey_island\cc\resources\configuration_import.py:19
|
||||
|
||||
# these are not needed for it to work, but may be useful extra information to understand what's going on
|
||||
WINDOWS_PBA_TYPE # unused variable (monkey/monkey_island/cc/resources/pba_file_upload.py:23)
|
||||
|
|
Loading…
Reference in New Issue