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 66a19ab

Browse files
authoredJun 9, 2025··
chore(dafny): Add ExecuteStatement test (#1932)
1 parent 6173888 commit 66a19ab

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
 

‎TestVectors/dafny/DDBEncryption/src/TestVectors.dfy

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
384384
BasicIoTestBatchWriteItem(c1, c2, globalRecords);
385385
BasicIoTestPutItem(c1, c2, globalRecords);
386386
BasicIoTestTransactWriteItems(c1, c2, globalRecords);
387+
BasicIoTestExecuteStatement(c1, c2);
387388
}
388389
}
389390

@@ -834,6 +835,50 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
834835
BasicIoTestTransactGetItems(rClient, records);
835836
}
836837

838+
method BasicIoTestExecuteStatement(writeConfig : TableConfig, readConfig : TableConfig)
839+
{
840+
var wClient :- expect newGazelle(writeConfig);
841+
var rClient :- expect newGazelle(readConfig);
842+
DeleteTable(wClient);
843+
var _ :- expect wClient.CreateTable(schemaOnEncrypt);
844+
845+
// Create a PartiQL INSERT statement
846+
// The dynamodb attributes are random and non-existent because ExecuteStatement is supposed to be failed before going into dynamodb.
847+
var insertStatement := "INSERT INTO \"" + TableName + "\" VALUE {'partition_key': 'a', 'sort_key': 'b', 'attribute1': 'a'";
848+
var inputForInsertStatement := DDB.ExecuteStatementInput(
849+
Statement := insertStatement,
850+
Parameters := None,
851+
ConsistentRead := None,
852+
NextToken := None,
853+
ReturnConsumedCapacity := None,
854+
Limit := None
855+
);
856+
var resultForInsertStatement := wClient.ExecuteStatement(inputForInsertStatement);
857+
expect resultForInsertStatement.Failure?, "ExecuteStatement should have failed";
858+
// This error is of type DynamoDbEncryptionTransformsException
859+
// but AWS SDK wraps it into its own type for which customers should be unwrapping.
860+
// In test vectors, we still have to change the error from AWS SDK to dafny so it turns out to be OpaqueWithText.
861+
expect resultForInsertStatement.error.OpaqueWithText?, "Error should have been of type OpaqueWithText";
862+
863+
// Create a PartiQL SELECT statement
864+
// The dynamodb attributes are random and non-existent because ExecuteStatement is supposed to be failed before going into dynamodb.
865+
var selectStatement := "SELECT * FROM " + TableName + " WHERE partition_key = 'a' AND sort_key = 'b'";
866+
var inputForSelectStatement := DDB.ExecuteStatementInput(
867+
Statement := selectStatement,
868+
Parameters := None,
869+
ConsistentRead := Some(true),
870+
NextToken := None,
871+
ReturnConsumedCapacity := None,
872+
Limit := None
873+
);
874+
var resultForSelectStatement := rClient.ExecuteStatement(inputForSelectStatement);
875+
expect resultForSelectStatement.Failure?, "ExecuteStatement should have failed";
876+
// This error is of type DynamoDbEncryptionTransformsException
877+
// but AWS SDK wraps it into its own type for which customers should be unwrapping.
878+
// In test vectors, we still have to change the error from AWS SDK to dafny so it turns out to be OpaqueWithText.
879+
expect resultForSelectStatement.error.OpaqueWithText?, "Error should have been of type OpaqueWithText";
880+
}
881+
837882
method FindMatchingRecord(expected : DDB.AttributeMap, actual : DDB.ItemList) returns (output : bool)
838883
{
839884
var exp := NormalizeItem(expected);

0 commit comments

Comments
 (0)
Please sign in to comment.