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 setUp(self): c = openapi_client.Configuration() c.host = BASE_PATH self.cli = openapi_client.ApiClient(c) ## Add OAuth1.0a interceptor add_signer_layer(self.cli, P12, KEY_PASSWORD, CONSUMER_KEY) ## Add Field Level Encryption interceptor config_file = os.path.join(os.path.dirname(__file__), FLE_CONFIG_PATH) add_encryption_layer(self.cli, config_file)
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())
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())
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_wrong_oauth_layer_flag_warning(self): test_client = Mock() # __oauth__ is None test_client.request.__oauth__ = None with self.assertWarns(UserWarning): to_test.add_encryption_layer(test_client, self._json_config) # __oauth__ is False test_client.request.__oauth__ = False with self.assertWarns(UserWarning): to_test.add_encryption_layer(test_client, self._json_config) # __oauth__ is not a boolean test_client.request.__oauth__ = 5 with self.assertWarns(UserWarning): to_test.add_encryption_layer(test_client, self._json_config)
def test_add_encryption_layer_missing_oauth_layer_warning(self): test_client = Mock() # no __oauth__ flag with self.assertWarns(UserWarning): to_test.add_encryption_layer(test_client, self._json_config)
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_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