Skip to content

Commit 9582321

Browse files
auto commit
1 parent cd82fb9 commit 9582321

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

TestVectors/dafny/DDBEncryption/src/TestVectors.dfy

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
384384
BasicIoTestBatchWriteItem(c1, c2, globalRecords);
385385
BasicIoTestPutItem(c1, c2, globalRecords);
386386
BasicIoTestTransactWriteItems(c1, c2, globalRecords);
387-
BasicIoTestUpdateItem(c1, c2, globalRecords);
387+
BasicIoTestUpdateItem(c1, c2, globalRecords, "One");
388+
BasicIoTestUpdateItem(c1, c2, globalRecords, "Two");
388389
BasicIoTestDeleteItem(c1, c2, globalRecords);
389390
BasicIoTestExecuteStatement(c1, c2);
390391
}
@@ -837,7 +838,7 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
837838
BasicIoTestTransactGetItems(rClient, records);
838839
}
839840

840-
method BasicIoTestUpdateItem(writeConfig : TableConfig, readConfig : TableConfig, records : seq<Record>)
841+
method {:only} BasicIoTestUpdateItem(writeConfig : TableConfig, readConfig : TableConfig, records : seq<Record>, attributeToUpdate: DDB.AttributeName)
841842
{
842843
var wClient :- expect newGazelle(writeConfig);
843844
var rClient :- expect newGazelle(readConfig);
@@ -847,14 +848,12 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
847848
// Update each record by appending "updated" to the partition key
848849
for i := 0 to |records| {
849850
var newValue := "updated";
850-
851851
// Create an update expression to update the partition key
852-
var updateExpr := "SET #pk = :val";
853-
var exprAttrNames := map["#pk" := HashName];
852+
var updateExpr := "SET #att = :val";
853+
expect attributeToUpdate in writeConfig.config.attributeActionsOnEncrypt, "`attributeToUpdate` not in attributeActionsOnEncrypt";
854+
var exprAttrNames := map["#att" := attributeToUpdate];
854855
var exprAttrValues := map[":val" := DDB.AttributeValue.S(newValue)];
855-
856856
expect HashName in records[i].item, "`HashName` is not in records.";
857-
858857
var updateInput := DDB.UpdateItemInput(
859858
TableName := TableName,
860859
Key := map[HashName := records[i].item[HashName]],
@@ -866,15 +865,18 @@ module {:options "-functionSyntax:4"} DdbEncryptionTestVectors {
866865
ReturnItemCollectionMetrics := None,
867866
ConditionExpression := None
868867
);
869-
870-
var updateSignedItemResult := wClient.UpdateItem(updateInput);
871-
expect updateSignedItemResult.Failure?, "UpdateItem should have failed for signed item.";
872-
// This error is of type DynamoDbEncryptionTransformsException
873-
// but AWS SDK wraps it into its own type for which customers should be unwrapping.
874-
// In test vectors, we still have to change the error from AWS SDK to dafny so it turns out to be OpaqueWithText.
875-
expect updateSignedItemResult.error.OpaqueWithText?, "Error should have been of type OpaqueWithText";
876-
var hasDynamoDbEncryptionTransformsException? := String.HasSubString(updateSignedItemResult.error.objMessage, "Update Expressions forbidden on signed attributes");
877-
expect hasDynamoDbEncryptionTransformsException?.Some?, "Error might is not be of type DynamoDbEncryptionTransformsException";
868+
var updateResult := wClient.UpdateItem(updateInput);
869+
if writeConfig.config.attributeActionsOnEncrypt[attributeToUpdate] == SE.ENCRYPT_AND_SIGN || writeConfig.config.attributeActionsOnEncrypt[attributeToUpdate] == SE.SIGN_ONLY {
870+
expect updateResult.Failure?, "UpdateItem should have failed for signed item.";
871+
// This error is of type DynamoDbEncryptionTransformsException
872+
// but AWS SDK wraps it into its own type for which customers should be unwrapping.
873+
// In test vectors, we still have to change the error from AWS SDK to dafny so it turns out to be OpaqueWithText.
874+
expect updateResult.error.OpaqueWithText?, "Error should have been of type OpaqueWithText";
875+
var hasDynamoDbEncryptionTransformsException? := String.HasSubString(updateResult.error.objMessage, "Update Expressions forbidden on signed attributes");
876+
expect hasDynamoDbEncryptionTransformsException?.Some?, "Error might is not be of type DynamoDbEncryptionTransformsException";
877+
} else {
878+
expect updateResult.Success?;
879+
}
878880
}
879881
}
880882

0 commit comments

Comments
 (0)