Skip to content

Commit 0089b0e

Browse files
auto commit
1 parent 5657883 commit 0089b0e

File tree

7 files changed

+177
-214
lines changed

7 files changed

+177
-214
lines changed

DynamoDbEncryption/runtimes/rust/examples/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub mod keyring;
1414
pub mod multi_get_put_example;
1515
pub mod searchableencryption;
1616
pub mod test_utils;
17+
pub mod migration;
1718

1819
use std::convert::From;
1920

DynamoDbEncryption/runtimes/rust/examples/migration/plaintext_to_awsdbe/awsdbe/migration_step_1.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ use crate::migration::plaintext_to_awsdbe::migration_utils::{
99
verify_returned_item, ENCRYPTED_AND_SIGNED_VALUE, SIGN_ONLY_VALUE, DO_NOTHING_VALUE,
1010
};
1111
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_2::migration_step_2_example;
15+
use crate::migration::plaintext_to_awsdbe::awsdbe::migration_step_3::migration_step_3_example;
16+
use crate::test_utils;
17+
use uuid::Uuid;
1218

1319
/*
1420
Migration Step 1: This is the first step in the migration process from
@@ -134,3 +140,46 @@ pub async fn migration_step_1_example(
134140
Err("No item found".into())
135141
}
136142
}
143+
144+
#[tokio::test(flavor = "multi_thread")]
145+
async fn test_migration_step_1() -> Result<(), Box<dyn std::error::Error>> {
146+
let kms_key_id = test_utils::TEST_KMS_KEY_ID;
147+
let table_name = test_utils::TEST_DDB_TABLE_NAME;
148+
let partition_key = Uuid::new_v4().to_string();
149+
let sort_keys = ["0", "1", "2", "3"];
150+
151+
// Given: Step 0 has succeeded
152+
let success = migration_step_0_example(table_name, &partition_key, sort_keys[0], sort_keys[0]).await?;
153+
assert!(success, "MigrationStep0 should complete successfully");
154+
155+
// Successfully executes step 1
156+
let success = migration_step_1_example(kms_key_id, table_name, &partition_key, sort_keys[1], sort_keys[1]).await?;
157+
assert!(success, "MigrationStep1 should complete successfully");
158+
159+
// When: Execute Step 1 with sortReadValue=0, Then: Success (i.e. can read plaintext values from Step 0)
160+
let success = migration_step_1_example(kms_key_id, table_name, &partition_key, sort_keys[1], sort_keys[0]).await?;
161+
assert!(success, "MigrationStep1 should be able to read items written by Step 0");
162+
163+
// Given: Step 2 has succeeded
164+
let success = migration_step_2_example(kms_key_id, table_name, &partition_key, sort_keys[2], sort_keys[2]).await?;
165+
assert!(success, "MigrationStep2 should complete successfully");
166+
167+
// When: Execute Step 1 with sortReadValue=2, Then: Success (i.e. can read encrypted values from Step 2)
168+
let success = migration_step_1_example(kms_key_id, table_name, &partition_key, sort_keys[1], sort_keys[2]).await?;
169+
assert!(success, "MigrationStep1 should be able to read items written by Step 2");
170+
171+
// Given: Step 3 has succeeded
172+
let success = migration_step_3_example(kms_key_id, table_name, &partition_key, sort_keys[3], sort_keys[3]).await?;
173+
assert!(success, "MigrationStep3 should complete successfully");
174+
175+
// When: Execute Step 1 with sortReadValue=3, Then: Success (i.e. can read encrypted values from Step 3)
176+
let success = migration_step_1_example(kms_key_id, table_name, &partition_key, sort_keys[1], sort_keys[3]).await?;
177+
assert!(success, "MigrationStep1 should be able to read items written by Step 3");
178+
179+
// Cleanup
180+
for sort_key in &sort_keys {
181+
test_utils::cleanup_items(table_name, &partition_key, sort_key).await?;
182+
}
183+
184+
Ok(())
185+
}

DynamoDbEncryption/runtimes/rust/examples/migration/plaintext_to_awsdbe/awsdbe/migration_step_2.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ use crate::migration::plaintext_to_awsdbe::migration_utils::{
99
verify_returned_item, ENCRYPTED_AND_SIGNED_VALUE, SIGN_ONLY_VALUE, DO_NOTHING_VALUE,
1010
};
1111
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_3::migration_step_3_example;
16+
use crate::test_utils;
17+
use uuid::Uuid;
1218

1319
/*
1420
Migration Step 2: This is the second step in the migration process from
@@ -136,3 +142,46 @@ pub async fn migration_step_2_example(
136142
Err("No item found".into())
137143
}
138144
}
145+
146+
#[tokio::test(flavor = "multi_thread")]
147+
async fn test_migration_step_2() -> Result<(), Box<dyn std::error::Error>> {
148+
let kms_key_id = test_utils::TEST_KMS_KEY_ID;
149+
let table_name = test_utils::TEST_DDB_TABLE_NAME;
150+
let partition_key = Uuid::new_v4().to_string();
151+
let sort_keys = ["0", "1", "2", "3"];
152+
153+
// Given: Step 0 has succeeded
154+
let success = migration_step_0_example(table_name, &partition_key, sort_keys[0], sort_keys[0]).await?;
155+
assert!(success, "MigrationStep0 should complete successfully");
156+
157+
// Given: Step 1 has succeeded
158+
let success = migration_step_1_example(kms_key_id, table_name, &partition_key, sort_keys[1], sort_keys[1]).await?;
159+
assert!(success, "MigrationStep1 should complete successfully");
160+
161+
// Successfully executes step 2
162+
let success = migration_step_2_example(kms_key_id, table_name, &partition_key, sort_keys[2], sort_keys[2]).await?;
163+
assert!(success, "MigrationStep2 should complete successfully");
164+
165+
// When: Execute Step 2 with sortReadValue=0, Then: Success (i.e. can read plaintext values from Step 0)
166+
let success = migration_step_2_example(kms_key_id, table_name, &partition_key, sort_keys[2], sort_keys[0]).await?;
167+
assert!(success, "MigrationStep2 should be able to read items written by Step 0");
168+
169+
// When: Execute Step 2 with sortReadValue=1, Then: Success (i.e. can read plaintext values from Step 1)
170+
let success = migration_step_2_example(kms_key_id, table_name, &partition_key, sort_keys[2], sort_keys[1]).await?;
171+
assert!(success, "MigrationStep2 should be able to read items written by Step 1");
172+
173+
// Given: Step 3 has succeeded
174+
let success = migration_step_3_example(kms_key_id, table_name, &partition_key, sort_keys[3], sort_keys[3]).await?;
175+
assert!(success, "MigrationStep3 should complete successfully");
176+
177+
// When: Execute Step 2 with sortReadValue=3, Then: Success (i.e. can read encrypted values from Step 3)
178+
let success = migration_step_2_example(kms_key_id, table_name, &partition_key, sort_keys[2], sort_keys[3]).await?;
179+
assert!(success, "MigrationStep2 should be able to read items written by Step 3");
180+
181+
// Cleanup
182+
for sort_key in &sort_keys {
183+
test_utils::cleanup_items(table_name, &partition_key, sort_key).await?;
184+
}
185+
186+
Ok(())
187+
}

DynamoDbEncryption/runtimes/rust/examples/migration/plaintext_to_awsdbe/migration_tests.rs

Lines changed: 0 additions & 210 deletions
This file was deleted.
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
pub mod awsdbe;
45
pub mod migration_utils;
56
pub mod plaintext;
6-
pub mod awsdbe;
7-
8-
#[cfg(test)]
9-
pub mod migration_tests;

0 commit comments

Comments
 (0)