@@ -1205,16 +1205,17 @@ def setUp(self):
1205
1205
kms_tls_options = KMS_TLS_OPTS )
1206
1206
1207
1207
kms_providers_invalid = copy .deepcopy (kms_providers )
1208
- kms_providers_invalid ['azure' ]['identityPlatformEndpoint' ] = 'example.com :443'
1209
- kms_providers_invalid ['gcp' ]['endpoint' ] = 'example.com :443'
1208
+ kms_providers_invalid ['azure' ]['identityPlatformEndpoint' ] = 'doesnotexist.invalid :443'
1209
+ kms_providers_invalid ['gcp' ]['endpoint' ] = 'doesnotexist.invalid :443'
1210
1210
kms_providers_invalid ['kmip' ]['endpoint' ] = 'doesnotexist.local:5698'
1211
1211
self .client_encryption_invalid = ClientEncryption (
1212
1212
kms_providers = kms_providers_invalid ,
1213
1213
key_vault_namespace = 'keyvault.datakeys' ,
1214
1214
key_vault_client = client_context .client ,
1215
1215
codec_options = OPTS ,
1216
1216
kms_tls_options = KMS_TLS_OPTS )
1217
- self ._kmip_host_error = ''
1217
+ self ._kmip_host_error = None
1218
+ self ._invalid_host_error = None
1218
1219
1219
1220
def tearDown (self ):
1220
1221
self .client_encryption .close ()
@@ -1295,9 +1296,9 @@ def test_06_aws_endpoint_invalid_host(self):
1295
1296
"region" : "us-east-1" ,
1296
1297
"key" : ("arn:aws:kms:us-east-1:579766882180:key/"
1297
1298
"89fcc2c4-08b0-4bd9-9f25-e30687b580d0" ),
1298
- "endpoint" : "example.com "
1299
+ "endpoint" : "doesnotexist.invalid "
1299
1300
}
1300
- with self .assertRaisesRegex (EncryptionError , 'parse error' ):
1301
+ with self .assertRaisesRegex (EncryptionError , self . invalid_host_error ):
1301
1302
self .client_encryption .create_data_key (
1302
1303
'aws' , master_key = master_key )
1303
1304
@@ -1309,8 +1310,8 @@ def test_07_azure(self):
1309
1310
self .run_test_expected_success ('azure' , master_key )
1310
1311
1311
1312
# The full error should be something like:
1312
- # "Invalid JSON in KMS response. HTTP status=404. Error: Got parse error at '<', position 0: 'SPECIAL_EXPECTED' "
1313
- with self .assertRaisesRegex (EncryptionError , 'parse error' ):
1313
+ # "[Errno 8] nodename nor servname provided, or not known "
1314
+ with self .assertRaisesRegex (EncryptionError , self . invalid_host_error ):
1314
1315
self .client_encryption_invalid .create_data_key (
1315
1316
'azure' , master_key = master_key )
1316
1317
@@ -1326,8 +1327,8 @@ def test_08_gcp_valid_endpoint(self):
1326
1327
self .run_test_expected_success ('gcp' , master_key )
1327
1328
1328
1329
# The full error should be something like:
1329
- # "Invalid JSON in KMS response. HTTP status=404. Error: Got parse error at '<', position 0: 'SPECIAL_EXPECTED' "
1330
- with self .assertRaisesRegex (EncryptionError , 'parse error' ):
1330
+ # "[Errno 8] nodename nor servname provided, or not known "
1331
+ with self .assertRaisesRegex (EncryptionError , self . invalid_host_error ):
1331
1332
self .client_encryption_invalid .create_data_key (
1332
1333
'gcp' , master_key = master_key )
1333
1334
@@ -1339,30 +1340,38 @@ def test_09_gcp_invalid_endpoint(self):
1339
1340
"location" : "global" ,
1340
1341
"keyRing" : "key-ring-csfle" ,
1341
1342
"keyName" : "key-name-csfle" ,
1342
- "endpoint" : "example.com :443" }
1343
+ "endpoint" : "doesnotexist.invalid :443" }
1343
1344
1344
1345
# The full error should be something like:
1345
1346
# "Invalid KMS response, no access_token returned. HTTP status=200"
1346
1347
with self .assertRaisesRegex (EncryptionError , "Invalid KMS response" ):
1347
1348
self .client_encryption .create_data_key (
1348
1349
'gcp' , master_key = master_key )
1349
1350
1350
- def kmip_host_error (self ):
1351
- if self ._kmip_host_error :
1352
- return self ._kmip_host_error
1351
+ def dns_error (self , host , port ):
1353
1352
# The full error should be something like:
1354
1353
# "[Errno 8] nodename nor servname provided, or not known"
1355
- try :
1356
- socket .getaddrinfo ('doesnotexist.local' , 5698 , socket .AF_INET ,
1357
- socket .SOCK_STREAM )
1358
- except Exception as exc :
1359
- self ._kmip_host_error = re .escape (str (exc ))
1360
- return self ._kmip_host_error
1354
+ with self .assertRaises (Exception ) as ctx :
1355
+ socket .getaddrinfo (host , port , socket .AF_INET , socket .SOCK_STREAM )
1356
+ return re .escape (str (ctx .exception ))
1357
+
1358
+ @property
1359
+ def invalid_host_error (self ):
1360
+ if self ._invalid_host_error is None :
1361
+ self ._invalid_host_error = self .dns_error (
1362
+ 'doesnotexist.invalid' , 443 )
1363
+ return self ._invalid_host_error
1364
+
1365
+ @property
1366
+ def kmip_host_error (self ):
1367
+ if self ._kmip_host_error is None :
1368
+ self ._kmip_host_error = self .dns_error ('doesnotexist.local' , 5698 )
1369
+ return self ._kmip_host_error
1361
1370
1362
1371
def test_10_kmip_invalid_endpoint (self ):
1363
1372
key = {'keyId' : '1' }
1364
1373
self .run_test_expected_success ('kmip' , key )
1365
- with self .assertRaisesRegex (EncryptionError , self .kmip_host_error () ):
1374
+ with self .assertRaisesRegex (EncryptionError , self .kmip_host_error ):
1366
1375
self .client_encryption_invalid .create_data_key ('kmip' , key )
1367
1376
1368
1377
def test_11_kmip_master_key_endpoint (self ):
@@ -1379,7 +1388,7 @@ def test_11_kmip_master_key_endpoint(self):
1379
1388
1380
1389
def test_12_kmip_master_key_invalid_endpoint (self ):
1381
1390
key = {'keyId' : '1' , 'endpoint' : 'doesnotexist.local:5698' }
1382
- with self .assertRaisesRegex (EncryptionError , self .kmip_host_error () ):
1391
+ with self .assertRaisesRegex (EncryptionError , self .kmip_host_error ):
1383
1392
self .client_encryption .create_data_key ('kmip' , key )
1384
1393
1385
1394
0 commit comments