- Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-3385 Add prose test for RewrapManyDataKey #1034
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 8 commits
Commits
Show all changes
10 commits Select commit Hold shift + click to select a range
088a7b8
PYTHON-3385 Add prose test for RewrapManyDataKey
blink1073 ce8c4f0
fix master_keys usage
blink1073 76ff36c
address review
blink1073 b615518
address review
blink1073 23da78f
address review
blink1073 1bca8d2
address review
blink1073 4f3946b
address review
blink1073 035fbf2
add tls options
blink1073 be94b66
address review
blink1073 1d06312
remove unused prop
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
Original file line number | Diff line number | Diff line change |
---|---|---|
| @@ -24,7 +24,7 @@ | |
import textwrap | ||
import traceback | ||
import uuid | ||
from typing import Any, Dict | ||
from typing import Any, Dict, Mapping | ||
| ||
from pymongo.collection import Collection | ||
| ||
| @@ -2202,6 +2202,93 @@ def test_05_roundtrip_encrypted_unindexed(self): | |
self.assertEqual(decrypted, val) | ||
| ||
| ||
# https://github.com/mongodb/specifications/blob/072601/source/client-side-encryption/tests/README.rst#rewrap | ||
class TestRewrapWithSeparateClientEncryption(EncryptionIntegrationTest): | ||
| ||
MASTER_KEYS: Mapping[str, Mapping[str, Any]] = { | ||
"aws": { | ||
"region": "us-east-1", | ||
"key": "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0", | ||
}, | ||
"azure": { | ||
"keyVaultEndpoint": "key-vault-csfle.vault.azure.net", | ||
"keyName": "key-name-csfle", | ||
}, | ||
"gcp": { | ||
"projectId": "devprod-drivers", | ||
"location": "global", | ||
"keyRing": "key-ring-csfle", | ||
"keyName": "key-name-csfle", | ||
}, | ||
"kmip": {}, | ||
"local": {}, | ||
} | ||
| ||
KMS_TLS_OPTS = { | ||
"aws": {"tlsCAFile": CA_PEM}, | ||
"azure": {"tlsCAFile": CA_PEM}, | ||
"gcp": {"tlsCAFile": CA_PEM}, | ||
"kmip": {"tlsCAFile": CA_PEM}, | ||
} | ||
| ||
def test_rewrap(self): | ||
for src_provider in self.MASTER_KEYS: | ||
for dst_provider in self.MASTER_KEYS: | ||
with self.subTest(src_provider=src_provider, dst_provider=dst_provider): | ||
self.run_test(src_provider, dst_provider) | ||
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. The test says we still need to test the "local" provider:
I think that means we need to add
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. They used | ||
| ||
def run_test(self, src_provider, dst_provider): | ||
# Step 1. Drop the collection ``keyvault.datakeys``. | ||
self.client.keyvault.drop_collection("datakeys") | ||
| ||
# Step 2. Create a ``ClientEncryption`` object named ``client_encryption1`` | ||
client_encryption1 = ClientEncryption( | ||
ShaneHarvey marked this conversation as resolved. Show resolved Hide resolved | ||
key_vault_client=self.client, | ||
key_vault_namespace="keyvault.datakeys", | ||
kms_providers=ALL_KMS_PROVIDERS, | ||
kms_tls_options=self.KMS_TLS_OPTS, | ||
codec_options=OPTS, | ||
) | ||
self.addCleanup(client_encryption1.close) | ||
| ||
# Step 3. Call ``client_encryption1.create_data_key`` with ``src_provider``. | ||
key_id = client_encryption1.create_data_key( | ||
master_key=self.MASTER_KEYS[src_provider], kms_provider=src_provider | ||
) | ||
| ||
# Step 4. Call ``client_encryption1.encrypt`` with the value "test" | ||
cipher_text = client_encryption1.encrypt( | ||
"test", key_id=key_id, algorithm=Algorithm.AEAD_AES_256_CBC_HMAC_SHA_512_Deterministic | ||
) | ||
| ||
# Step 5. Create a ``ClientEncryption`` object named ``client_encryption2`` | ||
client2 = MongoClient() | ||
self.addCleanup(client2.close) | ||
client_encryption2 = ClientEncryption( | ||
ShaneHarvey marked this conversation as resolved. Show resolved Hide resolved | ||
key_vault_client=client2, | ||
key_vault_namespace="keyvault.datakeys", | ||
kms_providers=ALL_KMS_PROVIDERS, | ||
kms_tls_options=self.KMS_TLS_OPTS, | ||
codec_options=OPTS, | ||
) | ||
self.addCleanup(client_encryption1.close) | ||
| ||
# Step 6. Call ``client_encryption2.rewrap_many_data_key`` with an empty ``filter``. | ||
rewrap_many_data_key_result = client_encryption2.rewrap_many_data_key( | ||
{}, provider=dst_provider, master_key=self.MASTER_KEYS[dst_provider] | ||
) | ||
| ||
self.assertEqual(rewrap_many_data_key_result.bulk_write_result.modified_count, 1) | ||
| ||
# 7. Call ``client_encryption1.decrypt`` with the ``cipher_text``. Assert the return value is "test". | ||
decrypt_result1 = client_encryption1.decrypt(cipher_text) | ||
self.assertEqual(decrypt_result1, "test") | ||
| ||
# 8. Call ``client_encryption2.decrypt`` with the ``cipher_text``. Assert the return value is "test". | ||
decrypt_result2 = client_encryption2.decrypt(cipher_text) | ||
self.assertEqual(decrypt_result2, "test") | ||
| ||
| ||
class TestQueryableEncryptionDocsExample(EncryptionIntegrationTest): | ||
# Queryable Encryption is not supported on Standalone topology. | ||
@client_context.require_no_standalone | ||
|
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.
I think the tlsCAFile is only valid/needed for kmip. Can we use the existing KMS_TLS_OPTS global instead of adding a new self.KMS_TLS_OPTS?
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.
Done