Skip to content

Migrate folder create and edit #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"spki",
"totp",
"uniffi",
"wiremock",
"wordlist",
"XCHACHA",
"Zeroize",
Expand Down
16 changes: 15 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ bitwarden-fido = { path = "crates/bitwarden-fido", version = "=1.0.0" }
bitwarden-generators = { path = "crates/bitwarden-generators", version = "=1.0.0" }
bitwarden-ipc = { path = "crates/bitwarden-ipc", version = "=1.0.0" }
bitwarden-send = { path = "crates/bitwarden-send", version = "=1.0.0" }
bitwarden-state = { path = "crates/bitwarden-state", version = "=1.0.0" }
bitwarden-threading = { path = "crates/bitwarden-threading", version = "=1.0.0" }
bitwarden-sm = { path = "bitwarden_license/bitwarden-sm", version = "=1.0.0" }
bitwarden-ssh = { path = "crates/bitwarden-ssh", version = "=1.0.0" }
bitwarden-state = { path = "crates/bitwarden-state", version = "=1.0.0" }
bitwarden-test = { path = "crates/bitwarden-test", version = "=1.0.0" }
bitwarden-threading = { path = "crates/bitwarden-threading", version = "=1.0.0" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we were running cargo sort to check the order here, I wonder how these went through initially

bitwarden-uuid = { path = "crates/bitwarden-uuid", version = "=1.0.0" }
bitwarden-uuid-macro = { path = "crates/bitwarden-uuid-macro", version = "=1.0.0" }
bitwarden-vault = { path = "crates/bitwarden-vault", version = "=1.0.0" }
Expand All @@ -60,6 +61,7 @@ serde = { version = ">=1.0, <2.0", features = ["derive"] }
serde_json = ">=1.0.96, <2.0"
serde_qs = ">=0.12.0, <0.16"
serde_repr = ">=0.1.12, <0.2"
serde-wasm-bindgen = ">=0.6.0, <0.7"
syn = ">=2.0.87, <3"
thiserror = ">=1.0.40, <3"
tokio = { version = "1.36.0", features = ["macros"] }
Expand All @@ -72,7 +74,7 @@ validator = { version = ">=0.18.1, <0.21", features = ["derive"] }
wasm-bindgen = { version = ">=0.2.91, <0.3", features = ["serde-serialize"] }
wasm-bindgen-futures = "0.4.41"
wasm-bindgen-test = "0.3.45"
serde-wasm-bindgen = ">=0.6.0, <0.7"
wiremock = ">=0.6.0, <0.7"

# There is an incompatibility when using pkcs5 and chacha20 on wasm builds. This can be removed once a new
# rustcrypto-formats crate version is released since the fix has been upstreamed.
Expand Down
2 changes: 1 addition & 1 deletion bitwarden_license/bitwarden-sm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ validator = { workspace = true }

[dev-dependencies]
tokio = { workspace = true, features = ["rt"] }
wiremock = "0.6.0"
wiremock = { workspace = true }

[lints]
workspace = true
2 changes: 1 addition & 1 deletion crates/bitwarden-generators/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ wasm-bindgen = { workspace = true, optional = true }
[dev-dependencies]
rand_chacha = "0.3.1"
tokio = { workspace = true, features = ["rt"] }
wiremock = "0.6.0"
wiremock = { workspace = true }

[lints]
workspace = true
25 changes: 25 additions & 0 deletions crates/bitwarden-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "bitwarden-test"
description = """
Internal crate for the bitwarden crate. Do not use.
"""

version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
license-file.workspace = true
keywords.workspace = true

[dependencies]
async-trait = { workspace = true }
bitwarden-api-api.workspace = true
bitwarden-state = { workspace = true }
reqwest = { workspace = true }
wiremock = { workspace = true }

[lints]
workspace = true
7 changes: 7 additions & 0 deletions crates/bitwarden-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Bitwarden Test

<div class="warning">
This crate should only be used in tests and should not be included in production builds.
</div>

Contains test utilities for Bitwarden.
24 changes: 24 additions & 0 deletions crates/bitwarden-test/src/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use bitwarden_api_api::apis::configuration::Configuration;

/// Helper for testing the Bitwarden API using wiremock.
///
/// Warning: when using `Mock::expected` ensure `server` is not dropped before the test completes,
pub async fn start_api_mock(mocks: Vec<wiremock::Mock>) -> (wiremock::MockServer, Configuration) {
let server = wiremock::MockServer::start().await;

for mock in mocks {
server.register(mock).await;
}

let config = Configuration {
base_path: server.uri(),
user_agent: Some("test-agent".to_string()),
client: reqwest::Client::new(),
basic_auth: None,
oauth_access_token: None,
bearer_access_token: None,
api_key: None,
};

(server, config)
}
7 changes: 7 additions & 0 deletions crates/bitwarden-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![doc = include_str!("../README.md")]

mod api;
pub use api::*;

mod repository;
pub use repository::*;
54 changes: 54 additions & 0 deletions crates/bitwarden-test/src/repository.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use bitwarden_state::repository::{Repository, RepositoryError, RepositoryItem};

/// A simple in-memory repository implementation. The data is only stored in memory and will not
/// persist beyond the lifetime of the repository instance.
///
/// Primary use case is for unit and integration tests.
pub struct MemoryRepository<V: RepositoryItem> {
store: std::sync::Mutex<std::collections::HashMap<String, V>>,
}

impl<V: RepositoryItem + Clone> Default for MemoryRepository<V> {
fn default() -> Self {
Self {
store: std::sync::Mutex::new(std::collections::HashMap::new()),
}
}
}

#[async_trait::async_trait]
impl<V: RepositoryItem + Clone> Repository<V> for MemoryRepository<V> {
async fn get(&self, key: String) -> Result<Option<V>, RepositoryError> {
let store = self
.store
.lock()
.map_err(|e| RepositoryError::Internal(e.to_string()))?;
Ok(store.get(&key).cloned())
}

async fn list(&self) -> Result<Vec<V>, RepositoryError> {
let store = self
.store
.lock()
.map_err(|e| RepositoryError::Internal(e.to_string()))?;
Ok(store.values().cloned().collect())
}

Check warning on line 35 in crates/bitwarden-test/src/repository.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-test/src/repository.rs#L29-L35

Added lines #L29 - L35 were not covered by tests

async fn set(&self, key: String, value: V) -> Result<(), RepositoryError> {
let mut store = self
.store
.lock()
.map_err(|e| RepositoryError::Internal(e.to_string()))?;
store.insert(key, value);
Ok(())
}

async fn remove(&self, key: String) -> Result<(), RepositoryError> {
let mut store = self
.store
.lock()
.map_err(|e| RepositoryError::Internal(e.to_string()))?;
store.remove(&key);
Ok(())
}

Check warning on line 53 in crates/bitwarden-test/src/repository.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-test/src/repository.rs#L46-L53

Added lines #L46 - L53 were not covered by tests
}
6 changes: 5 additions & 1 deletion crates/bitwarden-vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ uniffi = [
wasm = [
"bitwarden-core/wasm",
"dep:tsify-next",
"dep:wasm-bindgen"
"dep:wasm-bindgen",
"dep:wasm-bindgen-futures"
] # WASM support

[dependencies]
Expand All @@ -48,9 +49,12 @@ tsify-next = { workspace = true, optional = true }
uniffi = { workspace = true, optional = true }
uuid = { workspace = true }
wasm-bindgen = { workspace = true, optional = true }
wasm-bindgen-futures = { workspace = true, optional = true }

[dev-dependencies]
bitwarden-test = { workspace = true }
tokio = { workspace = true, features = ["rt"] }
wiremock = { workspace = true }

[lints]
workspace = true
Loading