0ef9109876
Introduce a new struct `WhisperUserSettings` to hold per-user transcription settings. This allows users to customize Whisper transcription for their specific needs directly in the `users.toml` configuration file. The changes include: - Defining `WhisperUserSettings` with optional fields for `language`, `hotwords`, and `initial_prompt`. - Integrating `WhisperUserSettings` into the `User` struct, with `#[serde(default)]` to ensure it defaults to `WhisperUserSettings::default()` if not present in the TOML. - Adding new unit tests to verify that users can be parsed correctly with and without a `[user.whisper]` block. - Updating existing tests in `auth_test.rs`, `upload_test.rs`, and `web_test.rs` to include the new `whisper` field, ensuring backward compatibility.
101 lines
2.7 KiB
Rust
101 lines
2.7 KiB
Rust
use std::collections::HashMap;
|
|
use std::sync::Arc;
|
|
|
|
use axum::body::Body;
|
|
use axum::http::{Request, StatusCode};
|
|
use tower::util::ServiceExt;
|
|
|
|
use doctate_server::config::{Config, User};
|
|
|
|
fn test_config() -> Arc<Config> {
|
|
Arc::new(Config {
|
|
server_port: 3000,
|
|
data_path: "/tmp/doctate-test".into(),
|
|
log_level: "info".into(),
|
|
log_path: "/tmp/doctate-test/logs".into(),
|
|
log_max_days: 90,
|
|
users: vec![User {
|
|
slug: "dr_test".into(),
|
|
api_key: "test-key-123".into(),
|
|
web_password: "unused".into(),
|
|
role: "doctor".into(),
|
|
whisper: Default::default(),
|
|
}],
|
|
api_keys: HashMap::from([("test-key-123".into(), "dr_test".into())]),
|
|
retention_audio_days: 30,
|
|
retention_transcript_days: 30,
|
|
retention_document_days: 0,
|
|
whisper_url: "http://localhost:10300".into(),
|
|
whisper_timeout_seconds: 120,
|
|
ollama_url: "http://localhost:11434".into(),
|
|
ollama_model: "gemma3:4b".into(),
|
|
ollama_keep_alive: 0,
|
|
llm_url: String::new(),
|
|
llm_api_key: String::new(),
|
|
llm_model: String::new(),
|
|
llm_temperature: 0.0,
|
|
session_timeout_hours: 8,
|
|
})
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn valid_api_key_returns_user() {
|
|
let app = doctate_server::create_router(test_config());
|
|
|
|
let response = app
|
|
.oneshot(
|
|
Request::builder()
|
|
.uri("/api/debug/whoami")
|
|
.header("X-API-Key", "test-key-123")
|
|
.body(Body::empty())
|
|
.unwrap(),
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
assert_eq!(response.status(), StatusCode::OK);
|
|
|
|
let body = axum::body::to_bytes(response.into_body(), usize::MAX)
|
|
.await
|
|
.unwrap();
|
|
let json: serde_json::Value = serde_json::from_slice(&body).unwrap();
|
|
|
|
assert_eq!(json["slug"], "dr_test");
|
|
assert_eq!(json["role"], "doctor");
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn invalid_api_key_returns_401() {
|
|
let app = doctate_server::create_router(test_config());
|
|
|
|
let response = app
|
|
.oneshot(
|
|
Request::builder()
|
|
.uri("/api/debug/whoami")
|
|
.header("X-API-Key", "wrong-key")
|
|
.body(Body::empty())
|
|
.unwrap(),
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn missing_api_key_returns_401() {
|
|
let app = doctate_server::create_router(test_config());
|
|
|
|
let response = app
|
|
.oneshot(
|
|
Request::builder()
|
|
.uri("/api/debug/whoami")
|
|
.body(Body::empty())
|
|
.unwrap(),
|
|
)
|
|
.await
|
|
.unwrap();
|
|
|
|
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
|
|
}
|