feat: add skeleton structure for MFA endpoints tests

This commit is contained in:
xystrive 2024-07-25 13:21:18 +01:00
parent cd637fbb6b
commit 6ef5221c2c
No known key found for this signature in database
GPG Key ID: 5EC5BBA34DEE94B7
1 changed files with 120 additions and 5 deletions

View File

@ -2,9 +2,9 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this // License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::str::FromStr; use std::{os::unix::fs::chroot, str::FromStr};
use chorus::types::{LoginSchema, RegisterSchema}; use chorus::{instance::ChorusUser, types::{AuthenticatorType, LoginSchema, MfaVerifySchema, RegisterSchema, SendMfaSmsSchema}};
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*; use wasm_bindgen_test::*;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
@ -85,9 +85,7 @@ async fn test_login_with_token() {
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
bundle.user.object.as_ref().unwrap() bundle.user.object.as_ref().unwrap().read().unwrap().id,
.read().unwrap()
.id,
other_user.object.unwrap().read().unwrap().id other_user.object.unwrap().read().unwrap().id
); );
assert_eq!(bundle.user.token, other_user.token); assert_eq!(bundle.user.token, other_user.token);
@ -107,3 +105,120 @@ async fn test_login_with_invalid_token() {
common::teardown(bundle).await; common::teardown(bundle).await;
} }
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn test_complete_mfa_challenge_totp() {
let mut bundle = common::setup().await;
let token = "".to_string();
let mut chorus_user = bundle.instance.login_with_token(token).await
.unwrap();
let schema = MfaVerifySchema {
ticket: "".to_string(),
mfa_type: AuthenticatorType::TOTP,
data: "".to_string(),
};
let result = chorus_user.complete_mfa_challenge(schema)
.await;
assert!(result.is_ok())
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn test_complete_mfa_challenge_sms() {
let mut bundle = common::setup().await;
let token = "".to_string();
let mut chorus_user = bundle.instance.login_with_token(token).await
.unwrap();
let schema = MfaVerifySchema {
ticket: "".to_string(),
mfa_type: AuthenticatorType::SMS,
data: "".to_string(),
};
let result = chorus_user.complete_mfa_challenge(schema)
.await;
assert!(result.is_ok())
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn test_verify_mfa_login_webauthn() {
let mut bundle = common::setup().await;
let token = "".to_string();
let mut chorus_user = bundle.instance.login_with_token(token).await
.unwrap();
let schema = MfaVerifySchema {
ticket: "".to_string(),
mfa_type: AuthenticatorType::SMS,
data: "".to_string(),
};
let result = chorus_user.complete_mfa_challenge(schema)
.await;
assert!(result.is_ok())
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn test_complete_mfa_challenge_backup() {
let mut bundle = common::setup().await;
let token = "".to_string();
let mut chorus_user = bundle.instance.login_with_token(token).await
.unwrap();
let schema = MfaVerifySchema {
ticket: "".to_string(),
mfa_type: AuthenticatorType::Backup,
data: "".to_string(),
};
let result = chorus_user.complete_mfa_challenge(schema)
.await;
assert!(result.is_ok())
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn test_complete_mfa_challenge_password() {
let mut bundle = common::setup().await;
let token = "".to_string();
let mut chorus_user = bundle.instance.login_with_token(token).await
.unwrap();
let schema = MfaVerifySchema {
ticket: "".to_string(),
mfa_type: AuthenticatorType::Password,
data: "".to_string(),
};
let result = chorus_user.complete_mfa_challenge(schema)
.await;
assert!(result.is_ok())
}
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn test_send_mfa_sms() {
let mut bundle = common::setup().await;
let schema = SendMfaSmsSchema { ticket: "".to_string() };
let result = bundle.instance.send_mfa_sms(schema).await;
assert!(result.is_ok())
}