Skip to content

Commit a83d09a

Browse files
author
Lucas McDonald
committed
m
1 parent 3945dcb commit a83d09a

File tree

7 files changed

+24
-28
lines changed

7 files changed

+24
-28
lines changed

DynamoDbEncryption/runtimes/python/test/integ/encrypted/test_item.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
from ...items import complex_item_ddb, complex_item_dict, simple_item_ddb, simple_item_dict
1414

1515

16-
# Creates a matrix
16+
# Creates a matrix of tests for each value in param,
17+
# with a user-friendly string for test output:
18+
# use_complex_item = True -> "complex_item"
19+
# use_complex_item = False -> "simple_item"
1720
@pytest.fixture(params=[True, False], ids=["complex_item", "simple_item"])
1821
def use_complex_item(request):
1922
return request.param

Examples/runtimes/python/DynamoDBEncryption/src/item_encryptor/encrypt_decrypt_example.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
13
"""
24
Set up an ItemEncryptor and use its APIs to encrypt and decrypt items in 3 different formats.
35
@@ -45,7 +47,7 @@ def encrypt_decrypt_example(kms_key_id: str, ddb_table_name: str) -> None:
4547
"""Encrypt and decrypt an item with an ItemEncryptor."""
4648
# 1. Create a Keyring. This Keyring will be responsible for protecting the data keys that protect your data.
4749
# For this example, we will create a AWS KMS Keyring with the AWS KMS Key we want to use.
48-
# We will use the `CreateMrkMultiKeyring` method to create this keyring,
50+
# We will use the `CreateAwsKmsMrkMultiKeyringInput` method to create this keyring,
4951
# as it will correctly handle both single region and Multi-Region KMS Keys.
5052
mat_prov: AwsCryptographicMaterialProviders = AwsCryptographicMaterialProviders(config=MaterialProvidersConfig())
5153
kms_mrk_multi_keyring_input: CreateAwsKmsMrkMultiKeyringInput = CreateAwsKmsMrkMultiKeyringInput(
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
3-
"""Test suite for the EncryptedClient example."""
3+
"""Test suite for the ItemEncryptor example."""
44
import pytest
55

66
from ...src.item_encryptor.encrypt_decrypt_example import encrypt_decrypt_example
@@ -9,7 +9,7 @@
99

1010

1111
def test_encrypt_decrypt_example():
12-
"""Test function for encrypt and decrypt using the EncryptedClient example."""
12+
"""Test function for encrypt and decrypt using the ItemEncryptor example."""
1313
test_kms_key_id = "arn:aws:kms:us-west-2:658956600833:key/b3537ef1-d8dc-4780-9f5a-55776cbb2f7f"
1414
test_dynamodb_table_name = "DynamoDbEncryptionInterceptorTestTable"
1515
encrypt_decrypt_example(test_kms_key_id, test_dynamodb_table_name)

TestVectors/runtimes/python/src/aws_dbesdk_dynamodb_test_vectors/internaldafny/extern/CreateInterceptedDDBResource.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
13
import boto3
24
import types
35
import aws_dbesdk_dynamodb_test_vectors.internaldafny.generated.CreateInterceptedDDBClient

TestVectors/runtimes/python/src/aws_dbesdk_dynamodb_test_vectors/internaldafny/extern/CreateInterceptedDDBTable.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
13
import boto3
2-
import types
34
import aws_dbesdk_dynamodb_test_vectors.internaldafny.generated.CreateInterceptedDDBClient
45
import aws_cryptography_internal_dynamodb.internaldafny.extern
56
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb.dafny_to_smithy import aws_cryptography_dbencryptionsdk_dynamodb_DynamoDbTablesEncryptionConfig
@@ -25,7 +26,7 @@
2526
# When querying, DBESDK DDB TestVectors will pass the Table the query as a string.
2627
# The Table could accept this string as-is and process it correctly.
2728
# However, EncryptedTables have extra logic to process boto3 Conditions.
28-
# We want to test this extra logic as much as possible.
29+
# I want to test this extra logic as much as possible.
2930
# This map converts some known query strings to equivalent Conditions.
3031
# TestVectors will pass the query string (map key) to the Table;
3132
# the Table's internal logic will look up the query string in this map:
@@ -82,17 +83,17 @@
8283
# "Complex" queries
8384
"Comp1 := :cmp1a": Attr("Comp1").eq(":cmp1a"),
8485
"begins_with(Comp1, :cmp1c)": Attr("Comp1").begins_with(":cmp1c"),
85-
# Another query that can't be translated to boto3 Conditions,
86-
# since attribute values aren't attribute names.
87-
# Pass the original string through.
88-
":cmp1c <= Comp1": ":cmp1c <= Comp1",
89-
9086
"cmp1c < Comp1": Attr("cmp1c").lt("Comp1"),
9187
"cmp1c = Comp1": Attr("cmp1c").eq("Comp1"),
9288
"begins_with(Comp1, :cmp1d)": Attr("Comp1").begins_with(":cmp1d"),
9389
"contains(Comp1, :cmp1c)": Attr("Comp1").contains(":cmp1c"),
9490
"contains(Comp1, :cmp1d)": Attr("Comp1").contains(":cmp1d"),
9591
"Comp1 = :cmp1b": Attr("Comp1").eq(":cmp1b"),
92+
93+
# Another query that can't be translated to boto3 Conditions,
94+
# since attribute values aren't attribute names.
95+
# Pass the original string through.
96+
":cmp1c <= Comp1": ":cmp1c <= Comp1",
9697
}
9798

9899
class DynamoDBClientWrapperForDynamoDBTable:

TestVectors/runtimes/python/src/aws_dbesdk_dynamodb_test_vectors/internaldafny/extern/CreateWrappedDictItemEncryptor.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
1-
import boto3
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
23
import aws_dbesdk_dynamodb_test_vectors.internaldafny.generated.CreateWrappedItemEncryptor
34
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_itemencryptor.dafny_to_smithy import aws_cryptography_dbencryptionsdk_dynamodb_itemencryptor_DynamoDbItemEncryptorConfig
45
from aws_dbesdk_dynamodb.encrypted.item import ItemEncryptor
56
from smithy_dafny_standard_library.internaldafny.generated import Wrappers
67
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_itemencryptor.errors import _smithy_error_to_dafny_error
78
from aws_dbesdk_dynamodb_test_vectors.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_itemencryptor.shim import DynamoDbItemEncryptorShim
89
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_itemencryptor.models import (
9-
DecryptItemInput,
1010
DecryptItemOutput,
11-
EncryptItemInput,
1211
EncryptItemOutput,
1312
)
14-
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_itemencryptor.smithy_to_dafny import (
15-
aws_cryptography_dbencryptionsdk_dynamodb_itemencryptor_EncryptItemOutput as SmithyToDafnyEncryptItemOutput,
16-
aws_cryptography_dbencryptionsdk_dynamodb_itemencryptor_DecryptItemOutput as SmithyToDafnyDecryptItemOutput,
17-
)
18-
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_itemencryptor.dafny_to_smithy import (
19-
aws_cryptography_dbencryptionsdk_dynamodb_itemencryptor_EncryptItemInput as DafnyToSmithyEncryptItemInput,
20-
aws_cryptography_dbencryptionsdk_dynamodb_itemencryptor_DecryptItemInput as DafnyToSmithyDecryptItemInput,
21-
)
2213
from aws_dbesdk_dynamodb.transform import (
2314
dict_to_ddb,
2415
ddb_to_dict,
@@ -32,6 +23,7 @@ class DynamoDBFormatToDictFormatWrapper:
3223
However, the legacy Python DDBEC ItemEncryptor also supports Python dictionary-formatted items.
3324
This class transforms Dafny TestVectors' DynamoDB-formatted items
3425
to Python DBESDK's ItemEncryptor's Python dictionary-formatted encryption methods.
26+
This improves the test coverage of the ItemEncryptor.
3527
"""
3628
def __init__(self, item_encryptor):
3729
self._item_encryptor = item_encryptor

TestVectors/runtimes/python/src/aws_dbesdk_dynamodb_test_vectors/internaldafny/extern/CreateWrappedDynamoDbItemEncryptor.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
import boto3
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
23
import aws_dbesdk_dynamodb_test_vectors.internaldafny.generated.CreateWrappedItemEncryptor
34
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_itemencryptor.dafny_to_smithy import aws_cryptography_dbencryptionsdk_dynamodb_itemencryptor_DynamoDbItemEncryptorConfig
45
from aws_dbesdk_dynamodb.encrypted.item import ItemEncryptor
56
from smithy_dafny_standard_library.internaldafny.generated import Wrappers
67
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_itemencryptor.errors import _smithy_error_to_dafny_error
78
from aws_dbesdk_dynamodb_test_vectors.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_itemencryptor.shim import DynamoDbItemEncryptorShim
8-
from aws_dbesdk_dynamodb.smithygenerated.aws_cryptography_dbencryptionsdk_dynamodb_itemencryptor.models import (
9-
DecryptItemInput,
10-
EncryptItemInput,
11-
)
129

13-
# In contrast to
1410

1511
class default__:
1612
@staticmethod

0 commit comments

Comments
 (0)