fix #14740: fixed backend url per build, key bound to its server
- the backend URL is no longer a setting: one constant per build (release/dev) in src-tauri/src/backend.rs; Settings shows the server read-only; an old backend_url in settings.json is ignored - the stored key records the backend it was created for; a key of another backend is discarded before any use and never stored - a refused key is discarded only if it still is the stored one - the keyring is never called while the settings are locked - one upload per call at a time, also visible after a view switch - opener plugin without its link-click script (it also ran in the remote login page); a login error says to reload the login page Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+28
-56
@@ -11,8 +11,6 @@ use std::path::Path;
|
||||
use chrono::{DateTime, Local};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::backend;
|
||||
|
||||
/// Executables whose mic use counts as a call (matched case-insensitively).
|
||||
const DEFAULT_ALLOWLIST: [&str; 6] = [
|
||||
"ms-teams.exe",
|
||||
@@ -41,13 +39,14 @@ pub struct Settings {
|
||||
pub autostart: bool,
|
||||
pub start_after_secs: u64,
|
||||
pub end_after_secs: u64,
|
||||
/// The euvino admin backend transcripts are uploaded to.
|
||||
pub backend_url: String,
|
||||
/// Whose backend key is stored (the key itself is in the keyring). Set
|
||||
/// by the app at login, not by the user.
|
||||
pub backend_username: Option<String>,
|
||||
/// When the stored backend key expires. Set by the app at login.
|
||||
pub backend_key_expires_at: Option<DateTime<Local>>,
|
||||
/// The backend the stored key was created for: it is sent to that one
|
||||
/// only. Set by the app at login.
|
||||
pub backend_key_base_url: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
@@ -62,9 +61,9 @@ impl Default for Settings {
|
||||
autostart: true,
|
||||
start_after_secs: 3,
|
||||
end_after_secs: 10,
|
||||
backend_url: backend::DEFAULT_URL.to_string(),
|
||||
backend_username: None,
|
||||
backend_key_expires_at: None,
|
||||
backend_key_base_url: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,28 +85,18 @@ impl Settings {
|
||||
END_AFTER_SECS.end()
|
||||
));
|
||||
}
|
||||
backend::normalize_url(&self.backend_url)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The settings after the user saved `edited` over these: checked, with
|
||||
/// the backend URL normalized and the backend login (which only the app
|
||||
/// changes) kept. If the backend URL changed, the login is cleared and
|
||||
/// `true` returned: the stored key belongs to the old backend and must
|
||||
/// be discarded.
|
||||
pub fn edited(&self, mut edited: Settings) -> Result<(Settings, bool), String> {
|
||||
/// the backend login (which only the app changes) kept, so a settings
|
||||
/// page loaded before a login cannot undo it.
|
||||
pub fn edited(&self, mut edited: Settings) -> Result<Settings, String> {
|
||||
edited.validate()?;
|
||||
edited.backend_url = backend::normalize_url(&edited.backend_url)?;
|
||||
let backend_changed = backend::normalize_url(&self.backend_url)
|
||||
.map_or(true, |current| current != edited.backend_url);
|
||||
if backend_changed {
|
||||
edited.backend_username = None;
|
||||
edited.backend_key_expires_at = None;
|
||||
} else {
|
||||
edited.backend_username = self.backend_username.clone();
|
||||
edited.backend_key_expires_at = self.backend_key_expires_at;
|
||||
}
|
||||
Ok((edited, backend_changed))
|
||||
edited.backend_username = self.backend_username.clone();
|
||||
edited.backend_key_expires_at = self.backend_key_expires_at;
|
||||
edited.backend_key_base_url = self.backend_key_base_url.clone();
|
||||
Ok(edited)
|
||||
}
|
||||
|
||||
/// Reads the settings file. A missing or unreadable file yields the
|
||||
@@ -158,23 +147,26 @@ mod tests {
|
||||
assert!(s.autostart);
|
||||
assert_eq!(s.start_after_secs, 3);
|
||||
assert_eq!(s.end_after_secs, 10);
|
||||
assert_eq!(s.backend_url, "https://test.euvinopro.eu");
|
||||
assert_eq!(s.backend_username, None);
|
||||
assert_eq!(s.backend_key_expires_at, None);
|
||||
assert_eq!(s.backend_key_base_url, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_rejects_a_backend_url_that_is_not_https() {
|
||||
let s = Settings {
|
||||
backend_url: "http://test.euvinopro.eu".into(),
|
||||
..Settings::default()
|
||||
};
|
||||
fn a_backend_url_in_an_older_file_is_ignored() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = dir.path().join("settings.json");
|
||||
fs::write(
|
||||
&path,
|
||||
r#"{"retention_days": 9, "backend_url": "https://other.example"}"#,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
s.validate(),
|
||||
Err(
|
||||
"Backend-URL: bitte eine https-Adresse wie https://test.euvinopro.eu angeben"
|
||||
.to_string()
|
||||
)
|
||||
Settings::load(&path),
|
||||
Settings {
|
||||
retention_days: 9,
|
||||
..Settings::default()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -186,6 +178,7 @@ mod tests {
|
||||
.unwrap()
|
||||
.into(),
|
||||
),
|
||||
backend_key_base_url: Some("https://test.euvinopro.eu".into()),
|
||||
..Settings::default()
|
||||
}
|
||||
}
|
||||
@@ -195,15 +188,14 @@ mod tests {
|
||||
let current = logged_in();
|
||||
let edited = Settings {
|
||||
retention_days: 30,
|
||||
backend_url: "https://test.euvinopro.eu/".into(),
|
||||
backend_username: None,
|
||||
backend_key_expires_at: None,
|
||||
backend_key_base_url: Some("https://elsewhere.example".into()),
|
||||
..Settings::default()
|
||||
};
|
||||
|
||||
let (saved, backend_changed) = current.edited(edited).unwrap();
|
||||
let saved = current.edited(edited).unwrap();
|
||||
|
||||
assert!(!backend_changed);
|
||||
assert_eq!(
|
||||
saved,
|
||||
Settings {
|
||||
@@ -213,28 +205,8 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_edit_of_the_backend_url_ends_the_login() {
|
||||
let edited = Settings {
|
||||
backend_url: " https://other.example/ ".into(),
|
||||
..logged_in()
|
||||
};
|
||||
|
||||
let (saved, backend_changed) = logged_in().edited(edited).unwrap();
|
||||
|
||||
assert!(backend_changed);
|
||||
assert_eq!(saved.backend_url, "https://other.example");
|
||||
assert_eq!(saved.backend_username, None);
|
||||
assert_eq!(saved.backend_key_expires_at, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_invalid_edit_is_refused() {
|
||||
let edited = Settings {
|
||||
backend_url: "test.euvinopro.eu".into(),
|
||||
..Settings::default()
|
||||
};
|
||||
assert!(logged_in().edited(edited).is_err());
|
||||
let edited = Settings {
|
||||
start_after_secs: 0,
|
||||
..Settings::default()
|
||||
|
||||
Reference in New Issue
Block a user