1
0
mirror of https://github.com/actix/examples synced 2024-11-27 16:02:57 +01:00

auth/simple-auth-server: fix panic due to default SECRET_KEY being 32 bytes, not 64 bytes (#604)

This commit is contained in:
Jonas Fassbender 2023-02-19 07:12:36 +01:00 committed by GitHub
parent 2df944c5e5
commit 7dfe3074a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,7 +4,7 @@ use once_cell::sync::Lazy;
use crate::errors::ServiceError;
pub static SECRET_KEY: Lazy<String> =
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<bool, ServiceError> {
},
)
}
#[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());
}
}