From a2ef3f6ec4c830611fde1a2e935588ccbbc61c03 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 30 Apr 2025 10:47:54 +0200 Subject: config works --- logic/src/session.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'logic/src/session.rs') diff --git a/logic/src/session.rs b/logic/src/session.rs index bc7f137..72a1089 100644 --- a/logic/src/session.rs +++ b/logic/src/session.rs @@ -3,13 +3,13 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2025 metamuffin */ +use crate::CONF; use aes_gcm_siv::{ KeyInit, aead::{Aead, generic_array::GenericArray}, }; use anyhow::anyhow; use base64::Engine; -use jellybase::SECRETS; use jellycommon::{ chrono::{DateTime, Utc}, user::{PermissionSet, User}, @@ -32,7 +32,7 @@ pub struct SessionData { } static SESSION_KEY: LazyLock<[u8; 32]> = LazyLock::new(|| { - if let Some(sk) = &SECRETS.session_key { + if let Some(sk) = &CONF.session_key { let r = base64::engine::general_purpose::STANDARD .decode(sk) .expect("key invalid; should be valid base64"); @@ -85,9 +85,20 @@ pub fn validate(token: &str) -> anyhow::Result { Ok(session_data.username) } +#[cfg(test)] +fn load_test_config() { + use crate::{CONF_PRELOAD, Config}; + *CONF_PRELOAD.lock().unwrap() = Some(Config { + login_expire: 10, + session_key: None, + admin_password: None, + admin_username: None, + }); +} + #[test] fn test() { - jellybase::use_test_config(); + load_test_config(); let tok = create( "blub".to_string(), jellycommon::user::PermissionSet::default(), @@ -98,7 +109,7 @@ fn test() { #[test] fn test_crypto() { - jellybase::use_test_config(); + load_test_config(); let nonce = [(); 12].map(|_| rand::random()); let cipher = aes_gcm_siv::Aes256GcmSiv::new_from_slice(&*SESSION_KEY).unwrap(); let plaintext = b"testing stuff---"; -- cgit v1.2.3-70-g09d2