Skip to content

Commit

Permalink
Add test confirming the whole approve device flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed Jan 31, 2024
1 parent 302c832 commit df1b2c6
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion crates/bitwarden/src/auth/auth_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ mod tests {
use bitwarden_crypto::Kdf;

use super::*;
use crate::client::{LoginMethod, UserLoginMethod};
use crate::{
client::{LoginMethod, UserLoginMethod},
mobile::crypto::{InitUserCryptoMethod, InitUserCryptoRequest},
};

#[test]
fn test_approve() {
Expand Down Expand Up @@ -139,4 +142,60 @@ mod tests {

approve_auth_request(&mut client, public_key.to_owned()).unwrap();
}

#[tokio::test]
async fn test_device_login() {
let mut approving_client = Client::new(None);
approving_client.set_login_method(LoginMethod::User(UserLoginMethod::Username {
client_id: "123".to_owned(),
email: "[email protected]".to_owned(),
kdf: Kdf::PBKDF2 {
iterations: NonZeroU32::new(600_000).unwrap(),
},
}));

let user_key = "2.Q/2PhzcC7GdeiMHhWguYAQ==|GpqzVdr0go0ug5cZh1n+uixeBC3oC90CIe0hd/HWA/pTRDZ8ane4fmsEIcuc8eMKUt55Y2q/fbNzsYu41YTZzzsJUSeqVjT8/iTQtgnNdpo=|dwI+uyvZ1h/iZ03VQ+/wrGEFYVewBUUl/syYgjsNMbE=".parse().unwrap();
let private_key = "2.yN7l00BOlUE0Sb0M//Q53w==|EwKG/BduQRQ33Izqc/ogoBROIoI5dmgrxSo82sgzgAMIBt3A2FZ9vPRMY+GWT85JiqytDitGR3TqwnFUBhKUpRRAq4x7rA6A1arHrFp5Tp1p21O3SfjtvB3quiOKbqWk6ZaU1Np9HwqwAecddFcB0YyBEiRX3VwF2pgpAdiPbSMuvo2qIgyob0CUoC/h4Bz1be7Qa7B0Xw9/fMKkB1LpOm925lzqosyMQM62YpMGkjMsbZz0uPopu32fxzDWSPr+kekNNyLt9InGhTpxLmq1go/pXR2uw5df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WRrF8ftrI6xQnFjHBGWD/JWSvd6YMcQED0aVuQkuNW9ST/DzQThPzRfPUoiL10yAmV7Ytu4fR3x2sF0Yfi87YhHFuCMpV/DsqxmUizyiJuD938eRcH8hzR/VO53Qo3UIsqOLcyXtTv6THjSlTopQ+JOLOnHm1w8dzYbLN44OG44rRsbihMUQp+wUZ6bsI8rrOnm9WErzkbQFbrfAINdoCiNa6cimYIjvvnMTaFWNymqY1vZxGztQiMiHiHYwTfwHTXrb9j0uPM=|09J28iXv9oWzYtzK2LBT6Yht4IT4MijEkk0fwFdrVQ4=";

approving_client
.initialize_user_crypto("asdfasdfasdf", user_key, private_key.parse().unwrap())
.unwrap();

let mut requesting_client = Client::new(None);
let auth_req = new_auth_request("[email protected]").unwrap();

let approved_req =
approve_auth_request(&mut approving_client, auth_req.public_key).unwrap();

requesting_client
.crypto()
.initialize_user_crypto(InitUserCryptoRequest {
kdf_params: Kdf::PBKDF2 {
iterations: NonZeroU32::new(600_000).unwrap(),
},
email: "[email protected]".to_owned(),
private_key: private_key.to_owned(),
method: InitUserCryptoMethod::AuthRequest {
request_private_key: auth_req.private_key,
protected_user_key: approved_req,
},
})
.await

Check warning on line 183 in crates/bitwarden/src/auth/auth_request.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/auth/auth_request.rs#L183

Added line #L183 was not covered by tests
.unwrap();

assert_eq!(
approving_client
.get_encryption_settings()
.unwrap()
.get_key(&None)
.unwrap()
.to_base64(),
requesting_client
.get_encryption_settings()
.unwrap()
.get_key(&None)
.unwrap()
.to_base64()
);
}
}

0 comments on commit df1b2c6

Please sign in to comment.