Skip to content

Commit 5725d24

Browse files
committed
update the security verification tests to use new_without_privacy() for tests that inspect raw server data. The metadata privacy feature is tested separately in the metadata_privacy example.
1 parent 0600854 commit 5725d24

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

examples/security_verification.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ async fn test_1_encrypted_data_is_unreadable() -> anyhow::Result<()> {
5050
println!("🔐 Test 1: Encrypted data is unreadable on server");
5151
println!(" Testing that server-stored data doesn't contain plaintext...");
5252

53-
let encryption = EncryptionConfig::new();
53+
// Use without_privacy so we can inspect raw server data with known keys
54+
let encryption = EncryptionConfig::new_without_privacy();
5455
let config = Config::new("http://localhost:9000")
5556
.with_token("test-token");
5657
let encrypted_client = EncryptedClient::new(config.clone(), encryption)?;
@@ -112,8 +113,8 @@ async fn test_2_wrong_key_cannot_decrypt() -> anyhow::Result<()> {
112113
println!("\n🔐 Test 2: Wrong keys cannot decrypt data");
113114
println!(" Testing that attacker with different keys cannot read data...");
114115

115-
// Owner's encryption config
116-
let owner_encryption = EncryptionConfig::new();
116+
// Owner's encryption config (without privacy for predictable key paths)
117+
let owner_encryption = EncryptionConfig::new_without_privacy();
117118
let owner_config = Config::new("http://localhost:9000")
118119
.with_token("owner-token");
119120
let owner_client = EncryptedClient::new(owner_config, owner_encryption)?;
@@ -125,8 +126,8 @@ async fn test_2_wrong_key_cannot_decrypt() -> anyhow::Result<()> {
125126
let secret = "Bank account: 1234567890, PIN: 9999";
126127
owner_client.put_object_encrypted(bucket, "bank.txt", secret.as_bytes().to_vec()).await?;
127128

128-
// Attacker tries with different keys
129-
let attacker_encryption = EncryptionConfig::new();
129+
// Attacker tries with different keys (also without privacy to use same key path)
130+
let attacker_encryption = EncryptionConfig::new_without_privacy();
130131
let attacker_config = Config::new("http://localhost:9000")
131132
.with_token("attacker-token");
132133
let attacker_client = EncryptedClient::new(attacker_config, attacker_encryption)?;
@@ -211,8 +212,8 @@ async fn test_4_key_recovery_works() -> anyhow::Result<()> {
211212
println!("\n🔐 Test 4: Key recovery functionality");
212213
println!(" Testing that exported keys can decrypt data...");
213214

214-
// Original encryption setup
215-
let encryption = EncryptionConfig::new();
215+
// Original encryption setup (without privacy for predictable key paths)
216+
let encryption = EncryptionConfig::new_without_privacy();
216217

217218
// Export the secret key (simulating backup)
218219
let secret_key_backup = encryption.export_secret_key().to_base64();
@@ -230,7 +231,8 @@ async fn test_4_key_recovery_works() -> anyhow::Result<()> {
230231

231232
// Simulate key loss - create new client with recovered key
232233
let recovered_secret = SecretKey::from_base64(&secret_key_backup)?;
233-
let recovered_encryption = EncryptionConfig::from_secret_key(recovered_secret);
234+
let recovered_encryption = EncryptionConfig::from_secret_key(recovered_secret)
235+
.with_metadata_privacy(false); // Match original client settings
234236
let recovered_client = EncryptedClient::new(config, recovered_encryption)?;
235237

236238
// Decrypt with recovered key
@@ -331,7 +333,8 @@ async fn test_7_server_never_sees_plaintext() -> anyhow::Result<()> {
331333
println!("\n🔐 Test 7: Server-side plaintext isolation");
332334
println!(" Testing that plaintext never reaches the server...");
333335

334-
let encryption = EncryptionConfig::new();
336+
// Without privacy so we can inspect raw server data with known keys
337+
let encryption = EncryptionConfig::new_without_privacy();
335338
let config = Config::new("http://localhost:9000")
336339
.with_token("test-token");
337340
let client = EncryptedClient::new(config.clone(), encryption)?;

0 commit comments

Comments
 (0)