Skip to content

Commit

Permalink
fix rust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
“Giems” committed Jun 26, 2024
1 parent 4d945e3 commit 08e3895
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub async fn register_with_passkey_start(
};

// Generate verification code, if not in production use a static code
let code = if !is_test_env() {
let code = if is_test_env() {
"123456".to_string()
} else {
generate_verification_code()
Expand Down
14 changes: 7 additions & 7 deletions server/src/http/cloud/register/register_with_password_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub async fn register_with_password_start(
sessions_cache.remove(&sessions_key);

// Generate verification code, if not in production use a static code
let code = if !is_test_env() {
let code = if is_test_env() {
"123456".to_string()
} else {
generate_verification_code()
Expand All @@ -84,13 +84,13 @@ pub async fn register_with_password_start(
None,
);

// Send code via email
let request = SendEmailRequest::EmailConfirmation(EmailConfirmationRequest {
email: request.email,
code: code,
});

if !is_test_env() {
// Send code via email
let request = SendEmailRequest::EmailConfirmation(EmailConfirmationRequest {
email: request.email,
code: code,
});

println!("SENDING MAIL");
if let Some(err) = mailer.handle_email_request(&request).error_message {
error!("Failed to send email: {:?}, request: {:?}", err, request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub async fn reset_passkey_start(
};

// Generate verification code, if not in production use a static code
let code = if !is_test_env() {
let code = if is_test_env() {
"123456".to_string()
} else {
generate_verification_code()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub async fn reset_password_start(
sessions_cache.remove(&sessions_key);

// Generate verification code, if not in production use a static code
let code = if !is_test_env() {
let code = if is_test_env() {
"123456".to_string()
} else {
generate_verification_code()
Expand Down
2 changes: 1 addition & 1 deletion server/src/http/cloud/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub fn check_auth_code(
encrypted_auth_code: &Option<String>,
created_at: u64,
) -> bool {
if !is_test_env() {
if is_test_env() {
if encrypted_auth_code.is_none() {
println!("Encrypted auth code is missing");
}
Expand Down
21 changes: 21 additions & 0 deletions server/src/test_env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::sync::atomic::{AtomicBool, Ordering};

static IS_TEST_ENV: AtomicBool = AtomicBool::new(false);

pub fn is_test_env() -> bool {
IS_TEST_ENV.load(Ordering::Relaxed)
}

#[cfg(test)]
pub mod test_detection {
use super::IS_TEST_ENV;
use std::sync::{atomic::Ordering, Once};

static INIT: Once = Once::new();

pub fn setup() {
INIT.call_once(|| {
IS_TEST_ENV.store(true, Ordering::Relaxed);
});
}
}

0 comments on commit 08e3895

Please sign in to comment.