-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-5143 Support auto encryption in unified tests #2488
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
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5f4467f
fix c extension building on azure and gcp vms
blink1073 37975cb
update kms code
blink1073 9556f8c
PYTHON-5143 Support auto encryption in unified tests
blink1073 af34b9f
clean up helpers
blink1073 f0881db
fix oidc command
blink1073 d2f141d
Revert "fix oidc command"
blink1073 cb1031b
Merge branch 'master' of github.com:mongodb/mongo-python-driver into …
blink1073 ea63fe4
remove encrypted collections
blink1073 006f5ef
fix use of placeholders
blink1073 d75181a
undo changes to lock
blink1073 8ce517d
copy the autoEncryptOpts
blink1073 65ec644
fix handling of dropped encryption collections
blink1073 bcf5d53
undo changes to lock
blink1073 69697a7
remove whitespace
blink1073 13d5ee2
refactor helper methods and constants
blink1073 446cd96
add helper file
blink1073 b325829
fix handling of client_knobs
blink1073 a3d426a
undo changes to lock
blink1073 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ | |
) | ||
from test.asynchronous.utils import async_get_pool, flaky | ||
from test.asynchronous.utils_spec_runner import SpecRunnerTask | ||
from test.helpers import ALL_KMS_PROVIDERS, DEFAULT_KMS_TLS | ||
from test.unified_format_shared import ( | ||
KMS_TLS_OPTS, | ||
PLACEHOLDER_MAP, | ||
|
@@ -61,6 +62,8 @@ | |
from test.version import Version | ||
from typing import Any, Dict, List, Mapping, Optional | ||
|
||
import pytest | ||
|
||
import pymongo | ||
from bson import SON, json_util | ||
from bson.codec_options import DEFAULT_CODEC_OPTIONS | ||
|
@@ -76,7 +79,7 @@ | |
from pymongo.asynchronous.encryption import AsyncClientEncryption | ||
from pymongo.asynchronous.helpers import anext | ||
from pymongo.driver_info import DriverInfo | ||
from pymongo.encryption_options import _HAVE_PYMONGOCRYPT | ||
from pymongo.encryption_options import _HAVE_PYMONGOCRYPT, AutoEncryptionOpts | ||
from pymongo.errors import ( | ||
AutoReconnect, | ||
BulkWriteError, | ||
|
@@ -259,6 +262,23 @@ async def _create_entity(self, entity_spec, uri=None): | |
kwargs: dict = {} | ||
observe_events = spec.get("observeEvents", []) | ||
|
||
if "autoEncryptOpts" in spec: | ||
auto_encrypt_opts = spec["autoEncryptOpts"].copy() | ||
auto_encrypt_kwargs: dict = dict(kms_tls_options=DEFAULT_KMS_TLS) | ||
kms_providers = ALL_KMS_PROVIDERS.copy() | ||
key_vault_namespace = auto_encrypt_opts.pop("keyVaultNamespace") | ||
for provider_name, provider_value in auto_encrypt_opts.pop("kmsProviders").items(): | ||
kms_providers[provider_name].update(provider_value) | ||
extra_opts = auto_encrypt_opts.pop("extraOptions", {}) | ||
for key, value in extra_opts.items(): | ||
auto_encrypt_kwargs[camel_to_snake(key)] = value | ||
for key, value in auto_encrypt_opts.items(): | ||
auto_encrypt_kwargs[camel_to_snake(key)] = value | ||
auto_encryption_opts = AutoEncryptionOpts( | ||
kms_providers, key_vault_namespace, **auto_encrypt_kwargs | ||
) | ||
kwargs["auto_encryption_opts"] = auto_encryption_opts | ||
|
||
# The unified tests use topologyOpeningEvent, we use topologyOpenedEvent | ||
for i in range(len(observe_events)): | ||
if "topologyOpeningEvent" == observe_events[i]: | ||
|
@@ -430,7 +450,7 @@ class UnifiedSpecTestMixinV1(AsyncIntegrationTest): | |
a class attribute ``TEST_SPEC``. | ||
""" | ||
|
||
SCHEMA_VERSION = Version.from_string("1.22") | ||
SCHEMA_VERSION = Version.from_string("1.23") | ||
RUN_ON_LOAD_BALANCER = True | ||
TEST_SPEC: Any | ||
TEST_PATH = "" # This gets filled in by generate_test_classes | ||
|
@@ -462,6 +482,13 @@ async def insert_initial_data(self, initial_data): | |
wc = WriteConcern(w="majority") | ||
else: | ||
wc = WriteConcern(w=1) | ||
|
||
# Remove any encryption collections associated with the collection. | ||
collections = await db.list_collection_names() | ||
for collection in collections: | ||
if collection in [f"enxcol_.{coll_name}.esc", f"enxcol_.{coll_name}.ecoc"]: | ||
await db.drop_collection(collection) | ||
|
||
if documents: | ||
if opts: | ||
await db.create_collection(coll_name, **opts) | ||
|
@@ -488,6 +515,7 @@ def tearDownClass(cls) -> None: | |
async def asyncSetUp(self): | ||
# super call creates internal client cls.client | ||
await super().asyncSetUp() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unintended whitespace? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
# process file-level runOnRequirements | ||
run_on_spec = self.TEST_SPEC.get("runOnRequirements", []) | ||
if not await self.should_run_on(run_on_spec): | ||
|
@@ -1516,7 +1544,14 @@ class SpecTestBase(with_metaclass(UnifiedSpecTestMeta)): # type: ignore | |
TEST_SPEC = test_spec | ||
EXPECTED_FAILURES = expected_failures | ||
|
||
return SpecTestBase | ||
base = SpecTestBase | ||
|
||
# Add "encryption" marker if the "csfle" runOnRequirement is set. | ||
for req in test_spec.get("runOnRequirements", []): | ||
if req.get("csfle", False): | ||
base = pytest.mark.encryption(base) | ||
|
||
return base | ||
|
||
for dirpath, _, filenames in os.walk(test_path): | ||
dirname = os.path.split(dirpath)[-1] | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these need to be here where they'll be duplicated by synchro? Or can they go in a shared file in
test
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting we move the rest of the constants as well?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any constant (or function, value, anything really) that doesn't change based on async/sync should live outside of the synchro'd directories, yeah.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll refactor a bit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, let's see how the tests do