Default missing config fields on upgrade
ci / test (push) Waiting to run
ci / fuzz-smoke (push) Waiting to run
ci / windows-client (push) Waiting to run
ci / package-release (linux-x86_64, ubuntu-latest) (push) Waiting to run
ci / package-release (macos-aarch64, macos-14) (push) Waiting to run
ci / package-release (macos-x86_64, macos-13) (push) Waiting to run
ci / package-release (windows-x86_64, windows-latest) (push) Waiting to run
ci / publish-gitea-release (push) Blocked by required conditions
ci / remote-bench (push) Waiting to run
ci / test (push) Waiting to run
ci / fuzz-smoke (push) Waiting to run
ci / windows-client (push) Waiting to run
ci / package-release (linux-x86_64, ubuntu-latest) (push) Waiting to run
ci / package-release (macos-aarch64, macos-14) (push) Waiting to run
ci / package-release (macos-x86_64, macos-13) (push) Waiting to run
ci / package-release (windows-x86_64, windows-latest) (push) Waiting to run
ci / publish-gitea-release (push) Blocked by required conditions
ci / remote-bench (push) Waiting to run
This commit is contained in:
@@ -5,6 +5,7 @@ use std::fs;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(default)]
|
||||||
pub struct ServerConfig {
|
pub struct ServerConfig {
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
pub bind: String,
|
pub bind: String,
|
||||||
@@ -95,6 +96,7 @@ impl Default for ServerConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(default)]
|
||||||
pub struct ClientConfig {
|
pub struct ClientConfig {
|
||||||
pub update_repo: Option<String>,
|
pub update_repo: Option<String>,
|
||||||
pub update_port: Option<u16>,
|
pub update_port: Option<u16>,
|
||||||
@@ -330,3 +332,63 @@ pub fn expand_tilde(path: &str) -> PathBuf {
|
|||||||
}
|
}
|
||||||
PathBuf::from(path)
|
PathBuf::from(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::{ClientConfig, ServerConfig};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn old_client_configs_fill_new_fields_from_defaults() {
|
||||||
|
let raw = r#"
|
||||||
|
server = "palav"
|
||||||
|
dosh_port = 50000
|
||||||
|
"#;
|
||||||
|
|
||||||
|
let config: ClientConfig = toml::from_str(raw).expect("parse old client config");
|
||||||
|
|
||||||
|
assert_eq!(config.server, "palav");
|
||||||
|
assert!(config.predict);
|
||||||
|
assert_eq!(config.predict_mode, "experimental");
|
||||||
|
assert_eq!(config.auth_preference, "native,ssh");
|
||||||
|
assert_eq!(config.native_auth_timeout_ms, 700);
|
||||||
|
assert_eq!(config.known_hosts, "~/.config/dosh/known_hosts");
|
||||||
|
assert_eq!(config.identity_files, vec!["~/.ssh/id_ed25519"]);
|
||||||
|
assert!(config.use_ssh_agent);
|
||||||
|
assert!(!config.forward_agent);
|
||||||
|
assert!(config.disconnect_status);
|
||||||
|
assert_eq!(config.escape_key, "^]");
|
||||||
|
assert!(config.send_env.iter().any(|value| value == "TERM"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn old_server_configs_fill_new_fields_from_defaults() {
|
||||||
|
let raw = r#"
|
||||||
|
port = 50000
|
||||||
|
"#;
|
||||||
|
|
||||||
|
let config: ServerConfig = toml::from_str(raw).expect("parse old server config");
|
||||||
|
|
||||||
|
assert_eq!(config.port, 50000);
|
||||||
|
assert_eq!(config.bind, "0.0.0.0");
|
||||||
|
assert_eq!(config.client_timeout_secs, 2_592_000);
|
||||||
|
assert_eq!(config.output_frame_interval_ms, 16);
|
||||||
|
assert!(config.native_auth);
|
||||||
|
assert_eq!(config.host_key, "~/.config/dosh/host_key");
|
||||||
|
assert!(
|
||||||
|
config
|
||||||
|
.authorized_keys
|
||||||
|
.iter()
|
||||||
|
.any(|path| path == "~/.ssh/authorized_keys")
|
||||||
|
);
|
||||||
|
assert_eq!(config.native_auth_rate_limit_per_minute, 30);
|
||||||
|
assert_eq!(config.rekey_after_packets, 100_000);
|
||||||
|
assert_eq!(config.rekey_after_secs, 3600);
|
||||||
|
assert!(config.allow_tcp_forwarding);
|
||||||
|
assert!(!config.allow_remote_forwarding);
|
||||||
|
assert!(!config.allow_agent_forwarding);
|
||||||
|
assert!(config.allow_file_transfer);
|
||||||
|
assert!(config.allow_exec_command);
|
||||||
|
assert!(config.persist_sessions);
|
||||||
|
assert!(config.accept_env.iter().any(|value| value == "TERM"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user