Exemple #1
0
 def _get_plaintext_config_from_request(request_contents: dict) -> dict:
     try:
         config = request_contents["config"]
         if ConfigurationImport.is_config_encrypted(request_contents["config"]):
             config = decrypt_ciphertext(config, request_contents["password"])
         return json.loads(config)
     except (JSONDecodeError, InvalidCiphertextError):
         logger.exception(
             "Exception encountered when trying to extract plaintext configuration."
         )
         raise InvalidConfigurationError
Exemple #2
0
def test_decrypt_string__no_password(monkey_config_json):
    with pytest.raises(InvalidCredentialsError):
        decrypt_ciphertext(VALID_CIPHER_TEXT, "")
Exemple #3
0
def test_decrypt_string__wrong_password(monkey_config_json):
    with pytest.raises(InvalidCredentialsError):
        decrypt_ciphertext(VALID_CIPHER_TEXT, INCORRECT_PASSWORD)
Exemple #4
0
def test_decrypt_string__malformed_corrupted():
    with pytest.raises(ValueError):
        decrypt_ciphertext(MALFORMED_CIPHER_TEXT_CORRUPTED, PASSWORD)
Exemple #5
0
def test_encrypt_decrypt_string(monkey_config_json):
    encrypted_config = encrypt_string(monkey_config_json, PASSWORD)
    assert decrypt_ciphertext(encrypted_config, PASSWORD) == monkey_config_json