32
32
from dynamodb_encryption_sdk .encrypted .table import EncryptedTable
33
33
from dynamodb_encryption_sdk .identifiers import CryptoAction
34
34
from dynamodb_encryption_sdk .internal .identifiers import ReservedAttributes
35
+ from dynamodb_encryption_sdk .material_providers .most_recent import MostRecentProvider
35
36
from dynamodb_encryption_sdk .material_providers .static import StaticCryptographicMaterialsProvider
36
37
from dynamodb_encryption_sdk .material_providers .store .meta import MetaStore
37
38
from dynamodb_encryption_sdk .material_providers .wrapped import WrappedCryptographicMaterialsProvider
74
75
75
76
@pytest .fixture
76
77
def example_table ():
77
- mock_dynamodb2 ().start ()
78
+ mock_dynamodb2 ().start (reset = False )
78
79
ddb = boto3 .client ("dynamodb" , region_name = "us-west-2" )
79
80
ddb .create_table (
80
81
TableName = TEST_TABLE_NAME ,
@@ -94,7 +95,7 @@ def example_table():
94
95
95
96
@pytest .fixture
96
97
def table_with_local_seconary_indexes ():
97
- mock_dynamodb2 ().start ()
98
+ mock_dynamodb2 ().start (reset = False )
98
99
ddb = boto3 .client ("dynamodb" , region_name = "us-west-2" )
99
100
ddb .create_table (
100
101
TableName = TEST_TABLE_NAME ,
@@ -126,8 +127,8 @@ def table_with_local_seconary_indexes():
126
127
127
128
128
129
@pytest .fixture
129
- def table_with_global_seconary_indexes ():
130
- mock_dynamodb2 ().start ()
130
+ def table_with_global_secondary_indexes ():
131
+ mock_dynamodb2 ().start (reset = False )
131
132
ddb = boto3 .client ("dynamodb" , region_name = "us-west-2" )
132
133
ddb .create_table (
133
134
TableName = TEST_TABLE_NAME ,
@@ -676,3 +677,72 @@ def mock_metastore():
676
677
metastore , table_name = build_metastore ()
677
678
yield metastore
678
679
delete_metastore (table_name )
680
+
681
+
682
+ def _count_entries (records , * messages ):
683
+ count = 0
684
+
685
+ for record in records :
686
+ if all ((message in record .getMessage () for message in messages )):
687
+ count += 1
688
+
689
+ return count
690
+
691
+
692
+ def _count_puts (records , table_name ):
693
+ return _count_entries (records , '"TableName": "{}"' .format (table_name ), "OperationModel(name=PutItem)" )
694
+
695
+
696
+ def _count_gets (records , table_name ):
697
+ return _count_entries (records , '"TableName": "{}"' .format (table_name ), "OperationModel(name=GetItem)" )
698
+
699
+
700
+ def check_metastore_cache_use_encrypt (metastore , table_name , log_capture ):
701
+ table = boto3 .resource ("dynamodb" ).Table (table_name )
702
+
703
+ most_recent_provider = MostRecentProvider (provider_store = metastore , material_name = "test" , version_ttl = 600.0 )
704
+ e_table = EncryptedTable (
705
+ table = table ,
706
+ materials_provider = most_recent_provider ,
707
+ )
708
+
709
+ item = diverse_item ()
710
+ item .update (TEST_KEY )
711
+ e_table .put_item (Item = item )
712
+ e_table .put_item (Item = item )
713
+ e_table .put_item (Item = item )
714
+ e_table .put_item (Item = item )
715
+
716
+ try :
717
+ primary_puts = _count_puts (log_capture .records , e_table .name )
718
+ metastore_puts = _count_puts (log_capture .records , metastore ._table .name )
719
+
720
+ assert primary_puts == 4
721
+ assert metastore_puts == 1
722
+
723
+ e_table .get_item (Key = TEST_KEY )
724
+ e_table .get_item (Key = TEST_KEY )
725
+ e_table .get_item (Key = TEST_KEY )
726
+
727
+ primary_gets = _count_gets (log_capture .records , e_table .name )
728
+ metastore_gets = _count_gets (log_capture .records , metastore ._table .name )
729
+ metastore_puts = _count_puts (log_capture .records , metastore ._table .name )
730
+
731
+ assert primary_gets == 3
732
+ assert metastore_gets == 0
733
+ assert metastore_puts == 1
734
+
735
+ most_recent_provider .refresh ()
736
+
737
+ e_table .get_item (Key = TEST_KEY )
738
+ e_table .get_item (Key = TEST_KEY )
739
+ e_table .get_item (Key = TEST_KEY )
740
+
741
+ primary_gets = _count_gets (log_capture .records , e_table .name )
742
+ metastore_gets = _count_gets (log_capture .records , metastore ._table .name )
743
+
744
+ assert primary_gets == 6
745
+ assert metastore_gets == 1
746
+
747
+ finally :
748
+ e_table .delete_item (Key = TEST_KEY )
0 commit comments