From ff3ff6026ada02068008b4a30dcf2c4f5a0104d7 Mon Sep 17 00:00:00 2001 From: Hinton Date: Tue, 31 Oct 2023 11:43:25 +0100 Subject: [PATCH] Move test to integration test --- crates/bitwarden/src/client/client.rs | 47 ++++----------------------- crates/bitwarden/tests/register.rs | 35 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 41 deletions(-) create mode 100644 crates/bitwarden/tests/register.rs diff --git a/crates/bitwarden/src/client/client.rs b/crates/bitwarden/src/client/client.rs index 35e230e29..b29118fe5 100644 --- a/crates/bitwarden/src/client/client.rs +++ b/crates/bitwarden/src/client/client.rs @@ -1,5 +1,10 @@ use std::time::{Duration, Instant}; +use reqwest::header::{self}; +use uuid::Uuid; + +#[cfg(feature = "secrets")] +use crate::auth::login::{access_token_login, AccessTokenLoginRequest, AccessTokenLoginResponse}; #[cfg(feature = "internal")] use crate::{ auth::login::{ @@ -13,11 +18,6 @@ use crate::{ SecretVerificationRequest, SyncRequest, SyncResponse, UserApiKeyResponse, }, }; -use reqwest::header::{self}; -use uuid::Uuid; - -#[cfg(feature = "secrets")] -use crate::auth::login::{access_token_login, AccessTokenLoginRequest, AccessTokenLoginResponse}; use crate::{ auth::renew::renew_token, client::{ @@ -288,14 +288,9 @@ impl Client { #[cfg(test)] mod tests { - use std::num::NonZeroU32; - use wiremock::{matchers, Mock, ResponseTemplate}; - use crate::{ - auth::login::AccessTokenLoginRequest, client::kdf::Kdf, mobile::crypto::InitCryptoRequest, - secrets_manager::secrets::*, Client, - }; + use crate::{auth::login::AccessTokenLoginRequest, secrets_manager::secrets::*}; #[tokio::test] async fn test_access_token_login() { @@ -384,34 +379,4 @@ mod tests { assert_eq!(res.note, "TEST"); assert_eq!(res.value, "TEST"); } - - #[cfg(feature = "internal")] - #[tokio::test] - async fn test_register_initialize_crypto() { - let mut client = Client::new(None); - - let email = "test@bitwarden.com"; - let password = "test123"; - let kdf = Kdf::PBKDF2 { - iterations: NonZeroU32::new(600_000).unwrap(), - }; - - let register_response = client - .auth() - .make_register_keys(email.to_owned(), password.to_owned(), kdf.clone()) - .unwrap(); - - client - .crypto() - .initialize_crypto(InitCryptoRequest { - kdf_params: kdf, - email: email.to_owned(), - password: password.to_owned(), - user_key: register_response.encrypted_user_key, - private_key: register_response.keys.private.to_string(), - organization_keys: Default::default(), - }) - .await - .unwrap(); - } } diff --git a/crates/bitwarden/tests/register.rs b/crates/bitwarden/tests/register.rs new file mode 100644 index 000000000..d4e632e55 --- /dev/null +++ b/crates/bitwarden/tests/register.rs @@ -0,0 +1,35 @@ +/// Integration test for registering a new user and unlocking the vault +#[cfg(feature = "mobile")] +#[tokio::test] +async fn test_register_initialize_crypto() { + use std::num::NonZeroU32; + + use bitwarden::{client::kdf::Kdf, mobile::crypto::InitCryptoRequest, Client}; + + let mut client = Client::new(None); + + let email = "test@bitwarden.com"; + let password = "test123"; + let kdf = Kdf::PBKDF2 { + iterations: NonZeroU32::new(600_000).unwrap(), + }; + + let register_response = client + .auth() + .make_register_keys(email.to_owned(), password.to_owned(), kdf.clone()) + .unwrap(); + + // Ensure we can initialize the crypto with the new keys + client + .crypto() + .initialize_crypto(InitCryptoRequest { + kdf_params: kdf, + email: email.to_owned(), + password: password.to_owned(), + user_key: register_response.encrypted_user_key, + private_key: register_response.keys.private.to_string(), + organization_keys: Default::default(), + }) + .await + .unwrap(); +}