aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--base/src/lib.rs31
-rw-r--r--common/src/config.rs2
-rw-r--r--server/src/routes/ui/account/session/token.rs2
3 files changed, 27 insertions, 8 deletions
diff --git a/base/src/lib.rs b/base/src/lib.rs
index b90934e..385ad7a 100644
--- a/base/src/lib.rs
+++ b/base/src/lib.rs
@@ -11,11 +11,25 @@ pub mod federation;
pub mod permission;
use jellycommon::config::{GlobalConfig, SecretsConfig};
-use std::{fs::File, sync::LazyLock};
+use std::sync::{
+ atomic::{AtomicBool, Ordering},
+ LazyLock,
+};
-pub static CONF: LazyLock<GlobalConfig> = LazyLock::new(|| {
+pub static CONF: LazyLock<GlobalConfig> = LazyLock::new(load_config);
+pub static SECRETS: LazyLock<SecretsConfig> = LazyLock::new(load_secrets);
+pub static USE_TEST: AtomicBool = AtomicBool::new(false);
+
+pub fn use_test_config() {
+ USE_TEST.store(true, Ordering::Relaxed)
+}
+
+pub fn load_config() -> GlobalConfig {
+ if USE_TEST.load(Ordering::Relaxed) {
+ return GlobalConfig::default();
+ }
serde_yaml::from_reader(
- File::open(std::env::var("JELLYTHING_CONFIG").unwrap_or_else(|_| {
+ std::fs::File::open(std::env::var("JELLYTHING_CONFIG").unwrap_or_else(|_| {
if std::env::args()
.nth(0)
.unwrap_or_default()
@@ -31,8 +45,11 @@ pub static CONF: LazyLock<GlobalConfig> = LazyLock::new(|| {
.expect("config cannot be read"),
)
.expect("config invalid")
-});
-pub static SECRETS: LazyLock<SecretsConfig> = LazyLock::new(|| {
- serde_yaml::from_reader(File::open(&CONF.secrets_path).expect("secrets file missing"))
+}
+fn load_secrets() -> SecretsConfig {
+ if USE_TEST.load(Ordering::Relaxed) {
+ return SecretsConfig::default();
+ }
+ serde_yaml::from_reader(std::fs::File::open(&CONF.secrets_path).expect("secrets file missing"))
.expect("secrets config invalid")
-});
+}
diff --git a/common/src/config.rs b/common/src/config.rs
index 6dd5b68..9aeefe6 100644
--- a/common/src/config.rs
+++ b/common/src/config.rs
@@ -30,7 +30,7 @@ pub struct GlobalConfig {
#[serde(default)] pub default_permission_set: PermissionSet,
}
-#[derive(Serialize, Deserialize, Debug)]
+#[derive(Serialize, Deserialize, Debug, Default)]
pub struct SecretsConfig {
#[serde(default)]
pub federation: HashMap<String, FederationAccount>,
diff --git a/server/src/routes/ui/account/session/token.rs b/server/src/routes/ui/account/session/token.rs
index e40772a..1d191ec 100644
--- a/server/src/routes/ui/account/session/token.rs
+++ b/server/src/routes/ui/account/session/token.rs
@@ -72,6 +72,7 @@ pub fn validate(token: &str) -> anyhow::Result<String> {
#[test]
fn test() {
+ jellybase::use_test_config();
let tok = create(
"blub".to_string(),
jellycommon::user::PermissionSet::default(),
@@ -82,6 +83,7 @@ fn test() {
#[test]
fn test_crypto() {
+ jellybase::use_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---";