def test_add_header_encryption_layer_post_no_oaep_algo(self):
        self._set_header_params_config()
        del self._json_config["oaepPaddingDigestAlgorithmFieldName"]

        secret1 = 435
        secret2 = 746
        test_client = MockApiClient()
        to_test.add_encryption_layer(test_client, self._json_config)
        response = MockService(test_client).do_something_post_use_headers(
            body={
                "data": {
                    "secret1": secret1,
                    "secret2": secret2
                },
                "encryptedData": {}
            },
            headers={"Content-Type": "application/json"})

        self.assertIn("data", json.loads(response.data))
        self.assertIn("secret", json.loads(response.data)["data"])
        self.assertEqual(secret2 - secret1,
                         json.loads(response.data)["data"]["secret"])
        self.assertDictEqual(
            {
                "Content-Type": "application/json",
                "x-oaep-digest": "SHA256"
            }, response.getheaders())
    def test_add_header_encryption_layer_no_secret_key(self):
        self._set_header_params_config()
        del self._json_config["encryptedKeyFieldName"]

        test_client = MockApiClient()

        self.assertRaises(KeyError, to_test.add_encryption_layer, test_client,
                          self._json_config)
예제 #3
0
    def test_add_encryption_layer_get(self):
        test_client = MockApiClient()
        to_test.add_encryption_layer(test_client, self._json_config)
        response = MockService(test_client).do_something_get(
            headers={"Content-Type": "application/json"})

        self.assertIn("data", response.data)
        self.assertIn("secret", response.data["data"])
        self.assertEqual([53, 84, 75], response.data["data"]["secret"])
        self.assertDictEqual({"Content-Type": "application/json"},
                             response.getheaders())
    def test_add_encryption_layer_delete(self):
        secret1 = 394
        secret2 = 394
        test_client = MockApiClient()
        to_test.add_encryption_layer(test_client, self._json_config)
        response = MockService(test_client).do_something_delete(
            body={"data": {
                "secret1": secret1,
                "secret2": secret2
            }},
            headers={"Content-Type": "application/json"})

        self.assertEqual("OK", json.loads(response.data))
        self.assertDictEqual({"Content-Type": "application/json"},
                             response.getheaders())
예제 #5
0
    def test_add_encryption_layer_post(self):
        secret1 = 435
        secret2 = 746
        test_client = MockApiClient()
        to_test.add_encryption_layer(test_client, self._json_config)
        response = MockService(test_client).do_something_post(
            body={"data": {
                "secret1": secret1,
                "secret2": secret2
            }},
            headers={"Content-Type": "application/json"})

        self.assertIn("data", response.data)
        self.assertIn("secret", response.data["data"])
        self.assertEqual(secret2 - secret1, response.data["data"]["secret"])
        self.assertDictEqual({"Content-Type": "application/json"},
                             response.getheaders())
    def test_add_header_encryption_layer_delete(self):
        self._set_header_params_config()

        secret1 = 783
        secret2 = 783
        test_client = MockApiClient()
        to_test.add_encryption_layer(test_client, self._json_config)
        response = MockService(test_client).do_something_delete_use_headers(
            body={
                "data": {
                    "secret1": secret1,
                    "secret2": secret2
                },
                "encryptedData": {}
            },
            headers={"Content-Type": "application/json"})

        self.assertEqual("OK", response.data)
        self.assertDictEqual({"Content-Type": "application/json"},
                             response.getheaders())
    def test_add_header_encryption_layer_post(self):
        self._set_header_params_config()

        secret1 = 445
        secret2 = 497
        test_client = MockApiClient()
        to_test.add_encryption_layer(test_client, self._json_config)
        response = MockService(test_client).do_something_post_use_headers(
            body={
                "data": {
                    "secret1": secret1,
                    "secret2": secret2
                },
                "encryptedData": {}
            },
            headers={"Content-Type": "application/json"})

        self.assertIn("data", json.loads(response.data))
        self.assertIn("secret", json.loads(response.data)["data"])
        self.assertEqual(secret2 - secret1,
                         json.loads(response.data)["data"]["secret"])
        self.assertDictEqual({"Content-Type": "application/json"},
                             response.getheaders())
예제 #8
0
    def test_add_header_encryption_layer_post_no_pubkey_fingerprint(self):
        self._set_header_params_config()
        del self._json_config["encryptionKeyFingerprintFieldName"]

        secret1 = 245
        secret2 = 854
        test_client = MockApiClient()
        to_test.add_encryption_layer(test_client, self._json_config)
        response = MockService(test_client).do_something_post_use_headers(
            body={
                "data": {
                    "secret1": secret1,
                    "secret2": secret2
                },
                "encryptedData": {}
            },
            headers={"Content-Type": "application/json"})

        self.assertIn("data", response.data)
        self.assertIn("secret", response.data["data"])
        self.assertEqual(secret2 - secret1, response.data["data"]["secret"])
        self.assertDictEqual({"Content-Type": "application/json"},
                             response.getheaders())
    def test_add_encryption_layer_oauth_set(self, __oauth_warn):
        test_client = MockApiClient()
        test_rest_client = MockRestApiClient(test_client)
        to_test.add_encryption_layer(test_rest_client, self._json_config)

        assert not __oauth_warn.called
 def test_add_header_encryption_layer_fail_with_config_as_string(self):
     self.assertRaises(FileNotFoundError, to_test.add_encryption_layer,
                       MockApiClient(), "this is not accepted")
    def test_add_header_encryption_layer_with_config_as_dict(
            self, FieldLevelEncryptionConfig):
        to_test.add_encryption_layer(MockApiClient(), self._json_config)

        assert FieldLevelEncryptionConfig.called
    def test_add_header_encryption_layer_with_config_as_file_name(
            self, FieldLevelEncryptionConfig):
        to_test.add_encryption_layer(MockApiClient(), TEST_CONFIG)

        assert FieldLevelEncryptionConfig.called