pub const API_SMBCLOUD_XYZ: &str =
"api.smbcloud.xyz ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINGy4LHGyOilS7SXo770V3tQnXDRVQr7X7JsPLCfy4XB";
pub const API_1_SMBCLOUD_XYZ: &str =
"api-1.smbcloud.xyz ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAII1G3JyS66+yIFGrN3Vgc/UlvBm/oS98qq5pS96UYxcz";
pub fn for_host(rsync_host: &str) -> &'static str {
if rsync_host.starts_with("api-1.") {
API_1_SMBCLOUD_XYZ
} else {
API_SMBCLOUD_XYZ
}
}
pub fn is_pinned_host(host: &str) -> bool {
matches!(host, "api.smbcloud.xyz" | "api-1.smbcloud.xyz")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn api_host_returns_correct_key() {
let key = for_host("api.smbcloud.xyz");
assert!(key.starts_with("api.smbcloud.xyz ssh-ed25519 "));
assert!(!key.contains("api-1"));
}
#[test]
fn api_1_host_returns_correct_key() {
let key = for_host("api-1.smbcloud.xyz");
assert!(key.starts_with("api-1.smbcloud.xyz ssh-ed25519 "));
}
#[test]
fn keys_are_distinct() {
assert_ne!(API_SMBCLOUD_XYZ, API_1_SMBCLOUD_XYZ);
}
#[test]
fn keys_contain_valid_ed25519_prefix() {
assert!(API_SMBCLOUD_XYZ.contains("AAAA"));
assert!(API_1_SMBCLOUD_XYZ.contains("AAAA"));
}
#[test]
fn rejects_unpinned_hosts() {
assert!(is_pinned_host("api.smbcloud.xyz"));
assert!(is_pinned_host("api-1.smbcloud.xyz"));
assert!(!is_pinned_host("example.com"));
}
}