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;
13
14pub mod DnsResolutionResult;
15
16pub mod DnsServerInfo;
17
18pub mod ForwardAllowList;
19
20pub mod StartupTime;
21
22pub mod ZoneInfo;
23
24pub mod ZoneRecord;
25
26pub mod dns_get_forward_allowlist;
27
28pub mod dns_get_health_status;
29
30pub mod dns_get_server_info;
31
32pub mod dns_get_zone_info;
33
34pub mod dns_health_check;
35
36pub mod dns_resolve;
37
38pub mod dns_test_resolution;
39
40#[cfg(test)]
41mod tests {
42
43	use super::{
44		DnsHealthStatus::DnsHealthStatus,
45		DnsResolutionResult::DnsResolutionResult,
46		DnsServerInfo::DnsServerInfo,
47		ForwardAllowList::ForwardAllowList,
48		ZoneRecord::ZoneRecord,
49	};
50
51	#[test]
52	fn DnsServerInfoSerialization() {
53		let info = DnsServerInfo { port:5380, is_running:true, startup_time:"2024-01-01T00:00:00Z".to_string() };
54
55		let json = serde_json::to_string(&info).unwrap();
56
57		let deserialized:DnsServerInfo = serde_json::from_str(&json).unwrap();
58
59		assert_eq!(deserialized.port, 5380);
60
61		assert_eq!(deserialized.is_running, true);
62
63		assert_eq!(deserialized.startup_time, "2024-01-01T00:00:00Z");
64	}
65
66	#[test]
67	fn ZoneRecordSerialization() {
68		let record = ZoneRecord {
69			name:"code.editor.land.".to_string(),
70
71			record_type:"A".to_string(),
72
73			ttl:3600,
74
75			data:"127.0.0.1".to_string(),
76		};
77
78		let json = serde_json::to_string(&record).unwrap();
79
80		let deserialized:ZoneRecord = serde_json::from_str(&json).unwrap();
81
82		assert_eq!(deserialized.name, "code.editor.land.");
83
84		assert_eq!(deserialized.record_type, "A");
85
86		assert_eq!(deserialized.ttl, 3600);
87
88		assert_eq!(deserialized.data, "127.0.0.1");
89	}
90
91	#[test]
92	fn ForwardAllowListSerialization() {
93		let allowlist = ForwardAllowList { domains:vec!["update.editor.land.".to_string()] };
94
95		let json = serde_json::to_string(&allowlist).unwrap();
96
97		let deserialized:ForwardAllowList = serde_json::from_str(&json).unwrap();
98
99		assert_eq!(deserialized.domains.len(), 1);
100
101		assert_eq!(deserialized.domains[0], "update.editor.land.");
102	}
103
104	#[test]
105	fn DnsHealthStatusSerialization() {
106		let health = DnsHealthStatus {
107			server_status:"running".to_string(),
108
109			zone_status:"active".to_string(),
110
111			forward_status:"active".to_string(),
112
113			last_error:None,
114		};
115
116		let json = serde_json::to_string(&health).unwrap();
117
118		let deserialized:DnsHealthStatus = serde_json::from_str(&json).unwrap();
119
120		assert_eq!(deserialized.server_status, "running");
121
122		assert_eq!(deserialized.zone_status, "active");
123
124		assert_eq!(deserialized.forward_status, "active");
125
126		assert!(deserialized.last_error.is_none());
127	}
128
129	#[test]
130	fn DnsResolutionResultSerialization() {
131		let result = DnsResolutionResult {
132			domain:"code.editor.land.".to_string(),
133
134			record_type:"A".to_string(),
135
136			addresses:vec!["127.0.0.1".to_string()],
137
138			ttl:3600,
139
140			succeeded:true,
141
142			error:None,
143		};
144
145		let json = serde_json::to_string(&result).unwrap();
146
147		let deserialized:DnsResolutionResult = serde_json::from_str(&json).unwrap();
148
149		assert_eq!(deserialized.domain, "code.editor.land.");
150
151		assert_eq!(deserialized.record_type, "A");
152
153		assert_eq!(deserialized.addresses.len(), 1);
154
155		assert_eq!(deserialized.addresses[0], "127.0.0.1");
156
157		assert_eq!(deserialized.ttl, 3600);
158
159		assert!(deserialized.succeeded);
160
161		assert!(deserialized.error.is_none());
162	}
163}