mod access_line;
mod accounting;
mod archival;
mod arp;
mod authentication_secret;
mod auto_sw_sync;
mod autoinstallation;
mod backup_router;
mod commit;
mod configuration;
mod configuration_database;
mod ddos_protection;
mod demux_options;
mod dynamic_profile_options;
mod export_format;
mod extensions;
mod fib_streaming;
mod health_monitor;
mod icmp;
mod internet_options;
mod kernel_replication;
mod license;
mod location;
mod login;
mod management_traffic;
mod master_password;
mod monitor;
mod name_server;
mod ntp;
mod packet_forwarding_options;
mod password_options;
mod pixel_tracing;
mod ports;
mod processes;
mod proxy;
mod radius_options;
mod radius_server;
mod resiliency;
mod root_authentication;
mod schema;
mod scripts;
mod services;
mod snapshot;
mod static_host_mapping;
mod syslog;
mod tacplus_options;
mod tacplus_server;
mod tracing;
pub use access_line::{AccessLine, AccessLineAdjustment};
pub use accounting::{Accounting, AccountingDestination};
pub use archival::{Archival, ArchivalConfiguration};
pub use arp::{Arp, ArpInterface};
pub use authentication_secret::AuthenticationSecret;
pub use auto_sw_sync::AutoSwSync;
pub use autoinstallation::{Autoinstallation, AutoinstallationInterface};
pub use backup_router::BackupRouter;
pub use commit::{Commit, CommitPeer, CommitServer};
pub use configuration::ConfigurationInput;
pub use configuration_database::{
ConfigurationDatabase, DatabaseResize, EphemeralDatabase, EphemeralInstance, VirtualMemoryProcess,
};
pub use ddos_protection::{DdosFlowLevels, DdosFpc, DdosGlobal, DdosPacketType, DdosProtection, DdosProtocolGroup};
pub use demux_options::DemuxOptions;
pub use dynamic_profile_options::DynamicProfileOptions;
pub use export_format::ExportFormat;
pub use extensions::{ExtensionApplication, ExtensionProvider, Extensions, ProviderLicense};
pub use fib_streaming::{FibStreaming, FibStreamingTable};
pub use health_monitor::HealthMonitor;
pub use icmp::Icmp;
pub use internet_options::{IcmpRateLimit, InternetOptions};
pub use kernel_replication::KernelReplication;
pub use license::{License, LicenseAutoupdate, LicenseRenew};
pub use location::Location;
pub use login::{Login, LoginClass, LoginPassword, LoginRetryOptions, LoginUser};
pub use management_traffic::ManagementTrafficProtocol;
pub use master_password::MasterPassword;
pub use monitor::{
MemoryMonitor, Monitor, ProcessMemoryEvent, ProcessMemoryMonitor, ProcessMemoryThreshold, SystemMemoryEvent,
SystemMemoryMonitor,
};
pub use name_server::NameServer;
pub use ntp::{Ntp, NtpAuthenticationKey, NtpBroadcast, NtpHost, NtpHostNts, NtpNts, NtpRestriction, NtpThreshold};
pub use packet_forwarding_options::{
HwMonitorProfile, HwResourceList, HwResourceMonitor, PacketForwardingOptions, PfeFirewall, PfeSystemProfile,
RecycleBandwidthProfile,
};
pub use password_options::PasswordOptions;
pub use pixel_tracing::PixelTracing;
pub use ports::{Auxiliary, Console, Ports};
pub use processes::{DhcpSessionLog, Process, SnoopingFile};
pub use proxy::Proxy;
pub use radius_options::RadiusOptions;
pub use radius_server::RadiusServer;
pub use resiliency::{Resiliency, ResiliencyFile, ResiliencyStore};
pub use root_authentication::RootAuthentication;
pub use schema::Schema;
pub use scripts::{ScriptArgument, ScriptDampen, ScriptFile, ScriptKind, ScriptOid, Scripts};
pub use services::{
AaclStatisticsProfile, ConnectionLimits, DhcpActiveLeasequery, DhcpActiveLeasequeryLimits, DhcpAuthentication,
DhcpBfd, DhcpBulkLeasequery, DhcpClassificationKey, DhcpDelay, DhcpDualStackGroup, DhcpDynamicProfile,
DhcpDynamicServerGroup, DhcpDynamicServerInterface, DhcpFingerprintServer, DhcpFingerprintServerGroup,
DhcpGroupInterface, DhcpInterfaceTag, DhcpLeaseTimeValidation, DhcpLivenessDetection, DhcpLocalServer,
DhcpLocalServerGroup, DhcpMatch, DhcpOptions, DhcpOverrides, DhcpPool, DhcpReconfigure, DhcpServer,
DhcpServerSettings, DhcpShortCycleProtection, DhcpStaticBinding, DhcpUsernameInclude, Dns, DnsCacheEntry,
DnsDomain, DnsProxy, DnsView, Dnssec, DynamicDnsClient, ExtensibleSubscriberServices, ExtensionService,
ExternalManagement, FlowTapDtcp, FlowTapDtcpSsh, FpcLimit, FtpService, GrpcService, GrpcSsl, GrpcTunnel,
GrpcTunnelServer, HttpServer, HttpServerTls, InbandZtp, InlineNaptPool, Jeb, JebTls, JetNotification,
JtreeResourceType, LocalPolicyDecisionFunction, Netconf, NetconfClientIdentity, NetconfDefaultClientIdentity,
NetconfHelloMessage, NetconfMonitoring, NetconfSsh, NetconfTls, NetconfYangModules, OutboundHttpsAddress,
OutboundHttpsClient, OutboundSshClient, OutboundSshServer, OverrideFamily, PicLimit, PortLimit,
RedundancyInterface, RemoteDeviceNetconf, ResourceMonitor, Rest, RestHttp, RestHttps, Reverse, ServiceDeployment,
ServiceDeploymentServer, ServiceDevice, Services, Shmlog, SshModuli, SshService, StaticSubscriberGroup,
StaticSubscriberProfile, StaticSubscriberUsername, StaticSubscribers, SubscriberLimit, SubscriberManagement,
SubscriberOverrides, SubscriberRedundancy, TcpForwardingEntry, TelnetService, WebManagement, WebManagementHttp,
WebManagementHttps, WebManagementVirtualDomain, Webapi, WebapiHttps, WebapiUser, XnmClearText, XnmSsl,
};
pub use snapshot::{Snapshot, SnapshotRecovery};
pub use static_host_mapping::StaticHostMapping;
pub use syslog::{
GrpcReplay, Syslog, SyslogArchive, SyslogHost, SyslogRule, SyslogStructuredData, SyslogTarget, SyslogTlsDetails,
};
pub use tacplus_options::TacplusOptions;
pub use tacplus_server::TacplusServer;
pub use tracing::Tracing;
use crate::protocols::traceoptions::{parse_traceoptions, Traceoptions};
use crate::{
active_children, arg_of, args_of, child_block, has_leaf, list_values, split_name, toggle, top_level, unquote,
};
use access_line::parse_access_line;
use accounting::parse_accounting;
use archival::parse_archival;
use arp::parse_arp;
use asterust::config::{Config, ConfigLine};
use authentication_secret::password_secrets;
use auto_sw_sync::auto_sw_sync;
use autoinstallation::parse_autoinstallation;
use backup_router::parse_backup_router;
use commit::parse_commit;
use configuration::parse_configuration;
use configuration_database::parse_configuration_database;
use ddos_protection::parse_ddos_protection;
use demux_options::parse_demux_options;
use dynamic_profile_options::parse_dynamic_profile_options;
use export_format::parse_export_format;
use extensions::parse_extensions;
use fib_streaming::parse_fib_streaming;
use health_monitor::parse_health_monitor;
use icmp::parse_icmp;
use internet_options::parse_internet_options;
use kernel_replication::parse_kernel_replication;
use license::parse_license;
use location::parse_location;
use login::parse_login;
use management_traffic::management_traffic;
use master_password::parse_master_password;
use monitor::parse_monitor;
use name_server::name_servers;
use ntp::parse_ntp;
use packet_forwarding_options::parse_packet_forwarding_options;
use password_options::parse_password_options;
use pixel_tracing::parse_pixel_tracing;
use ports::parse_ports;
use processes::parse_processes;
use proxy::parse_proxy;
use radius_options::parse_radius_options;
use radius_server::radius_servers;
use resiliency::parse_resiliency;
use root_authentication::root_authentication;
use schema::parse_schema;
use scripts::parse_scripts;
use services::parse_services;
use snapshot::parse_snapshot;
use static_host_mapping::static_host_mappings;
use syslog::parse_syslog;
use tacplus_options::parse_tacplus_options;
use tacplus_server::tacplus_servers;
use tracing::parse_tracing;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct System {
pub host_name: Option<String>,
pub domain_name: Option<String>,
pub time_zone: Option<String>,
pub domain_search: Vec<String>,
pub static_host_mappings: Vec<StaticHostMapping>,
pub backup_router: Option<BackupRouter>,
pub inet6_backup_router: Option<BackupRouter>,
pub authentication_order: Vec<String>,
pub radius_servers: Vec<RadiusServer>,
pub tacplus_servers: Vec<TacplusServer>,
pub location: Option<Location>,
pub ports: Option<Ports>,
pub max_configurations_on_flash: Option<String>,
pub max_configuration_rollbacks: Option<String>,
pub no_redirects: bool,
pub default_address_selection: bool,
pub internet_options: Option<InternetOptions>,
pub commit: Option<Commit>,
pub processes: Vec<Process>,
pub dynamic_profile_options: Option<DynamicProfileOptions>,
pub extensions: Option<Extensions>,
pub autoinstallation: Option<Autoinstallation>,
pub schema: Option<Schema>,
pub pixel_tracing: Option<PixelTracing>,
pub scripts: Option<Scripts>,
pub no_multicast_echo: bool,
pub no_ping_record_route: bool,
pub no_ping_time_stamp: bool,
pub auto_snapshot: bool,
pub compress_configuration_files: bool,
pub mirror_flash_on_disk: bool,
pub switchover_on_routing_crash: bool,
pub use_imported_time_zones: bool,
pub archival: Option<Archival>,
pub accounting: Option<Accounting>,
pub root_authentication: Option<RootAuthentication>,
pub master_password: Option<MasterPassword>,
pub diag_port_authentication: Vec<String>,
pub diag_port_authentication_secrets: Vec<AuthenticationSecret>,
pub pic_console_authentication: Vec<String>,
pub pic_console_authentication_secrets: Vec<AuthenticationSecret>,
pub license: Option<License>,
pub name_servers: Vec<NameServer>,
pub ntp: Option<Ntp>,
pub syslog: Option<Syslog>,
pub login: Option<Login>,
pub services: Option<Services>,
pub arp: Option<Arp>,
pub icmp: Option<Icmp>,
pub tracing: Option<Tracing>,
pub proxy: Option<Proxy>,
pub demux_options: Option<DemuxOptions>,
pub kernel_replication: Option<KernelReplication>,
pub password_options: Option<PasswordOptions>,
pub radius_options: Option<RadiusOptions>,
pub tacplus_options: Option<TacplusOptions>,
pub auto_configuration_traceoptions: Option<Traceoptions>,
pub vnf_license_supplements: Vec<String>,
pub configuration: Option<ConfigurationInput>,
pub configuration_database: Option<ConfigurationDatabase>,
pub export_format: Option<ExportFormat>,
pub health_monitor: Option<HealthMonitor>,
pub monitor: Option<Monitor>,
pub resiliency: Option<Resiliency>,
pub snapshot: Option<Snapshot>,
pub access_line: Option<AccessLine>,
pub ddos_protection: Option<DdosProtection>,
pub fib_streaming: Option<FibStreaming>,
pub packet_forwarding_options: Option<PacketForwardingOptions>,
pub management_traffic: Vec<ManagementTrafficProtocol>,
pub auto_sw_sync: Vec<AutoSwSync>,
pub offline_nodes: Vec<String>,
pub boot_loader_authentication: Vec<String>,
pub boot_loader_authentication_secrets: Vec<AuthenticationSecret>,
pub device_authentication: Vec<String>,
pub device_authentication_secrets: Vec<AuthenticationSecret>,
pub allow_6pe_traceroute: bool,
pub allow_v4mapped_packets: bool,
pub arp_enhanced_scale: bool,
pub no_redirects_ipv6: bool,
pub nd_maxucast_retry: Option<String>,
pub allow_l3vpn_traceroute_src_select: bool,
pub dual_phase_bootup: bool,
pub extended_echo: bool,
pub management_instance: bool,
pub nd_override_preferred_src: bool,
pub no_hidden_commands: bool,
pub regex_additive_logic: bool,
pub unattended_boot: bool,
pub arp_system_cache_limit: Option<String>,
pub nd_retransmit_timer: Option<String>,
pub nd_system_cache_limit: Option<String>,
pub rng: Option<String>,
pub saved_core_context: Option<bool>,
pub saved_core_files: Option<String>,
}
pub fn system(config: &Config) -> Option<System> {
let system = top_level(config, "system")?;
Some(System {
host_name: arg_of(system, "host-name").map(str::to_string),
domain_name: arg_of(system, "domain-name").map(str::to_string),
time_zone: arg_of(system, "time-zone").map(str::to_string),
domain_search: args_of(system, "domain-search")
.into_iter()
.flat_map(list_values)
.collect(),
static_host_mappings: static_host_mappings(system),
backup_router: arg_of(system, "backup-router").map(parse_backup_router),
inet6_backup_router: arg_of(system, "inet6-backup-router").map(parse_backup_router),
authentication_order: args_of(system, "authentication-order")
.into_iter()
.flat_map(list_values)
.collect(),
radius_servers: radius_servers(system, "radius-server"),
tacplus_servers: tacplus_servers(system, "tacplus-server"),
location: child_block(system, "location").map(parse_location),
ports: child_block(system, "ports").map(parse_ports),
max_configurations_on_flash: arg_of(system, "max-configurations-on-flash").map(str::to_string),
max_configuration_rollbacks: arg_of(system, "max-configuration-rollbacks").map(str::to_string),
no_redirects: has_leaf(system, "no-redirects"),
default_address_selection: has_leaf(system, "default-address-selection"),
internet_options: child_block(system, "internet-options").map(parse_internet_options),
commit: child_block(system, "commit").map(parse_commit),
processes: child_block(system, "processes")
.map(parse_processes)
.unwrap_or_default(),
dynamic_profile_options: child_block(system, "dynamic-profile-options").map(parse_dynamic_profile_options),
extensions: child_block(system, "extensions").map(parse_extensions),
autoinstallation: child_block(system, "autoinstallation").map(parse_autoinstallation),
schema: child_block(system, "schema").map(parse_schema),
pixel_tracing: child_block(system, "pixel-tracing").map(parse_pixel_tracing),
scripts: child_block(system, "scripts").map(parse_scripts),
no_multicast_echo: has_leaf(system, "no-multicast-echo"),
no_ping_record_route: has_leaf(system, "no-ping-record-route"),
no_ping_time_stamp: has_leaf(system, "no-ping-time-stamp"),
auto_snapshot: has_leaf(system, "auto-snapshot"),
compress_configuration_files: has_leaf(system, "compress-configuration-files"),
mirror_flash_on_disk: has_leaf(system, "mirror-flash-on-disk"),
switchover_on_routing_crash: has_leaf(system, "switchover-on-routing-crash"),
use_imported_time_zones: has_leaf(system, "use-imported-time-zones"),
archival: child_block(system, "archival").map(parse_archival),
accounting: child_block(system, "accounting").map(parse_accounting),
root_authentication: root_authentication(system),
master_password: child_block(system, "master-password").map(parse_master_password),
diag_port_authentication: password_methods(system, "diag-port-authentication"),
diag_port_authentication_secrets: password_secrets(system, "diag-port-authentication"),
pic_console_authentication: password_methods(system, "pic-console-authentication"),
pic_console_authentication_secrets: password_secrets(system, "pic-console-authentication"),
license: child_block(system, "license").map(parse_license),
name_servers: name_servers(system),
ntp: child_block(system, "ntp").map(parse_ntp),
syslog: child_block(system, "syslog").map(parse_syslog),
login: child_block(system, "login").map(parse_login),
services: child_block(system, "services").map(parse_services),
arp: child_block(system, "arp").map(parse_arp),
icmp: child_block(system, "icmp").map(parse_icmp),
tracing: child_block(system, "tracing").map(parse_tracing),
proxy: child_block(system, "proxy").map(parse_proxy),
demux_options: child_block(system, "demux-options").map(parse_demux_options),
kernel_replication: child_block(system, "kernel-replication").map(parse_kernel_replication),
password_options: child_block(system, "password-options").map(parse_password_options),
radius_options: child_block(system, "radius-options").map(parse_radius_options),
tacplus_options: child_block(system, "tacplus-options").map(parse_tacplus_options),
auto_configuration_traceoptions: child_block(system, "auto-configuration").and_then(parse_traceoptions),
vnf_license_supplements: child_block(system, "vnf-license-supplement")
.map(|supplement| active_children(supplement).map(|line| line.text.clone()).collect())
.unwrap_or_default(),
configuration: child_block(system, "configuration").map(parse_configuration),
configuration_database: child_block(system, "configuration-database").map(parse_configuration_database),
export_format: child_block(system, "export-format").map(parse_export_format),
health_monitor: child_block(system, "health-monitor").map(parse_health_monitor),
monitor: child_block(system, "monitor").map(parse_monitor),
resiliency: child_block(system, "resiliency").map(parse_resiliency),
snapshot: child_block(system, "snapshot").map(parse_snapshot),
access_line: child_block(system, "access-line").map(parse_access_line),
ddos_protection: child_block(system, "ddos-protection").map(parse_ddos_protection),
fib_streaming: child_block(system, "fib-streaming").map(parse_fib_streaming),
packet_forwarding_options: child_block(system, "packet-forwarding-options")
.map(parse_packet_forwarding_options),
management_traffic: management_traffic(system),
auto_sw_sync: auto_sw_sync(system),
offline_nodes: child_block(system, "node")
.map(|node| args_of(node, "offline").into_iter().map(str::to_string).collect())
.unwrap_or_default(),
boot_loader_authentication: password_methods(system, "boot-loader-authentication"),
boot_loader_authentication_secrets: password_secrets(system, "boot-loader-authentication"),
device_authentication: password_methods(system, "device-authentication"),
device_authentication_secrets: password_secrets(system, "device-authentication"),
allow_6pe_traceroute: has_leaf(system, "allow-6pe-traceroute"),
allow_v4mapped_packets: has_leaf(system, "allow-v4mapped-packets"),
arp_enhanced_scale: has_leaf(system, "arp-enhanced-scale"),
no_redirects_ipv6: has_leaf(system, "no-redirects-ipv6"),
nd_maxucast_retry: arg_of(system, "nd-maxucast-retry").map(str::to_string),
allow_l3vpn_traceroute_src_select: has_leaf(system, "allow-l3vpn-traceroute-src-select"),
dual_phase_bootup: has_leaf(system, "dual-phase-bootup"),
extended_echo: has_leaf(system, "extended-echo"),
management_instance: has_leaf(system, "management-instance"),
nd_override_preferred_src: has_leaf(system, "nd-override-preferred-src"),
no_hidden_commands: has_leaf(system, "no-hidden-commands"),
regex_additive_logic: has_leaf(system, "regex-additive-logic"),
unattended_boot: has_leaf(system, "unattended-boot"),
arp_system_cache_limit: arg_of(system, "arp-system-cache-limit").map(str::to_string),
nd_retransmit_timer: arg_of(system, "nd-retransmit-timer").map(str::to_string),
nd_system_cache_limit: arg_of(system, "nd-system-cache-limit").map(str::to_string),
rng: arg_of(system, "rng").map(str::to_string),
saved_core_context: toggle(system, "saved-core-context"),
saved_core_files: arg_of(system, "saved-core-files").map(str::to_string),
})
}
fn servers<'a>(system: &'a ConfigLine, keyword: &str) -> Vec<(&'a str, &'a ConfigLine)> {
let mut found = Vec::new();
for child in active_children(system) {
if child.text == keyword {
found.extend(active_children(child).map(|server| (unquote(&server.text), server)));
} else if let Some(arg) = child.arg(keyword) {
found.push((split_name(arg).0, child));
}
}
found
}
fn password_methods(system: &ConfigLine, keyword: &str) -> Vec<String> {
let mut methods = Vec::new();
for child in active_children(system) {
if child.text == keyword {
methods.extend(authentication_methods(child));
} else if let Some(method) = child.arg(keyword).and_then(|arg| arg.split_whitespace().next()) {
methods.push(method.to_string());
}
}
methods
}
fn authentication_methods(auth: &ConfigLine) -> Vec<String> {
active_children(auth)
.filter_map(|c| c.text.split_whitespace().next())
.map(str::to_string)
.collect()
}
#[cfg(test)]
mod tests {
use crate::system::system;
use asterust::config::juniper;
#[test]
fn extracts_host_name() {
let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
assert_eq!(system.host_name.as_deref(), Some("pe1"));
}
#[test]
fn host_name_is_optional() {
let system = system(&juniper::parse_braces("system {\n domain-name example.net;\n}\n")).unwrap();
assert_eq!(system.host_name, None);
}
#[test]
fn skips_inactive_host_name() {
let system = system(&juniper::parse_braces("system {\n inactive: host-name pe1;\n}\n")).unwrap();
assert_eq!(system.host_name, None);
}
#[test]
fn extracts_domain_name() {
let system = system(&juniper::parse_braces(
"system {\n host-name pe1;\n domain-name example.net;\n}\n",
))
.unwrap();
assert_eq!(system.domain_name.as_deref(), Some("example.net"));
}
#[test]
fn domain_name_is_optional() {
let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
assert_eq!(system.domain_name, None);
}
#[test]
fn extracts_time_zone() {
let system = system(&juniper::parse_braces("system {\n time-zone America/New_York;\n}\n")).unwrap();
assert_eq!(system.time_zone.as_deref(), Some("America/New_York"));
}
#[test]
fn time_zone_is_optional() {
let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
assert_eq!(system.time_zone, None);
}
#[test]
fn extracts_configuration_limits_and_no_redirects() {
let system = system(&juniper::parse_braces(
"system {\n max-configurations-on-flash 5;\n max-configuration-rollbacks 20;\n no-redirects;\n}\n",
))
.unwrap();
assert_eq!(system.max_configurations_on_flash.as_deref(), Some("5"));
assert_eq!(system.max_configuration_rollbacks.as_deref(), Some("20"));
assert!(system.no_redirects);
}
#[test]
fn configuration_limits_are_optional() {
let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
assert_eq!(system.max_configurations_on_flash, None);
assert_eq!(system.max_configuration_rollbacks, None);
assert!(!system.no_redirects);
}
#[test]
fn extracts_system_flags() {
let system = system(&juniper::parse_braces(
"system {\n no-multicast-echo;\n no-ping-record-route;\n no-ping-time-stamp;\n auto-snapshot;\n compress-configuration-files;\n mirror-flash-on-disk;\n switchover-on-routing-crash;\n use-imported-time-zones;\n}\n",
))
.unwrap();
assert!(system.no_multicast_echo);
assert!(system.no_ping_record_route);
assert!(system.no_ping_time_stamp);
assert!(system.auto_snapshot);
assert!(system.compress_configuration_files);
assert!(system.mirror_flash_on_disk);
assert!(system.switchover_on_routing_crash);
assert!(system.use_imported_time_zones);
}
#[test]
fn system_flags_default_to_off() {
let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
assert!(!system.no_multicast_echo);
assert!(!system.auto_snapshot);
assert!(!system.use_imported_time_zones);
}
#[test]
fn no_system_is_none() {
assert!(system(&juniper::parse_braces("interfaces {\n lo0;\n}\n")).is_none());
}
#[test]
fn diag_port_and_pic_console_report_only_the_method() {
let system = system(&juniper::parse_braces(
r#"
system {
diag-port-authentication encrypted-password "$6$salt$hash"; ## SECRET-DATA
pic-console-authentication {
encrypted-password "$6$salt$other"; ## SECRET-DATA
}
}
"#,
))
.unwrap();
assert_eq!(system.diag_port_authentication, ["encrypted-password"]);
assert_eq!(system.pic_console_authentication, ["encrypted-password"]);
let values = |secrets: &[crate::system::AuthenticationSecret]| -> Vec<String> {
secrets.iter().map(|s| s.value.expose().to_string()).collect()
};
let (diag, pic) = if cfg!(feature = "secrets") {
(vec!["$6$salt$hash".to_string()], vec!["$6$salt$other".to_string()])
} else {
(Vec::new(), Vec::new())
};
assert_eq!(values(&system.diag_port_authentication_secrets), diag);
assert_eq!(values(&system.pic_console_authentication_secrets), pic);
}
#[test]
fn secret_settings_are_optional() {
let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
assert!(system.master_password.is_none());
assert!(system.diag_port_authentication.is_empty());
assert!(system.pic_console_authentication.is_empty());
}
#[test]
fn extracts_authentication_order() {
let system = system(&juniper::parse_braces(
"system {\n authentication-order [ tacplus radius password ];\n}\n",
))
.unwrap();
assert_eq!(system.authentication_order, ["tacplus", "radius", "password"]);
}
#[test]
fn authentication_settings_are_optional() {
let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
assert!(system.authentication_order.is_empty());
assert!(system.radius_servers.is_empty());
assert!(system.tacplus_servers.is_empty());
}
#[test]
fn extracts_domain_search_list() {
let system = system(&juniper::parse_braces(
"system {\n domain-search [ example.net lab.example.net ];\n}\n",
))
.unwrap();
assert_eq!(system.domain_search, ["example.net", "lab.example.net"]);
}
#[test]
fn addressing_settings_are_optional() {
let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
assert!(system.domain_search.is_empty());
assert!(system.static_host_mappings.is_empty());
assert!(system.backup_router.is_none());
assert!(system.inet6_backup_router.is_none());
}
#[test]
fn extracts_the_scalar_flags_and_limits() {
let system = system(&juniper::parse_braces(
r#"
system {
allow-6pe-traceroute;
allow-l3vpn-traceroute-src-select;
dual-phase-bootup;
extended-echo;
management-instance;
nd-override-preferred-src;
no-hidden-commands;
regex-additive-logic;
unattended-boot;
arp-system-cache-limit 50000;
nd-retransmit-timer 2000;
nd-system-cache-limit 150000;
rng fortuna;
saved-core-files 3;
saved-core-context;
}
"#,
))
.unwrap();
assert!(system.allow_6pe_traceroute);
assert!(system.allow_l3vpn_traceroute_src_select);
assert!(system.dual_phase_bootup);
assert!(system.extended_echo);
assert!(system.management_instance);
assert!(system.nd_override_preferred_src);
assert!(system.no_hidden_commands);
assert!(system.regex_additive_logic);
assert!(system.unattended_boot);
assert_eq!(system.arp_system_cache_limit.as_deref(), Some("50000"));
assert_eq!(system.nd_retransmit_timer.as_deref(), Some("2000"));
assert_eq!(system.nd_system_cache_limit.as_deref(), Some("150000"));
assert_eq!(system.rng.as_deref(), Some("fortuna"));
assert_eq!(system.saved_core_files.as_deref(), Some("3"));
assert_eq!(system.saved_core_context, Some(true));
}
#[test]
fn reads_no_saved_core_context() {
let system = system(&juniper::parse_braces("system {\n no-saved-core-context;\n}\n")).unwrap();
assert_eq!(system.saved_core_context, Some(false));
}
#[test]
fn extracts_the_v4mapped_enhanced_scale_and_nd_retry_statements() {
let system = system(&juniper::parse_braces(
"system {\n allow-v4mapped-packets;\n arp-enhanced-scale;\n no-redirects-ipv6;\n nd-maxucast-retry 5;\n}\n",
))
.unwrap();
assert!(system.allow_v4mapped_packets);
assert!(system.arp_enhanced_scale);
assert!(system.no_redirects_ipv6);
assert_eq!(system.nd_maxucast_retry.as_deref(), Some("5"));
}
#[test]
fn scalar_flags_and_limits_are_optional() {
let system = system(&juniper::parse_braces("system {\n host-name pe1;\n}\n")).unwrap();
assert!(!system.allow_6pe_traceroute);
assert!(!system.management_instance);
assert!(!system.unattended_boot);
assert_eq!(system.arp_system_cache_limit, None);
assert_eq!(system.rng, None);
assert_eq!(system.saved_core_context, None);
assert!(system.offline_nodes.is_empty());
}
#[test]
fn extracts_auto_configuration_traceoptions_and_vnf_license_supplements() {
let system = system(&juniper::parse_braces(
"system {\n auto-configuration {\n traceoptions {\n file autoconf.log;\n level info;\n }\n }\n vnf-license-supplement {\n gnf1 augmented-ssrn-1;\n }\n}\n",
))
.unwrap();
assert_eq!(
system.auto_configuration_traceoptions.unwrap().level.as_deref(),
Some("info")
);
assert_eq!(system.vnf_license_supplements, ["gnf1 augmented-ssrn-1"]);
}
#[test]
fn extracts_offline_nodes() {
let system = system(&juniper::parse_braces(
"system {\n node {\n offline re1;\n offline fpc3;\n }\n}\n",
))
.unwrap();
assert_eq!(system.offline_nodes, ["re1", "fpc3"]);
}
#[test]
fn boot_loader_and_device_authentication_report_only_the_method() {
let system = system(&juniper::parse_braces(
r#"
system {
boot-loader-authentication {
encrypted-password "$1$salt$hash"; ## SECRET-DATA
}
device-authentication {
encrypted-password "$6$salt$other"; ## SECRET-DATA
}
}
"#,
))
.unwrap();
assert_eq!(system.boot_loader_authentication, ["encrypted-password"]);
assert_eq!(system.device_authentication, ["encrypted-password"]);
let values = |secrets: &[crate::system::AuthenticationSecret]| -> Vec<String> {
secrets.iter().map(|s| s.value.expose().to_string()).collect()
};
let (boot, device) = if cfg!(feature = "secrets") {
(vec!["$1$salt$hash".to_string()], vec!["$6$salt$other".to_string()])
} else {
(Vec::new(), Vec::new())
};
assert_eq!(values(&system.boot_loader_authentication_secrets), boot);
assert_eq!(values(&system.device_authentication_secrets), device);
}
}