use crate::{arg_of, args_of, list_values};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct TelnetService {
pub authentication_order: Vec<String>,
pub connection_limit: Option<String>,
pub rate_limit: Option<String>,
}
pub(super) fn parse_telnet(telnet: &ConfigLine) -> TelnetService {
TelnetService {
authentication_order: args_of(telnet, "authentication-order")
.into_iter()
.flat_map(list_values)
.collect(),
connection_limit: arg_of(telnet, "connection-limit").map(str::to_string),
rate_limit: arg_of(telnet, "rate-limit").map(str::to_string),
}
}
#[cfg(test)]
mod tests {
use crate::system::system;
use asterust::config::juniper;
#[test]
fn extracts_telnet_options() {
let telnet = system(&juniper::parse_braces(
"system {\n services {\n telnet {\n authentication-order [ tacplus password ];\n connection-limit 10;\n rate-limit 5;\n }\n }\n}\n",
))
.unwrap()
.services
.unwrap()
.telnet_service
.unwrap();
assert_eq!(telnet.authentication_order, ["tacplus", "password"]);
assert_eq!(telnet.connection_limit.as_deref(), Some("10"));
assert_eq!(telnet.rate_limit.as_deref(), Some("5"));
}
#[test]
fn bare_telnet_has_no_options() {
let services = system(&juniper::parse_braces(
"system {\n services {\n telnet;\n }\n}\n",
))
.unwrap()
.services
.unwrap();
assert!(services.telnet);
assert_eq!(services.telnet_service, Some(Default::default()));
}
}