@@ -41,12 +41,18 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
41
41
import MPT = AwsCryptographyMaterialProvidersTypes
42
42
import Primitives = AtomicPrimitives
43
43
import ParseJsonManifests
44
+ import Time
45
+ import Trans = AwsCryptographyDbEncryptionSdkDynamoDbTransformsTypes
46
+ import TransOp = AwsCryptographyDbEncryptionSdkDynamoDbTransformsOperations
47
+ import DdbMiddlewareConfig
48
+ import DynamoDbEncryptionTransforms
44
49
45
50
46
51
datatype TestVectorConfig = TestVectorConfig (
47
52
schemaOnEncrypt : DDB .CreateTableInput,
48
53
globalRecords : seq <Record >,
49
54
tableEncryptionConfigs : map <ConfigName , TableConfig>,
55
+ largeEncryptionConfigs : map <ConfigName , TableConfig>,
50
56
queries : seq <SimpleQuery >,
51
57
names : DDB .ExpressionAttributeNameMap,
52
58
values : DDB .ExpressionAttributeValueMap,
@@ -58,7 +64,8 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
58
64
writeTests : seq <WriteTest >,
59
65
roundTripTests : seq <RoundTripTest >,
60
66
decryptTests : seq <DecryptTest >,
61
- strings : seq <string >
67
+ strings : seq <string >,
68
+ large : seq <LargeRecord >
62
69
) {
63
70
64
71
method RunAllTests (keyVectors: KeyVectors .KeyVectorsClient)
@@ -69,6 +76,7 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
69
76
print "DBE Test Vectors\n";
70
77
print |globalRecords|, " records. \n";
71
78
print |tableEncryptionConfigs|, " tableEncryptionConfigs. \n";
79
+ print |largeEncryptionConfigs|, " largeEncryptionConfigs. \n";
72
80
print |queries|, " queries. \n";
73
81
print |names|, " names. \n";
74
82
print |values|, " values. \n";
@@ -78,6 +86,7 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
78
86
print |configsForIoTest|, " configsForIoTest. \n";
79
87
print |configsForModTest|, " configsForModTest. \n";
80
88
print |strings|, " strings. \n";
89
+ print |large|, " large. \n";
81
90
if |roundTripTests| != 0 {
82
91
print |roundTripTests[0]. configs|, " configs and ", |roundTripTests[0]. records|, " records for round trip. \n";
83
92
}
@@ -107,6 +116,7 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
107
116
return ;
108
117
}
109
118
StringOrdering ();
119
+ LargeTests ();
110
120
BasicIoTest ();
111
121
RunIoTests ();
112
122
BasicQueryTest ();
@@ -484,6 +494,87 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
484
494
}
485
495
}
486
496
497
+ const TestConfigs : set < string > := {"all"}
498
+ const TestRecords : set < string > := {"all"}
499
+
500
+ predicate DoTestConfig (name : string )
501
+ {
502
+ "all" in TestConfigs || name in TestConfigs
503
+ }
504
+
505
+ predicate DoTestRecord (name : string )
506
+ {
507
+ "all" in TestRecords || name in TestRecords
508
+ }
509
+
510
+ method LargeTests ()
511
+ {
512
+ print "LargeTests\n";
513
+ DoLargeTest ("do_nothing");
514
+ DoLargeTest ("do_nothing_nosign");
515
+ DoLargeTest ("full_encrypt");
516
+ DoLargeTest ("full_encrypt_nosign");
517
+ DoLargeTest ("full_sign");
518
+ DoLargeTest ("full_sign_nosign");
519
+ }
520
+
521
+ method DoLargeTest (config : string )
522
+ {
523
+ if ! DoTestConfig (config) {
524
+ return ;
525
+ }
526
+ expect config in largeEncryptionConfigs;
527
+ var tconfig := largeEncryptionConfigs[config];
528
+ var configs := Types. DynamoDbTablesEncryptionConfig (
529
+ tableEncryptionConfigs := map[TableName := tconfig.config]
530
+ );
531
+ // because there are lots of pre-conditions on configs
532
+ assume {:axiom} false ;
533
+ var client :- expect DynamoDbEncryptionTransforms. DynamoDbEncryptionTransforms (configs);
534
+ LargeTestsClient (client, config);
535
+ }
536
+
537
+ method LargeTestsClient (client : Trans .IDynamoDbEncryptionTransformsClient, config : string )
538
+ requires client. ValidState ()
539
+ ensures client. ValidState ()
540
+ modifies client. Modifies
541
+ {
542
+ for i := 0 to |large| {
543
+ RunLargeTest (large[i], client, config);
544
+ }
545
+ }
546
+
547
+ method RunLargeTest (record : LargeRecord , client : Trans .IDynamoDbEncryptionTransformsClient, config : string )
548
+ requires client. ValidState ()
549
+ ensures client. ValidState ()
550
+ modifies client. Modifies
551
+ {
552
+ if ! DoTestRecord (record.name) {
553
+ return ;
554
+ }
555
+
556
+ var time := Time. GetAbsoluteTime ();
557
+ for i := 0 to record. count {
558
+ var put_input_input := Trans. PutItemInputTransformInput ( sdkInput := DDB.PutItemInput (TableName := TableName, Item := record.item));
559
+ var put_input_output :- expect client. PutItemInputTransform (put_input_input);
560
+ }
561
+ var elapsed := Time. TimeSince (time);
562
+ Time. PrintTimeLong (elapsed, "Large Encrypt " + record.name + "(" + Base10Int2String(record.count) + ") " + config);
563
+
564
+ var put_input_input := Trans. PutItemInputTransformInput ( sdkInput := DDB.PutItemInput (TableName := TableName, Item := record.item));
565
+ var put_input_output :- expect client. PutItemInputTransform (put_input_input);
566
+ time := Time. GetAbsoluteTime ();
567
+ for i := 0 to record. count {
568
+ var orig_get_input := DDB. GetItemInput (TableName := TableName, Key := map[]);
569
+ var get_output := DDB. GetItemOutput (Item := Some(put_input_output.transformedInput.Item));
570
+ var trans_get_input := Trans. GetItemOutputTransformInput (sdkOutput := get_output, originalInput := orig_get_input);
571
+ var put_output :- expect client. GetItemOutputTransform (trans_get_input);
572
+
573
+ }
574
+ elapsed := Time. TimeSince (time);
575
+ Time. PrintTimeLong (elapsed, "Large Decrypt " + record.name + "(" + Base10Int2String(record.count) + ") " + config);
576
+ }
577
+
487
578
method RoundTripTests ()
488
579
{
489
580
print "RoundTripTests\n";
@@ -999,7 +1090,7 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
999
1090
1000
1091
function MakeEmptyTestVector () : TestVectorConfig
1001
1092
{
1002
- TestVectorConfig (MakeCreateTableInput(), [], map [], [], map [], map [], [], [], [], [], [], [], [], [], [])
1093
+ TestVectorConfig (MakeCreateTableInput(), [], map [], map [], [], map [], map [], [], [], [], [], [], [], [], [], [], [])
1003
1094
}
1004
1095
1005
1096
method ParseTestVector (data : JSON , prev : TestVectorConfig , keyVectors: KeyVectors .KeyVectorsClient)
@@ -1020,10 +1111,12 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
1020
1111
var ioTests : seq < IoTest> := [];
1021
1112
var gsi : seq < DDB. GlobalSecondaryIndex> := [];
1022
1113
var tableEncryptionConfigs : map < string , TableConfig> := map [];
1114
+ var largeEncryptionConfigs : map < string , TableConfig> := map [];
1023
1115
var writeTests : seq < WriteTest> := [];
1024
1116
var roundTripTests : seq < RoundTripTest> := [];
1025
1117
var decryptTests : seq < DecryptTest> := [];
1026
1118
var strings : seq < string > := [];
1119
+ var large : seq < LargeRecord> := [];
1027
1120
1028
1121
for i := 0 to |data. obj| {
1029
1122
match data. obj[i]. 0 {
@@ -1038,10 +1131,12 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
1038
1131
case "IoTests" => ioTests :- GetIoTests (data.obj[i].1, keyVectors);
1039
1132
case "GSI" => gsi :- GetGSIs (data.obj[i].1);
1040
1133
case "tableEncryptionConfigs" => tableEncryptionConfigs :- GetTableConfigs (data.obj[i].1, keyVectors);
1134
+ case "largeEncryptionConfigs" => largeEncryptionConfigs :- GetTableConfigs (data.obj[i].1, keyVectors);
1041
1135
case "WriteTests" => writeTests :- GetWriteTests (data.obj[i].1, keyVectors);
1042
1136
case "RoundTripTest" => roundTripTests :- GetRoundTripTests (data.obj[i].1, keyVectors);
1043
1137
case "DecryptTests" => decryptTests :- GetDecryptTests (data.obj[i].1, keyVectors);
1044
1138
case "Strings" => strings :- GetStrings (data.obj[i].1);
1139
+ case "Large" => large :- GetLarges (data.obj[i].1);
1045
1140
case _ => return Failure ("Unexpected top level tag " + data.obj[i].0);
1046
1141
}
1047
1142
}
@@ -1052,6 +1147,7 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
1052
1147
schemaOnEncrypt := newSchema,
1053
1148
globalRecords := prev.globalRecords + records,
1054
1149
tableEncryptionConfigs := prev.tableEncryptionConfigs + tableEncryptionConfigs,
1150
+ largeEncryptionConfigs := prev.largeEncryptionConfigs + largeEncryptionConfigs,
1055
1151
queries := prev.queries + queries,
1056
1152
failingQueries := prev.failingQueries + failingQueries,
1057
1153
names := prev.names + names,
@@ -1063,7 +1159,8 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
1063
1159
writeTests := prev.writeTests + writeTests,
1064
1160
roundTripTests := prev.roundTripTests + roundTripTests,
1065
1161
decryptTests := prev.decryptTests + decryptTests,
1066
- strings := prev.strings + strings
1162
+ strings := prev.strings + strings,
1163
+ large := prev.large + large
1067
1164
)
1068
1165
);
1069
1166
}
0 commit comments