From 7dfe3074a0eb984d16b17c7b0f105d82683d156a Mon Sep 17 00:00:00 2001 From: Jonas Fassbender Date: Sun, 19 Feb 2023 07:12:36 +0100 Subject: [PATCH] auth/simple-auth-server: fix panic due to default `SECRET_KEY` being 32 bytes, not 64 bytes (#604) --- auth/simple-auth-server/src/utils.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/auth/simple-auth-server/src/utils.rs b/auth/simple-auth-server/src/utils.rs index 07cc025..86809ee 100644 --- a/auth/simple-auth-server/src/utils.rs +++ b/auth/simple-auth-server/src/utils.rs @@ -4,7 +4,7 @@ use once_cell::sync::Lazy; use crate::errors::ServiceError; pub static SECRET_KEY: Lazy = - Lazy::new(|| std::env::var("SECRET_KEY").unwrap_or_else(|_| "0123".repeat(8))); + Lazy::new(|| std::env::var("SECRET_KEY").unwrap_or_else(|_| "0123".repeat(16))); const SALT: &[u8] = b"supersecuresalt"; @@ -28,3 +28,19 @@ pub fn verify(hash: &str, password: &str) -> Result { }, ) } + +#[cfg(test)] +mod tests { + use std::env; + + use actix_web::cookie::Key; + + use super::SECRET_KEY; + + #[test] + fn secret_key_default() { + env::remove_var("SECRET_KEY"); + + assert!(Key::try_from(SECRET_KEY.as_bytes()).is_ok()); + } +}