Skip to content

PYTHON-3110 [v3.13] Remove use of example.com in CSFLE tests (#848) #851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions test/test_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import base64
import copy
import os
import re
import traceback
import socket
import sys
Expand Down Expand Up @@ -1115,13 +1116,15 @@ def setUp(self):
codec_options=OPTS)

kms_providers_invalid = copy.deepcopy(kms_providers)
kms_providers_invalid['azure']['identityPlatformEndpoint'] = 'example.com:443'
kms_providers_invalid['gcp']['endpoint'] = 'example.com:443'

kms_providers_invalid['azure']['identityPlatformEndpoint'] = 'doesnotexist.invalid:443'
kms_providers_invalid['gcp']['endpoint'] = 'doesnotexist.invalid:443'
self.client_encryption_invalid = ClientEncryption(
kms_providers=kms_providers_invalid,
key_vault_namespace='keyvault.datakeys',
key_vault_client=client_context.client,
codec_options=OPTS)
self._invalid_host_error = None

def tearDown(self):
self.client_encryption.close()
Expand Down Expand Up @@ -1202,9 +1205,9 @@ def test_06_aws_endpoint_invalid_host(self):
"region": "us-east-1",
"key": ("arn:aws:kms:us-east-1:579766882180:key/"
"89fcc2c4-08b0-4bd9-9f25-e30687b580d0"),
"endpoint": "example.com"
"endpoint": "doesnotexist.invalid"
}
with self.assertRaisesRegex(EncryptionError, 'parse error'):
with self.assertRaisesRegex(EncryptionError, self.invalid_host_error):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid_host_error hasn't been defined

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And rescheduled encryption tasks

self.client_encryption.create_data_key(
'aws', master_key=master_key)

Expand All @@ -1216,8 +1219,8 @@ def test_07_azure(self):
self.run_test_expected_success('azure', master_key)

# The full error should be something like:
# "Invalid JSON in KMS response. HTTP status=404. Error: Got parse error at '<', position 0: 'SPECIAL_EXPECTED'"
with self.assertRaisesRegex(EncryptionError, 'parse error'):
# "[Errno 8] nodename nor servname provided, or not known"
with self.assertRaisesRegex(EncryptionError, self.invalid_host_error):
self.client_encryption_invalid.create_data_key(
'azure', master_key=master_key)

Expand All @@ -1233,8 +1236,8 @@ def test_08_gcp_valid_endpoint(self):
self.run_test_expected_success('gcp', master_key)

# The full error should be something like:
# "Invalid JSON in KMS response. HTTP status=404. Error: Got parse error at '<', position 0: 'SPECIAL_EXPECTED'"
with self.assertRaisesRegex(EncryptionError, 'parse error'):
# "[Errno 8] nodename nor servname provided, or not known"
with self.assertRaisesRegex(EncryptionError, self.invalid_host_error):
self.client_encryption_invalid.create_data_key(
'gcp', master_key=master_key)

Expand All @@ -1246,7 +1249,7 @@ def test_09_gcp_invalid_endpoint(self):
"location": "global",
"keyRing": "key-ring-csfle",
"keyName": "key-name-csfle",
"endpoint": "example.com:443"}
"endpoint": "doesnotexist.invalid:443"}

# The full error should be something like:
# "Invalid KMS response, no access_token returned. HTTP status=200"
Expand All @@ -1255,6 +1258,20 @@ def test_09_gcp_invalid_endpoint(self):
'gcp', master_key=master_key)


def dns_error(self, host, port):
# The full error should be something like:
# "[Errno 8] nodename nor servname provided, or not known"
with self.assertRaises(Exception) as ctx:
socket.getaddrinfo(host, port, socket.AF_INET, socket.SOCK_STREAM)
return re.escape(str(ctx.exception))

@property
def invalid_host_error(self):
if self._invalid_host_error is None:
self._invalid_host_error = self.dns_error(
'doesnotexist.invalid', 443)
return self._invalid_host_error

class AzureGCPEncryptionTestMixin(object):
DEK = None
KMS_PROVIDER_MAP = None
Expand Down Expand Up @@ -1335,7 +1352,7 @@ def test_explicit(self):
'AQGVERPgAAAAAAAAAAAAAAAC5DbBSwPwfSlBrDtRuglvNvCXD1KzDuCKY2P+4bRFtHDjpTOE2XuytPAUaAbXf1orsPq59PVZmsbTZbt2CB8qaQ==')

def test_automatic(self):
expected_document_extjson = textwrap.dedent("""
expected_document_extjson = textwrap.dedent("""
{"secret_azure": {
"$binary": {
"base64": "AQGVERPgAAAAAAAAAAAAAAAC5DbBSwPwfSlBrDtRuglvNvCXD1KzDuCKY2P+4bRFtHDjpTOE2XuytPAUaAbXf1orsPq59PVZmsbTZbt2CB8qaQ==",
Expand All @@ -1361,7 +1378,7 @@ def test_explicit(self):
'ARgj/gAAAAAAAAAAAAAAAAACwFd+Y5Ojw45GUXNvbcIpN9YkRdoHDHkR4kssdn0tIMKlDQOLFkWFY9X07IRlXsxPD8DcTiKnl6XINK28vhcGlg==')

def test_automatic(self):
expected_document_extjson = textwrap.dedent("""
expected_document_extjson = textwrap.dedent("""
{"secret_gcp": {
"$binary": {
"base64": "ARgj/gAAAAAAAAAAAAAAAAACwFd+Y5Ojw45GUXNvbcIpN9YkRdoHDHkR4kssdn0tIMKlDQOLFkWFY9X07IRlXsxPD8DcTiKnl6XINK28vhcGlg==",
Expand Down