Skip to content

Commit 7210baf

Browse files
auto commit
1 parent 482e76b commit 7210baf

File tree

1 file changed

+23
-43
lines changed

1 file changed

+23
-43
lines changed

TestVectors/dafny/DDBEncryption/src/TestVectors.dfy

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -841,12 +841,11 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
841841
{
842842
var wClient :- expect newGazelle(writeConfig);
843843
var rClient :- expect newGazelle(readConfig);
844+
DeleteTable(wClient);
844845
WriteAllRecords(wClient, records);
845846

846847
// Update each record by appending "-updated" to the partition key
847848
for i := 0 to |records| {
848-
:- expect Need(HashName in records[i].item, "");
849-
850849
// Get the current value of the partition key
851850
var currentValue;
852851
currentValue := records[i].item[HashName].N;
@@ -879,63 +878,44 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
879878
// In test vectors, we still have to change the error from AWS SDK to dafny so it turns out to be OpaqueWithText.
880879
expect updateSignedItemResult.error.OpaqueWithText?, "Error should have been of type OpaqueWithText";
881880
var hasDynamoDbEncryptionTransformsException? := String.HasSubString(updateSignedItemResult.error.objMessage, "Update Expressions forbidden on signed attributes");
882-
expect hasDynamoDbEncryptionTransformsException?.Some?;
881+
expect hasDynamoDbEncryptionTransformsException?.Some?, "Error might is not be of type DynamoDbEncryptionTransformsException";
883882
}
884883
}
885884

886885
method BasicIoTestDeleteItem(writeConfig : TableConfig, readConfig : TableConfig, records : seq<Record>)
887886
{
888887
var wClient :- expect newGazelle(writeConfig);
889888
var rClient :- expect newGazelle(readConfig);
889+
DeleteTable(wClient);
890890
WriteAllRecords(wClient, records);
891891

892-
// Only delete half of the records to verify selective deletion
893-
var deleteCount := |records| / 2;
894-
895-
for i := 0 to deleteCount {
896-
:- expect Need(HashName in records[i].item, "");
897-
898-
var deleteInput := DDB.DeleteItemInput(
899-
TableName := TableName,
900-
Key := map[HashName := records[i].item[HashName]],
901-
Expected := None,
902-
ReturnValues := None,
903-
ReturnConsumedCapacity := None,
904-
ReturnItemCollectionMetrics := None,
905-
ConditionExpression := None,
906-
ExpressionAttributeNames := None,
907-
ExpressionAttributeValues := None
908-
);
909-
910-
var _ :- expect wClient.DeleteItem(deleteInput);
911-
}
912-
913-
// Verify deletions were successful
892+
// Try to delete records with a condition expression with condition to
893+
// delete records if the record has an attribute "randomAttribute" with value "random"
894+
// These are random attribute and value because we conditional expression should fail before going into dynamodb.
914895
for i := 0 to |records| {
915-
:- expect Need(HashName in records[i].item, "");
896+
// Set up condition expression to only delete if randomAttribute = "random"
897+
var conditionExpr := "#attr = :val";
898+
var exprAttrNames := map["#attr" := "randomAttribute"];
899+
var exprAttrValues := map[":val" := DDB.AttributeValue.S("random")];
916900

917-
var getInput := DDB.GetItemInput(
901+
var deleteInput := DDB.DeleteItemInput(
918902
TableName := TableName,
919903
Key := map[HashName := records[i].item[HashName]],
920-
AttributesToGet := None,
921-
ConsistentRead := None,
922-
ReturnConsumedCapacity := None,
923-
ProjectionExpression := None,
924-
ExpressionAttributeNames := None
904+
ConditionExpression := Some(conditionExpr),
905+
ExpressionAttributeNames := Some(exprAttrNames),
906+
ExpressionAttributeValues := Some(exprAttrValues)
925907
);
926908

927-
var out := rClient.GetItem(getInput);
909+
// The delete operation will succeed only if the condition is met
910+
var deleteResult := wClient.DeleteItem(deleteInput);
928911

929-
if i < deleteCount {
930-
// Deleted items should not be found
931-
expect out.Success?;
932-
expect out.value.Item.None?, "Item " + String.Base10Int2String(i) + " should have been deleted";
933-
} else {
934-
// Non-deleted items should still exist
935-
expect out.Success?;
936-
expect out.value.Item.Some?;
937-
expect NormalizeItem(out.value.Item.value) == NormalizeItem(records[i].item);
938-
}
912+
expect deleteResult.Failure?, "DeleteItem should have failed.";
913+
// This error is of type DynamoDbEncryptionTransformsException
914+
// but AWS SDK wraps it into its own type for which customers should be unwrapping.
915+
// In test vectors, we still have to change the error from AWS SDK to dafny so it turns out to be OpaqueWithText.
916+
expect deleteResult.error.OpaqueWithText?, "Error should have been of type OpaqueWithText";
917+
var hasDynamoDbEncryptionTransformsException? := String.HasSubString(deleteResult.error.objMessage, "Condition Expressions forbidden on encrypted attributes");
918+
expect hasDynamoDbEncryptionTransformsException?.Some?, "Error might is not be of type DynamoDbEncryptionTransformsException";
939919
}
940920
}
941921

0 commit comments

Comments
 (0)