From 6ef5221c2c7facb950255c48c29bb463821ac41a Mon Sep 17 00:00:00 2001 From: xystrive Date: Thu, 25 Jul 2024 13:21:18 +0100 Subject: [PATCH] feat: add skeleton structure for MFA endpoints tests --- tests/auth.rs | 125 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 120 insertions(+), 5 deletions(-) diff --git a/tests/auth.rs b/tests/auth.rs index c7da756..10f7195 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -2,9 +2,9 @@ // 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/. -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")] use wasm_bindgen_test::*; #[cfg(target_arch = "wasm32")] @@ -85,9 +85,7 @@ async fn test_login_with_token() { .await .unwrap(); assert_eq!( - bundle.user.object.as_ref().unwrap() - .read().unwrap() - .id, + bundle.user.object.as_ref().unwrap().read().unwrap().id, other_user.object.unwrap().read().unwrap().id ); assert_eq!(bundle.user.token, other_user.token); @@ -107,3 +105,120 @@ async fn test_login_with_invalid_token() { 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()) +}