@@ -9,6 +9,12 @@ use crate::migration::plaintext_to_awsdbe::migration_utils::{
9
9
verify_returned_item, ENCRYPTED_AND_SIGNED_VALUE , SIGN_ONLY_VALUE , DO_NOTHING_VALUE ,
10
10
} ;
11
11
use crate :: migration:: plaintext_to_awsdbe:: awsdbe:: common:: create_table_configs;
12
+ // We import these packages for testing combination of migration steps
13
+ use crate :: migration:: plaintext_to_awsdbe:: plaintext:: migration_step_0:: migration_step_0_example;
14
+ use crate :: migration:: plaintext_to_awsdbe:: awsdbe:: migration_step_1:: migration_step_1_example;
15
+ use crate :: migration:: plaintext_to_awsdbe:: awsdbe:: migration_step_2:: migration_step_2_example;
16
+ use crate :: test_utils;
17
+ use uuid:: Uuid ;
12
18
13
19
/*
14
20
Migration Step 3: This is the final step in the migration process from
@@ -137,3 +143,46 @@ pub async fn migration_step_3_example(
137
143
Err ( "No item found" . into ( ) )
138
144
}
139
145
}
146
+
147
+ #[ tokio:: test( flavor = "multi_thread" ) ]
148
+ async fn test_migration_step_3 ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
149
+ let kms_key_id = test_utils:: TEST_KMS_KEY_ID ;
150
+ let table_name = test_utils:: TEST_DDB_TABLE_NAME ;
151
+ let partition_key = Uuid :: new_v4 ( ) . to_string ( ) ;
152
+ let sort_keys = [ "0" , "1" , "2" , "3" ] ;
153
+
154
+ // Given: Step 0 has succeeded
155
+ let success = migration_step_0_example ( table_name, & partition_key, sort_keys[ 0 ] , sort_keys[ 0 ] ) . await ?;
156
+ assert ! ( success, "MigrationStep0 should complete successfully" ) ;
157
+
158
+ // Given: Step 1 has succeeded
159
+ let success = migration_step_1_example ( kms_key_id, table_name, & partition_key, sort_keys[ 1 ] , sort_keys[ 1 ] ) . await ?;
160
+ assert ! ( success, "MigrationStep1 should complete successfully" ) ;
161
+
162
+ // Given: Step 2 has succeeded
163
+ let success = migration_step_2_example ( kms_key_id, table_name, & partition_key, sort_keys[ 2 ] , sort_keys[ 2 ] ) . await ?;
164
+ assert ! ( success, "MigrationStep2 should complete successfully" ) ;
165
+
166
+ // Successfully executes step 3
167
+ let success = migration_step_3_example ( kms_key_id, table_name, & partition_key, sort_keys[ 3 ] , sort_keys[ 3 ] ) . await ?;
168
+ assert ! ( success, "MigrationStep3 should complete successfully" ) ;
169
+
170
+ // When: Execute Step 3 with sortReadValue=0, Then: should error out when reading plaintext items from Step 0
171
+ let result = migration_step_3_example ( kms_key_id, table_name, & partition_key, sort_keys[ 3 ] , sort_keys[ 0 ] ) . await ;
172
+ assert ! ( result. is_err( ) , "MigrationStep3 should fail when reading plaintext items" ) ;
173
+
174
+ // When: Execute Step 3 with sortReadValue=1, Then: should error out when reading plaintext items from Step 1
175
+ let result = migration_step_3_example ( kms_key_id, table_name, & partition_key, sort_keys[ 3 ] , sort_keys[ 1 ] ) . await ;
176
+ assert ! ( result. is_err( ) , "MigrationStep3 should fail when reading plaintext items" ) ;
177
+
178
+ // When: Execute Step 3 with sortReadValue=2, Then: Success (i.e. can read encrypted values from Step 2)
179
+ let success = migration_step_3_example ( kms_key_id, table_name, & partition_key, sort_keys[ 3 ] , sort_keys[ 2 ] ) . await ?;
180
+ assert ! ( success, "MigrationStep3 should be able to read items written by Step 2" ) ;
181
+
182
+ // Cleanup
183
+ for sort_key in & sort_keys {
184
+ test_utils:: cleanup_items ( table_name, & partition_key, sort_key) . await ?;
185
+ }
186
+
187
+ Ok ( ( ) )
188
+ }
0 commit comments