From 284914f957ec88c4c3f9e24926da0d068588fae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garci=CC=81a?= Date: Mon, 10 Nov 2025 16:58:42 +0100 Subject: [PATCH 1/2] Lint when holding KeyStoreContext across await points --- clippy.toml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/clippy.toml b/clippy.toml index a29e019ac..a3e600af9 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1,2 +1,10 @@ -allow-unwrap-in-tests=true -allow-expect-in-tests=true +allow-unwrap-in-tests = true +allow-expect-in-tests = true + +await-holding-invalid-types = [ + { path = "bitwarden_crypto::KeyStoreContext", reason = """ +Contains a RwLock guard that will limit concurrency and even deadlock when held across await points. +Instead, prefer to hold a reference to bitwarden_core::KeyStore and use its encrypt/decrypt methods directly. +If you require access to KeyStoreContext, create short-lived KeyStoreContext instances as needed. +""" }, +] From a4c8b21efe3d257bcd0de41e6171ba1a6f2e12b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garci=CC=81a?= Date: Mon, 10 Nov 2025 17:11:53 +0100 Subject: [PATCH 2/2] Fix two lints on vault --- .../src/cipher/cipher_client/edit.rs | 102 +++++++++--------- crates/bitwarden-vault/src/folder/edit.rs | 21 ++-- 2 files changed, 58 insertions(+), 65 deletions(-) diff --git a/crates/bitwarden-vault/src/cipher/cipher_client/edit.rs b/crates/bitwarden-vault/src/cipher/cipher_client/edit.rs index cf7a97646..db0110b34 100644 --- a/crates/bitwarden-vault/src/cipher/cipher_client/edit.rs +++ b/crates/bitwarden-vault/src/cipher/cipher_client/edit.rs @@ -462,58 +462,56 @@ mod tests { cipher_id: CipherId, name: &str, ) { - let mut ctx = store.context(); - - repository - .set( - cipher_id.to_string(), - Cipher { - id: Some(cipher_id), - organization_id: None, - folder_id: None, - collection_ids: vec![], - key: None, - name: name.encrypt(&mut ctx, SymmetricKeyId::User).unwrap(), - notes: None, - r#type: CipherType::Login, - login: Some(Login { - username: Some("test@example.com") - .map(|u| u.encrypt(&mut ctx, SymmetricKeyId::User)) - .transpose() - .unwrap(), - password: Some("password123") - .map(|p| p.encrypt(&mut ctx, SymmetricKeyId::User)) - .transpose() - .unwrap(), - password_revision_date: None, - uris: None, - totp: None, - autofill_on_page_load: None, - fido2_credentials: None, - }), - identity: None, - card: None, - secure_note: None, - ssh_key: None, - favorite: false, - reprompt: CipherRepromptType::None, - organization_use_totp: true, - edit: true, - permissions: None, - view_password: true, - local_data: None, - attachments: None, - fields: None, - password_history: None, - creation_date: "2024-01-01T00:00:00Z".parse().unwrap(), - deleted_date: None, - revision_date: "2024-01-01T00:00:00Z".parse().unwrap(), - archived_date: None, - data: None, - }, - ) - .await - .unwrap(); + let cipher = { + let mut ctx = store.context(); + + Cipher { + id: Some(cipher_id), + organization_id: None, + folder_id: None, + collection_ids: vec![], + key: None, + name: name.encrypt(&mut ctx, SymmetricKeyId::User).unwrap(), + notes: None, + r#type: CipherType::Login, + login: Some(Login { + username: Some("test@example.com") + .map(|u| u.encrypt(&mut ctx, SymmetricKeyId::User)) + .transpose() + .unwrap(), + password: Some("password123") + .map(|p| p.encrypt(&mut ctx, SymmetricKeyId::User)) + .transpose() + .unwrap(), + password_revision_date: None, + uris: None, + totp: None, + autofill_on_page_load: None, + fido2_credentials: None, + }), + identity: None, + card: None, + secure_note: None, + ssh_key: None, + favorite: false, + reprompt: CipherRepromptType::None, + organization_use_totp: true, + edit: true, + permissions: None, + view_password: true, + local_data: None, + attachments: None, + fields: None, + password_history: None, + creation_date: "2024-01-01T00:00:00Z".parse().unwrap(), + deleted_date: None, + revision_date: "2024-01-01T00:00:00Z".parse().unwrap(), + archived_date: None, + data: None, + } + }; + + repository.set(cipher_id.to_string(), cipher).await.unwrap(); } #[tokio::test] diff --git a/crates/bitwarden-vault/src/folder/edit.rs b/crates/bitwarden-vault/src/folder/edit.rs index a3b9fa8d3..878e710f9 100644 --- a/crates/bitwarden-vault/src/folder/edit.rs +++ b/crates/bitwarden-vault/src/folder/edit.rs @@ -76,19 +76,14 @@ mod tests { folder_id: FolderId, name: &str, ) { - repository - .set( - folder_id.to_string(), - Folder { - id: Some(folder_id), - name: name - .encrypt(&mut store.context(), SymmetricKeyId::User) - .unwrap(), - revision_date: "2024-01-01T00:00:00Z".parse().unwrap(), - }, - ) - .await - .unwrap(); + let folder = Folder { + id: Some(folder_id), + name: name + .encrypt(&mut store.context(), SymmetricKeyId::User) + .unwrap(), + revision_date: "2024-01-01T00:00:00Z".parse().unwrap(), + }; + repository.set(folder_id.to_string(), folder).await.unwrap(); } #[tokio::test]