|
| 1 | +package plaintext |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/aws/aws-database-encryption-sdk-dynamodb/releases/go/dynamodb-esdk/examples/migration/PlaintextToAWSDBE/awsdbe" |
| 7 | + "github.com/aws/aws-database-encryption-sdk-dynamodb/releases/go/dynamodb-esdk/examples/utils" |
| 8 | + "github.com/google/uuid" |
| 9 | +) |
| 10 | + |
| 11 | +func TestMigrationStep0(t *testing.T) { |
| 12 | + kmsKeyID := utils.KmsKeyID() |
| 13 | + tableName := utils.DdbTableName() |
| 14 | + partitionKey := uuid.New().String() |
| 15 | + sortKeys := []string{"0", "1", "2", "3"} |
| 16 | + |
| 17 | + // Successfully executes step 0 |
| 18 | + err := MigrationStep0(tableName, partitionKey, sortKeys[0]) |
| 19 | + utils.HandleError(err) |
| 20 | + |
| 21 | + // Given: Step 1 has succeeded |
| 22 | + err = awsdbe.MigrationStep1(kmsKeyID, tableName, partitionKey, sortKeys[1]) |
| 23 | + utils.HandleError(err) |
| 24 | + |
| 25 | + // When: Execute Step 0 with sortReadValue=1, Then: Success (i.e. can read plaintext values) |
| 26 | + err = MigrationStep0(tableName, partitionKey, sortKeys[1]) |
| 27 | + utils.HandleError(err) |
| 28 | + |
| 29 | + // Given: Step 2 has succeeded |
| 30 | + err = awsdbe.MigrationStep2(kmsKeyID, tableName, partitionKey, sortKeys[2]) |
| 31 | + utils.HandleError(err) |
| 32 | + |
| 33 | + // When: Execute Step 0 with sortReadValue=2, Then: should error out when reading encrypted items. |
| 34 | + err = MigrationStep0(tableName, partitionKey, sortKeys[2]) |
| 35 | + utils.AssertErrorMessage(err, "partition_key is not a string attribute") |
| 36 | + |
| 37 | + // Given: Step 3 has succeeded (if it exists) |
| 38 | + awsdbe.MigrationStep3(kmsKeyID, tableName, partitionKey, sortKeys[3]) |
| 39 | + // When: Execute Step 0 with sortReadValue=3, Then: should error out |
| 40 | + err = MigrationStep0(tableName, partitionKey, sortKeys[3]) |
| 41 | + utils.AssertErrorMessage(err, "partition_key is not a string attribute") |
| 42 | + |
| 43 | + // Cleanup |
| 44 | + for _, sortKey := range sortKeys[:3] { // Only clean up items we created |
| 45 | + utils.DeleteItem(tableName, "partition_key", partitionKey, "sort_key", sortKey) |
| 46 | + } |
| 47 | +} |
0 commit comments