Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/Binary/Build/
DnsCommands.rs

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