11
11
# ANY KIND, either express or implied. See the License for the specific
12
12
# language governing permissions and limitations under the License.
13
13
"""Functional tests for ``dynamodb_encryption_sdk.encrypted.client``."""
14
- import boto3
15
14
import hypothesis
16
15
import pytest
17
16
18
- from dynamodb_encryption_sdk .encrypted .client import EncryptedClient
19
- from dynamodb_encryption_sdk .internal .formatting .transform import ddb_to_dict , dict_to_ddb
20
17
from ..functional_test_utils import (
21
- check_encrypted_item , cycle_batch_item_check , set_parametrized_actions , set_parametrized_cmp ,
22
- set_parametrized_item , TEST_KEY , TEST_TABLE_NAME
18
+ client_cycle_batch_items_check , client_cycle_single_item_check ,
19
+ set_parametrized_actions , set_parametrized_cmp , set_parametrized_item ,
20
+ TEST_TABLE_NAME
23
21
)
24
22
from ..functional_test_utils import example_table # noqa pylint: disable=unused-import
25
23
from ..hypothesis_strategies import ddb_items , SLOW_SETTINGS , VERY_SLOW_SETTINGS
@@ -34,67 +32,24 @@ def pytest_generate_tests(metafunc):
34
32
35
33
36
34
def _client_cycle_single_item_check (materials_provider , initial_actions , initial_item ):
37
- check_attribute_actions = initial_actions .copy ()
38
- check_attribute_actions .set_index_keys (* list (TEST_KEY .keys ()))
39
- item = initial_item .copy ()
40
- item .update (TEST_KEY )
41
- ddb_item = dict_to_ddb (item )
42
- ddb_key = dict_to_ddb (TEST_KEY )
43
-
44
- client = boto3 .client ('dynamodb' , region_name = 'us-west-2' )
45
- e_client = EncryptedClient (
46
- client = client ,
47
- materials_provider = materials_provider ,
48
- attribute_actions = initial_actions
35
+ return client_cycle_single_item_check (
36
+ materials_provider ,
37
+ initial_actions ,
38
+ initial_item ,
39
+ TEST_TABLE_NAME ,
40
+ 'us-west-2'
49
41
)
50
42
51
- _put_result = e_client .put_item ( # noqa
52
- TableName = TEST_TABLE_NAME ,
53
- Item = ddb_item
54
- )
55
-
56
- encrypted_result = client .get_item (
57
- TableName = TEST_TABLE_NAME ,
58
- Key = ddb_key
59
- )
60
- check_encrypted_item (item , ddb_to_dict (encrypted_result ['Item' ]), check_attribute_actions )
61
-
62
- decrypted_result = e_client .get_item (
63
- TableName = TEST_TABLE_NAME ,
64
- Key = ddb_key
65
- )
66
- assert ddb_to_dict (decrypted_result ['Item' ]) == item
67
-
68
- e_client .delete_item (
69
- TableName = TEST_TABLE_NAME ,
70
- Key = ddb_key
71
- )
72
- del item
73
- del check_attribute_actions
74
-
75
43
76
44
def _client_cycle_batch_items_check (materials_provider , initial_actions , initial_item ):
77
- client = boto3 .client ('dynamodb' , region_name = 'us-west-2' )
78
- e_client = EncryptedClient (
79
- client = client ,
80
- materials_provider = materials_provider ,
81
- attribute_actions = initial_actions
45
+ return client_cycle_batch_items_check (
46
+ materials_provider ,
47
+ initial_actions ,
48
+ initial_item ,
49
+ TEST_TABLE_NAME ,
50
+ 'us-west-2'
82
51
)
83
52
84
- cycle_batch_item_check (
85
- raw = client ,
86
- encrypted = e_client ,
87
- initial_actions = initial_actions ,
88
- initial_item = initial_item ,
89
- write_transformer = dict_to_ddb ,
90
- read_transformer = ddb_to_dict
91
- )
92
-
93
- raw_scan_result = client .scan (TableName = TEST_TABLE_NAME )
94
- e_scan_result = e_client .scan (TableName = TEST_TABLE_NAME )
95
- assert not raw_scan_result ['Items' ]
96
- assert not e_scan_result ['Items' ]
97
-
98
53
99
54
def test_ephemeral_item_cycle (example_table , some_cmps , parametrized_actions , parametrized_item ):
100
55
"""Test a small number of curated CMPs against a small number of curated items."""
0 commit comments