Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4008095

Browse files
author
Lucas McDonald
committedApr 16, 2025·
m
1 parent 5d0b615 commit 4008095

File tree

4 files changed

+81
-5
lines changed

4 files changed

+81
-5
lines changed
 

‎DynamoDbEncryption/runtimes/python/test/integ/encrypted/test_client.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,35 @@ def test_GIVEN_valid_put_and_query_requests_WHEN_put_and_query_THEN_round_trip_p
246246
query_response = client.query(**query_request)
247247
# Then: query succeeds
248248
assert query_response["ResponseMetadata"]["HTTPStatusCode"] == 200
249+
assert len(query_response["Items"]) == 1
250+
# DynamoDB JSON uses lists to represent sets, so strict equality can fail.
251+
# Sort lists to ensure consistent ordering when comparing expected and actual items.
252+
expected_item = sort_dynamodb_json_lists(put_item_request["Item"])
253+
actual_item = sort_dynamodb_json_lists(query_response["Items"][0])
254+
assert expected_item == actual_item
255+
256+
@pytest.fixture
257+
def scan_request(expect_standard_dictionaries, test_item):
258+
if expect_standard_dictionaries:
259+
return {**basic_scan_request_dict(test_item), "TableName": INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME}
260+
return basic_scan_request_ddb(test_item)
261+
262+
def test_GIVEN_valid_put_and_scan_requests_WHEN_put_and_scan_THEN_round_trip_passes(client, put_item_request, scan_request):
263+
# Given: Valid put_item request
264+
# When: put_item
265+
put_response = client.put_item(**put_item_request)
266+
# Then: put_item succeeds
267+
assert put_response["ResponseMetadata"]["HTTPStatusCode"] == 200
268+
269+
# Given: Valid scan request
270+
# When: scan
271+
scan_response = client.scan(**scan_request)
272+
# Then: scan succeeds
273+
assert scan_response["ResponseMetadata"]["HTTPStatusCode"] == 200
274+
assert len(scan_response["Items"]) >= 1
275+
# Can't assert anything about the scan;
276+
# there are too many items.
277+
# The critical test is that the scan succeeds.
249278

250279
@pytest.fixture
251280
def transact_write_item_put_request(expect_standard_dictionaries, multiple_test_items):

‎DynamoDbEncryption/runtimes/python/test/integ/encrypted/test_paginator.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
complex_item_dict,
3535
complex_key_dict,
3636
)
37-
from ...requests import basic_query_paginator_request, basic_put_item_request_ddb, basic_put_item_request_dict
37+
from ...requests import basic_query_paginator_request, basic_put_item_request_ddb, basic_put_item_request_dict, basic_scan_request_ddb, basic_scan_request_dict
3838

3939
BOTO3_CLIENT = boto3.client("dynamodb")
4040
ENCRYPTED_CLIENT = EncryptedClient(
@@ -165,6 +165,31 @@ def test_GIVEN_query_paginator_WHEN_paginate_THEN_returns_expected_items(client,
165165
# Then: Items are equal
166166
assert expected_item == actual_item
167167

168+
@pytest.fixture
169+
def paginate_scan_request(expect_standard_dictionaries, encrypted, test_item):
170+
if expect_standard_dictionaries:
171+
request = {**basic_scan_request_dict(test_item), "TableName": INTEG_TEST_DEFAULT_DYNAMODB_TABLE_NAME}
172+
else:
173+
request = basic_scan_request_ddb(test_item)
174+
if encrypted:
175+
request["FilterExpression"] = request["FilterExpression"] + " AND attribute_exists (#sig)"
176+
request["ExpressionAttributeNames"] = {}
177+
request["ExpressionAttributeNames"]["#sig"] = "amzn-ddb-map-sig"
178+
return request
179+
180+
def test_GIVEN_scan_paginator_WHEN_paginate_THEN_returns_expected_items(client, scan_paginator, paginate_scan_request, put_item_request, test_item):
181+
# Given: item in table
182+
client.put_item(**put_item_request)
183+
# Given: Scan paginator
184+
# When: Paginate
185+
response = scan_paginator.paginate(**paginate_scan_request)
186+
# Then: Returns encrypted items
187+
items = []
188+
for page in response:
189+
if "Items" in page:
190+
for item in page["Items"]:
191+
items.append(item)
192+
168193
# TODO: set up scan table and tests
169194

170195
# @pytest.fixture

‎DynamoDbEncryption/runtimes/python/test/integ/encrypted/test_table.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
basic_put_item_request_dict,
2020
basic_get_item_request_dict,
2121
basic_query_request_dict,
22+
basic_scan_request_dict,
2223
)
2324

2425
serializer = TypeSerializer()
@@ -111,7 +112,6 @@ def test_GIVEN_items_WHEN_batch_write_and_get_THEN_round_trip_passes(
111112
assert get_response["ResponseMetadata"]["HTTPStatusCode"] == 200
112113
assert "Item" not in get_response
113114

114-
115115
def test_GIVEN_items_in_table_WHEN_query_THEN_items_are_decrypted_correctly(table, test_item):
116116
"""Test query and scan operations."""
117117
# Given: Simple and complex items in appropriate format for client
@@ -140,6 +140,28 @@ def test_GIVEN_items_in_table_WHEN_query_THEN_items_are_decrypted_correctly(tabl
140140
# found_items = scan_response["Items"]
141141
# assert all(any(found_item == item for found_item in found_items) for item in items)
142142

143+
@pytest.fixture
144+
def scan_request(encrypted, test_item):
145+
if encrypted:
146+
request = basic_scan_request_dict(test_item)
147+
request["FilterExpression"] = request["FilterExpression"] + " AND attribute_exists (#sig)"
148+
request["ExpressionAttributeNames"] = {}
149+
request["ExpressionAttributeNames"]["#sig"] = "amzn-ddb-map-sig"
150+
return request
151+
return basic_scan_request_dict(test_item)
152+
153+
def test_GIVEN_valid_put_and_scan_requests_WHEN_put_and_scan_THEN_round_trip_passes(table, test_item, scan_request):
154+
"""Test put_item and scan operations."""
155+
# Given: Simple and complex items in appropriate format for client
156+
put_item_request_dict = basic_put_item_request_dict(test_item)
157+
table.put_item(**put_item_request_dict)
158+
159+
# When: Scanning items
160+
scan_request_dict = scan_request
161+
scan_response = table.scan(**scan_request_dict)
162+
# Then: Scan returns both test items
163+
assert scan_response["ResponseMetadata"]["HTTPStatusCode"] == 200
164+
143165
def test_WHEN_update_item_THEN_raises_not_implemented_error():
144166
# Given: Encrypted client and update item parameters
145167
# When: Calling update_item

‎DynamoDbEncryption/runtimes/python/test/requests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ def base_query_request(item):
3333
def base_scan_request(item):
3434
"""Base structure for scan requests."""
3535
return {
36-
"FilterExpression": "attribute1 = :a1",
36+
"FilterExpression": "attribute2 = :a2",
3737
"ExpressionAttributeValues": {
38-
":a1": item["attribute1"]
39-
}
38+
":a2": item["attribute2"]
39+
},
4040
}
4141

4242
def base_batch_write_item_request(actions_with_items):

0 commit comments

Comments
 (0)
Please sign in to comment.