Skip to main content

Mountain/Binary/Build/
DnsCommands.rs

1#![allow(non_snake_case)]
2
3//! # DNS commands
4//!
5//! Tauri commands that surface the Mist-managed DNS server
6//! (Hickory) to the webview - server state, zone snapshot,
7//! forward allowlist, manual resolution. The DTOs and command
8//! handlers live in sibling files; the wire-bound names match
9//! the file names so the `invoke_handler!` registration in
10//! `Binary/Main/Entry.rs` is a 1:1 mapping.
11
12pub mod DnsHealthStatus;
13pub mod DnsResolutionResult;
14pub mod DnsServerInfo;
15pub mod ForwardAllowList;
16pub mod StartupTime;
17pub mod ZoneInfo;
18pub mod ZoneRecord;
19pub mod dns_get_forward_allowlist;
20pub mod dns_get_health_status;
21pub mod dns_get_server_info;
22pub mod dns_get_zone_info;
23pub mod dns_health_check;
24pub mod dns_resolve;
25pub mod dns_test_resolution;
26
27#[cfg(test)]
28mod tests {
29	use super::{
30		DnsHealthStatus::DnsHealthStatus,
31		DnsResolutionResult::DnsResolutionResult,
32		DnsServerInfo::DnsServerInfo,
33		ForwardAllowList::ForwardAllowList,
34		ZoneRecord::ZoneRecord,
35	};
36
37	#[test]
38	fn DnsServerInfoSerialization() {
39		let info = DnsServerInfo { port:5380, is_running:true, startup_time:"2024-01-01T00:00:00Z".to_string() };
40		let json = serde_json::to_string(&info).unwrap();
41		let deserialized:DnsServerInfo = serde_json::from_str(&json).unwrap();
42		assert_eq!(deserialized.port, 5380);
43		assert_eq!(deserialized.is_running, true);
44		assert_eq!(deserialized.startup_time, "2024-01-01T00:00:00Z");
45	}
46
47	#[test]
48	fn ZoneRecordSerialization() {
49		let record = ZoneRecord {
50			name:"code.editor.land.".to_string(),
51			record_type:"A".to_string(),
52			ttl:3600,
53			data:"127.0.0.1".to_string(),
54		};
55		let json = serde_json::to_string(&record).unwrap();
56		let deserialized:ZoneRecord = serde_json::from_str(&json).unwrap();
57		assert_eq!(deserialized.name, "code.editor.land.");
58		assert_eq!(deserialized.record_type, "A");
59		assert_eq!(deserialized.ttl, 3600);
60		assert_eq!(deserialized.data, "127.0.0.1");
61	}
62
63	#[test]
64	fn ForwardAllowListSerialization() {
65		let allowlist = ForwardAllowList { domains:vec!["update.editor.land.".to_string()] };
66		let json = serde_json::to_string(&allowlist).unwrap();
67		let deserialized:ForwardAllowList = serde_json::from_str(&json).unwrap();
68		assert_eq!(deserialized.domains.len(), 1);
69		assert_eq!(deserialized.domains[0], "update.editor.land.");
70	}
71
72	#[test]
73	fn DnsHealthStatusSerialization() {
74		let health = DnsHealthStatus {
75			server_status:"running".to_string(),
76			zone_status:"active".to_string(),
77			forward_status:"active".to_string(),
78			last_error:None,
79		};
80		let json = serde_json::to_string(&health).unwrap();
81		let deserialized:DnsHealthStatus = serde_json::from_str(&json).unwrap();
82		assert_eq!(deserialized.server_status, "running");
83		assert_eq!(deserialized.zone_status, "active");
84		assert_eq!(deserialized.forward_status, "active");
85		assert!(deserialized.last_error.is_none());
86	}
87
88	#[test]
89	fn DnsResolutionResultSerialization() {
90		let result = DnsResolutionResult {
91			domain:"code.editor.land.".to_string(),
92			record_type:"A".to_string(),
93			addresses:vec!["127.0.0.1".to_string()],
94			ttl:3600,
95			succeeded:true,
96			error:None,
97		};
98		let json = serde_json::to_string(&result).unwrap();
99		let deserialized:DnsResolutionResult = serde_json::from_str(&json).unwrap();
100		assert_eq!(deserialized.domain, "code.editor.land.");
101		assert_eq!(deserialized.record_type, "A");
102		assert_eq!(deserialized.addresses.len(), 1);
103		assert_eq!(deserialized.addresses[0], "127.0.0.1");
104		assert_eq!(deserialized.ttl, 3600);
105		assert!(deserialized.succeeded);
106		assert!(deserialized.error.is_none());
107	}
108}