Skip to content

Commit

Permalink
Move test to integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed Oct 31, 2023
1 parent 77d0f75 commit ff3ff60
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
47 changes: 6 additions & 41 deletions crates/bitwarden/src/client/client.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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::{
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 = "[email protected]";
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();
}
}
35 changes: 35 additions & 0 deletions crates/bitwarden/tests/register.rs
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]";
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();
}

0 comments on commit ff3ff60

Please sign in to comment.