def test_encrypt_payload_with_params_in_headers(self):
        self._set_header_params_config()

        test_headers = {"Content-Type": "application/json"}

        api_encryption = to_test.ApiEncryption(self._json_config)
        encrypted = api_encryption._encrypt_payload(body={
            "data": {
                "secret1": "test",
                "secret2": "secret"
            },
            "encryptedData": {}
        },
                                                    headers=test_headers)

        self.assertNotIn("data", encrypted)
        self.assertIn("encryptedData", encrypted)
        self.assertIn("encryptedValue", encrypted["encryptedData"])
        self.assertEqual(1, len(encrypted["encryptedData"].keys()))
        self.assertIn("x-iv", test_headers)
        self.assertIn("x-key", test_headers)
        self.assertIn("x-cert-fingerprint", test_headers)
        self.assertIn("x-key-fingerprint", test_headers)
        self.assertIn("x-oaep-digest", test_headers)
        self.assertEqual(6, len(test_headers.keys()))
    def test_decrypt_payload_with_params_in_headers_skip_decrypt(self):
        self._set_header_params_config()

        test_headers = {
            "Content-Type": "application/json",
            "x-key":
            "Jmh/bQPScUVFHSC9qinMGZ4lM7uetzUXcuMdEpC5g4C0Pb9HuaM3zC7K/509n7RTBZUPEzgsWtgi7m33nhpXsUo8WMcQkBIZlKn3ce+WRyZpZxcYtVoPqNn3benhcv7cq7yH1ktamUiZ5Dq7Ga+oQCaQEsOXtbGNS6vA5Bwa1pjbmMiRIbvlstInz8XTw8h/T0yLBLUJ0yYZmzmt+9i8qL8KFQ/PPDe5cXOCr1Aq2NTSixe5F2K/EI00q6D7QMpBDC7K6zDWgAOvINzifZ0DTkxVe4EE6F+FneDrcJsj+ZeIabrlRcfxtiFziH6unnXktta0sB1xcszIxXdMDbUcJA==",
            "x-cert-fingerprint":
            "gIEPwTqDGfzw4uwyLIKkwwS3gsw85nEXY0PP6BYMInk=",
            "x-key-fingerprint":
            "dhsAPB6t46VJDlAA03iHuqXm7A4ibAdwblmUUfwDKnk=",
            "x-oaep-digest": "SHA256"
        }

        api_encryption = to_test.ApiEncryption(self._json_config)
        decrypted = api_encryption._decrypt_payload(body={
            "data": {
                "key1": "notSecret",
                "key2": "anotherValue"
            },
        },
                                                    headers=test_headers)

        self.assertDictEqual(
            {"data": {
                "key1": "notSecret",
                "key2": "anotherValue"
            }}, decrypted)
        self.assertEqual(5, len(test_headers.keys()))
    def test_encrypt_payload_with_params_in_body(self):
        api_encryption = to_test.ApiEncryption(self._json_config)

        test_headers = {"Content-Type": "application/json"}

        encrypted = api_encryption._encrypt_payload(body={
            "data": {
                "secret1": "test",
                "secret2": "secret"
            },
            "encryptedData": {}
        },
                                                    headers=test_headers)

        self.assertNotIn("data", encrypted)
        self.assertIn("encryptedData", encrypted)
        self.assertIn("encryptedValue", encrypted["encryptedData"])
        self.assertEqual(6, len(encrypted["encryptedData"].keys()))
        self.assertDictEqual({"Content-Type": "application/json"},
                             test_headers)
    def test_decrypt_payload_with_params_in_body(self):
        api_encryption = to_test.ApiEncryption(self._json_config)

        test_headers = {"Content-Type": "application/json"}

        decrypted = json.loads(
            api_encryption._decrypt_payload(body={
                "encryptedData": {
                    "iv": "uldLBySPY3VrznePihFYGQ==",
                    "encryptedKey":
                    "Jmh/bQPScUVFHSC9qinMGZ4lM7uetzUXcuMdEpC5g4C0Pb9HuaM3zC7K/509n7RTBZUPEzgsWtgi7m33nhpXsUo8WMcQkBIZlKn3ce+WRyZpZxcYtVoPqNn3benhcv7cq7yH1ktamUiZ5Dq7Ga+oQCaQEsOXtbGNS6vA5Bwa1pjbmMiRIbvlstInz8XTw8h/T0yLBLUJ0yYZmzmt+9i8qL8KFQ/PPDe5cXOCr1Aq2NTSixe5F2K/EI00q6D7QMpBDC7K6zDWgAOvINzifZ0DTkxVe4EE6F+FneDrcJsj+ZeIabrlRcfxtiFziH6unnXktta0sB1xcszIxXdMDbUcJA==",
                    "encryptedValue": "KGfmdUWy89BwhQChzqZJ4w==",
                    "oaepHashingAlgo": "SHA256"
                }
            },
                                            headers=test_headers))

        self.assertNotIn("encryptedData", decrypted)
        self.assertDictEqual({"data": {}}, decrypted)
        self.assertDictEqual({"Content-Type": "application/json"},
                             test_headers)
    def test_ApiEncryption_with_config_as_dict(self,
                                               FieldLevelEncryptionConfig):
        to_test.ApiEncryption(self._json_config)

        assert FieldLevelEncryptionConfig.called
    def test_ApiEncryption_with_config_as_file_name(
            self, FieldLevelEncryptionConfig):
        to_test.ApiEncryption(TEST_CONFIG)

        assert FieldLevelEncryptionConfig.called