A0: review round 1 peer entry defaults and class strings
This commit is contained in:
1 parent
4bfb097be6
commit
0dbaf58c8c
10 files changed
+276
-32
No files matched your search
@@ -87,15 +87,25 @@ impl fmt::Display for Secret {
|
||||
}
|
||||
}
|
||||
|
||||
fn peer_enabled_default() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// One validated `[[peers.peer]]` entry. The token itself is not held here;
|
||||
/// only the path of the externally managed file.
|
||||
///
|
||||
/// `enabled` defaults to true, `allow_plain_http` to false, and `ca_file`
|
||||
/// may be omitted: entries often carry only `name`, `url` and `token_file`.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PeerConfig {
|
||||
pub name: PeerName,
|
||||
pub url: Url,
|
||||
pub token_file: PathBuf,
|
||||
#[serde(default)]
|
||||
pub ca_file: Option<PathBuf>,
|
||||
#[serde(default)]
|
||||
pub allow_plain_http: bool,
|
||||
#[serde(default = "peer_enabled_default")]
|
||||
pub enabled: bool,
|
||||
}
|
||||
|
||||
@@ -280,6 +290,32 @@ mod tests {
|
||||
assert_eq!(c.tcp_interval_secs, 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn peer_entry_omits_optional_keys() {
|
||||
let c: PeersConfig = toml::from_str(
|
||||
r#"
|
||||
[[peer]]
|
||||
name = "beta"
|
||||
url = "http://beta:1984"
|
||||
token_file = "/run/credentials/skyg-linux-tracker.service/peer-beta"
|
||||
allow_plain_http = true
|
||||
|
||||
[[peer]]
|
||||
name = "delta"
|
||||
url = "https://delta:1984"
|
||||
token_file = "/run/credentials/skyg-linux-tracker.service/peer-delta"
|
||||
enabled = false
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
assert!(c.peer[0].enabled);
|
||||
assert!(c.peer[0].allow_plain_http);
|
||||
assert!(c.peer[0].ca_file.is_none());
|
||||
assert!(!c.peer[1].enabled);
|
||||
assert!(!c.peer[1].allow_plain_http);
|
||||
assert!(c.peer[1].ca_file.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn display_url_drops_normalized_root_path() {
|
||||
assert_eq!(
|
||||
|
||||
Reference in new issue
Block a user