first commit

This commit is contained in:
O K
2026-05-18 11:45:56 +03:00
commit d0156ad51c
20 changed files with 4324 additions and 0 deletions

23
tests/common/mod.rs Normal file
View File

@@ -0,0 +1,23 @@
use std::collections::HashSet;
use server18004::state::AppState;
/// Creates a test AppState with the given allowed domains.
/// Uses a temp directory for the domains file so tests don't interfere.
pub fn test_state(domains: &[&str]) -> AppState {
let domain_set: HashSet<String> = domains.iter().map(|s| s.to_string()).collect();
// Use a temp file for domain persistence during tests
let tmp_dir = tempfile::tempdir().expect("Failed to create temp dir");
let domains_path = tmp_dir
.path()
.join("domains.conf")
.to_str()
.unwrap()
.to_string();
// We need to leak the TempDir so it doesn't get cleaned up during the test
// (the test functions are short-lived, this is fine for testing)
std::mem::forget(tmp_dir);
AppState::new(domain_set, domains_path, "test-default.com".to_string())
}

View File

@@ -0,0 +1,3 @@
GET http://127.0.0.1:4083/domains HTTP/1.1
content-type: application/json