diff options
Diffstat (limited to 'logic/src/session.rs')
-rw-r--r-- | logic/src/session.rs | 19 |
1 files changed, 15 insertions, 4 deletions
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 <metamuffin.org> */ +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<String> { 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---"; |