From 418a3c473274581572729ef80b0b4948931676b3 Mon Sep 17 00:00:00 2001 From: Hinton Date: Fri, 3 May 2024 12:44:56 +0200 Subject: [PATCH] Hide Sensitive::test behind flag --- crates/bitwarden-crypto/Cargo.toml | 1 + crates/bitwarden-crypto/src/sensitive/sensitive.rs | 4 +--- crates/bitwarden-exporters/Cargo.toml | 3 +++ crates/bitwarden/Cargo.toml | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/bitwarden-crypto/Cargo.toml b/crates/bitwarden-crypto/Cargo.toml index f07fc2a04..9da62a44c 100644 --- a/crates/bitwarden-crypto/Cargo.toml +++ b/crates/bitwarden-crypto/Cargo.toml @@ -17,6 +17,7 @@ keywords.workspace = true default = [] mobile = ["dep:uniffi"] # Mobile-specific features +test = [] # Test methods [dependencies] aes = { version = ">=0.8.2, <0.9", features = ["zeroize"] } diff --git a/crates/bitwarden-crypto/src/sensitive/sensitive.rs b/crates/bitwarden-crypto/src/sensitive/sensitive.rs index 2ae54d7a2..4ae779f05 100644 --- a/crates/bitwarden-crypto/src/sensitive/sensitive.rs +++ b/crates/bitwarden-crypto/src/sensitive/sensitive.rs @@ -228,9 +228,7 @@ impl JsonSchema for Sensitive { // We use a lot of `&str` and `&[u8]` in our tests, so we expose this helper // to make it easier. // IMPORTANT: This should not be used outside of test code -// Note that we can't just mark it with #[cfg(test)] because that only applies -// when testing this crate, not when testing other crates that depend on it. -// By at least limiting it to &'static reference we should be able to avoid accidental usages +#[cfg(any(test, feature = "test"))] impl Sensitive { pub fn test(value: &'static T) -> Self where diff --git a/crates/bitwarden-exporters/Cargo.toml b/crates/bitwarden-exporters/Cargo.toml index ddfff5b38..3b19d4bf5 100644 --- a/crates/bitwarden-exporters/Cargo.toml +++ b/crates/bitwarden-exporters/Cargo.toml @@ -29,5 +29,8 @@ serde_json = ">=1.0.96, <2.0" thiserror = ">=1.0.40, <2.0" uuid = { version = ">=1.3.3, <2.0", features = ["serde", "v4"] } +[dev-dependencies] +bitwarden-crypto = { workspace = true, features = ["test"] } + [lints] workspace = true diff --git a/crates/bitwarden/Cargo.toml b/crates/bitwarden/Cargo.toml index 3e92981f0..0be39073e 100644 --- a/crates/bitwarden/Cargo.toml +++ b/crates/bitwarden/Cargo.toml @@ -81,6 +81,7 @@ reqwest = { version = ">=0.12, <0.13", features = [ ], default-features = false } [dev-dependencies] +bitwarden-crypto = { workspace = true, features = ["test"] } rand_chacha = "0.3.1" tokio = { version = "1.36.0", features = ["rt", "macros"] } wiremock = "0.6.0"