Skip to content

Commit 01607a6

Browse files
committed
retrieve configured provider from conn settings
1 parent 0495cc8 commit 01607a6

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

tests/encryption_/test_base.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
31
import pymongo
42
from bson.binary import Binary
53
from django.conf import settings
@@ -21,18 +19,3 @@ def assertEncrypted(self, model, field):
2119
collection = db[model._meta.db_table]
2220
data = collection.find_one({}, {field: 1, "_id": 0})
2321
self.assertIsInstance(data[field], Binary)
24-
25-
def __init__(self, *args, **kwargs):
26-
super().__init__(*args, **kwargs)
27-
28-
AWS_CREDS = {
29-
"accessKeyId": os.environ.get("FLE_AWS_KEY", ""),
30-
"secretAccessKey": os.environ.get("FLE_AWS_SECRET", ""),
31-
}
32-
_USE_AWS_KMS = any(AWS_CREDS.values())
33-
34-
if _USE_AWS_KMS:
35-
self.DEFAULT_KMS_PROVIDER = "aws"
36-
else:
37-
# Local-only fallback
38-
self.DEFAULT_KMS_PROVIDER = "local"

tests/encryption_/test_management.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ def test_show_encrypted_fields_map(self):
114114
self._compare_output(expected, command_output[model_key])
115115

116116
def test_missing_key(self):
117+
connection = connections["encrypted"]
118+
auto_encryption_opts = connection.connection._options.auto_encryption_opts
119+
kms_providers = auto_encryption_opts._kms_providers
117120
test_key = "encryption__patient.patient_record.ssn"
118121
msg = (
119122
f"Encryption key {test_key} not found. Have migrated the "
@@ -125,11 +128,10 @@ def test_missing_key(self):
125128
call_command("showencryptedfieldsmap", "--database", "encrypted", verbosity=0)
126129
finally:
127130
# Replace the deleted key.
128-
master_key = connections["encrypted"].settings_dict["KMS_CREDENTIALS"][
129-
self.DEFAULT_KMS_PROVIDER
130-
]
131-
connections["encrypted"].client_encryption.create_data_key(
132-
kms_provider=self.DEFAULT_KMS_PROVIDER,
131+
kms_provider = next(iter(kms_providers.keys()))
132+
master_key = connection.settings_dict["KMS_CREDENTIALS"][kms_provider]
133+
connection.client_encryption.create_data_key(
134+
kms_provider=kms_provider,
133135
master_key=master_key,
134136
key_alt_names=[test_key],
135137
)

0 commit comments

Comments
 (0)