12
12
# language governing permissions and limitations under the License.
13
13
"""Integration tests for ``dynamodb_encryption_sdk.material_providers.aws_kms``."""
14
14
import logging
15
+ import itertools
15
16
16
17
import hypothesis
17
18
import pytest
18
19
19
20
from dynamodb_encryption_sdk .encrypted import CryptoConfig
20
- from dynamodb_encryption_sdk .identifiers import USER_AGENT_SUFFIX
21
- from dynamodb_encryption_sdk .structures import EncryptionContext
21
+ from dynamodb_encryption_sdk .identifiers import CryptoAction , USER_AGENT_SUFFIX
22
+ from dynamodb_encryption_sdk .structures import AttributeActions , EncryptionContext
23
+ from dynamodb_encryption_sdk .transform import dict_to_ddb
22
24
from ..integration_test_utils import aws_kms_cmp # noqa pylint: disable=unused-import
23
25
from ..integration_test_utils import functional_test_utils , hypothesis_strategies
24
26
25
27
pytestmark = pytest .mark .integ
26
28
29
+ _primary_key_names = ('partition_key' , 'sort_key' )
30
+
27
31
28
32
def pytest_generate_tests (metafunc ):
29
33
functional_test_utils .set_parametrized_actions (metafunc )
@@ -38,6 +42,35 @@ def test_verify_user_agent(aws_kms_cmp, caplog):
38
42
assert USER_AGENT_SUFFIX in caplog .text
39
43
40
44
45
+ def _many_items ():
46
+ values = ('a string' , 1234 , b'binary \x00 \x88 value' )
47
+ partition_keys = (('partition_key' , value ) for value in values )
48
+ sort_keys = (('sort_key' , value ) for value in values )
49
+ for pairs in itertools .product (partition_keys , sort_keys ):
50
+ item = dict (pairs )
51
+ yield pytest .param (item , id = str (item ))
52
+
53
+
54
+ @pytest .mark .parametrize ('item' , _many_items ())
55
+ def test_aws_kms_diverse_indexes (aws_kms_cmp , item ):
56
+ """Verify that AWS KMS cycle works for items with all possible combinations for primary index attribute types."""
57
+ crypto_config = CryptoConfig (
58
+ materials_provider = aws_kms_cmp ,
59
+ encryption_context = EncryptionContext (
60
+ partition_key_name = 'partition_key' ,
61
+ sort_key_name = 'sort_key' ,
62
+ attributes = dict_to_ddb (item )
63
+ ),
64
+ attribute_actions = AttributeActions (
65
+ attribute_actions = {
66
+ key : CryptoAction .SIGN_ONLY
67
+ for key in _primary_key_names
68
+ }
69
+ )
70
+ )
71
+ functional_test_utils .cycle_item_check (item , crypto_config )
72
+
73
+
41
74
def test_aws_kms_item_cycle (aws_kms_cmp , parametrized_actions , parametrized_item ):
42
75
crypto_config = CryptoConfig (
43
76
materials_provider = aws_kms_cmp ,
0 commit comments