upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/grasp-audit/src/specs/grasp01/nip11_document.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-01 14:31:32 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-01 15:22:38 +0000
commitd2ac69816567f092fe0d4661723bc43778cb481b (patch)
treee8b51b61a6a7b0ab1a214adebe4e237143b01f0b /grasp-audit/src/specs/grasp01/nip11_document.rs
parent7a78815e29b01c83f3d0ec195ba717a2eba8cd37 (diff)
fix cargo clippy and fmt warnings
Diffstat (limited to 'grasp-audit/src/specs/grasp01/nip11_document.rs')
-rw-r--r--grasp-audit/src/specs/grasp01/nip11_document.rs61
1 files changed, 41 insertions, 20 deletions
diff --git a/grasp-audit/src/specs/grasp01/nip11_document.rs b/grasp-audit/src/specs/grasp01/nip11_document.rs
index bb864f2..51b147d 100644
--- a/grasp-audit/src/specs/grasp01/nip11_document.rs
+++ b/grasp-audit/src/specs/grasp01/nip11_document.rs
@@ -42,7 +42,9 @@ impl Nip11DocumentTests {
42 ) 42 )
43 .run(|| async { 43 .run(|| async {
44 // 1. Extract HTTP(S) URL from client's WebSocket URL 44 // 1. Extract HTTP(S) URL from client's WebSocket URL
45 let ws_url = client.relay_url().await 45 let ws_url = client
46 .relay_url()
47 .await
46 .map_err(|e| format!("Failed to get relay URL: {}", e))?; 48 .map_err(|e| format!("Failed to get relay URL: {}", e))?;
47 let http_url = AuditClient::ws_to_http_url(&ws_url) 49 let http_url = AuditClient::ws_to_http_url(&ws_url)
48 .map_err(|e| format!("Failed to convert WebSocket URL to HTTP: {}", e))?; 50 .map_err(|e| format!("Failed to convert WebSocket URL to HTTP: {}", e))?;
@@ -66,16 +68,18 @@ impl Nip11DocumentTests {
66 } 68 }
67 69
68 // 4. Verify response is valid JSON 70 // 4. Verify response is valid JSON
69 let json_text = response.text().await 71 let json_text = response
72 .text()
73 .await
70 .map_err(|e| format!("Failed to read response body: {}", e))?; 74 .map_err(|e| format!("Failed to read response body: {}", e))?;
71 75
72 let doc: serde_json::Value = serde_json::from_str(&json_text) 76 let doc: serde_json::Value = serde_json::from_str(&json_text)
73 .map_err(|e| format!("Response is not valid JSON: {}", e))?; 77 .map_err(|e| format!("Response is not valid JSON: {}", e))?;
74 78
75 // 5. Verify has required NIP-11 fields 79 // 5. Verify has required NIP-11 fields
76 let required_fields = ["name", "description", "software", "version"]; 80 let required_fields = ["name", "description", "software", "version"];
77 for field in &required_fields { 81 for field in &required_fields {
78 if !doc.get(field).is_some() { 82 if doc.get(field).is_none() {
79 return Err(format!("Missing required NIP-11 field: {}", field)); 83 return Err(format!("Missing required NIP-11 field: {}", field));
80 } 84 }
81 } 85 }
@@ -97,7 +101,9 @@ impl Nip11DocumentTests {
97 ) 101 )
98 .run(|| async { 102 .run(|| async {
99 // 1. Fetch NIP-11 document 103 // 1. Fetch NIP-11 document
100 let ws_url = client.relay_url().await 104 let ws_url = client
105 .relay_url()
106 .await
101 .map_err(|e| format!("Failed to get relay URL: {}", e))?; 107 .map_err(|e| format!("Failed to get relay URL: {}", e))?;
102 let http_url = AuditClient::ws_to_http_url(&ws_url) 108 let http_url = AuditClient::ws_to_http_url(&ws_url)
103 .map_err(|e| format!("Failed to convert WebSocket URL to HTTP: {}", e))?; 109 .map_err(|e| format!("Failed to convert WebSocket URL to HTTP: {}", e))?;
@@ -110,18 +116,22 @@ impl Nip11DocumentTests {
110 .await 116 .await
111 .map_err(|e| format!("Failed to fetch NIP-11 document: {}", e))?; 117 .map_err(|e| format!("Failed to fetch NIP-11 document: {}", e))?;
112 118
113 let json_text = response.text().await 119 let json_text = response
120 .text()
121 .await
114 .map_err(|e| format!("Failed to read response body: {}", e))?; 122 .map_err(|e| format!("Failed to read response body: {}", e))?;
115 123
116 let doc: serde_json::Value = serde_json::from_str(&json_text) 124 let doc: serde_json::Value = serde_json::from_str(&json_text)
117 .map_err(|e| format!("Response is not valid JSON: {}", e))?; 125 .map_err(|e| format!("Response is not valid JSON: {}", e))?;
118 126
119 // 2. Verify `supported_grasps` field exists 127 // 2. Verify `supported_grasps` field exists
120 let supported_grasps = doc.get("supported_grasps") 128 let supported_grasps = doc
129 .get("supported_grasps")
121 .ok_or_else(|| "Missing required field: supported_grasps".to_string())?; 130 .ok_or_else(|| "Missing required field: supported_grasps".to_string())?;
122 131
123 // 3. Verify it's a JSON array 132 // 3. Verify it's a JSON array
124 let grasps_array = supported_grasps.as_array() 133 let grasps_array = supported_grasps
134 .as_array()
125 .ok_or_else(|| "supported_grasps must be an array".to_string())?; 135 .ok_or_else(|| "supported_grasps must be an array".to_string())?;
126 136
127 // 4. Verify array includes "GRASP-01" 137 // 4. Verify array includes "GRASP-01"
@@ -140,7 +150,7 @@ impl Nip11DocumentTests {
140 // 5. Verify format: each entry should match pattern "GRASP-\d{2}" 150 // 5. Verify format: each entry should match pattern "GRASP-\d{2}"
141 let grasp_pattern = regex::Regex::new(r"^GRASP-\d{2}$") 151 let grasp_pattern = regex::Regex::new(r"^GRASP-\d{2}$")
142 .map_err(|e| format!("Failed to compile regex: {}", e))?; 152 .map_err(|e| format!("Failed to compile regex: {}", e))?;
143 153
144 for grasp in &grasp_strings { 154 for grasp in &grasp_strings {
145 if !grasp_pattern.is_match(grasp) { 155 if !grasp_pattern.is_match(grasp) {
146 return Err(format!( 156 return Err(format!(
@@ -167,7 +177,9 @@ impl Nip11DocumentTests {
167 ) 177 )
168 .run(|| async { 178 .run(|| async {
169 // 1. Fetch NIP-11 document 179 // 1. Fetch NIP-11 document
170 let ws_url = client.relay_url().await 180 let ws_url = client
181 .relay_url()
182 .await
171 .map_err(|e| format!("Failed to get relay URL: {}", e))?; 183 .map_err(|e| format!("Failed to get relay URL: {}", e))?;
172 let http_url = AuditClient::ws_to_http_url(&ws_url) 184 let http_url = AuditClient::ws_to_http_url(&ws_url)
173 .map_err(|e| format!("Failed to convert WebSocket URL to HTTP: {}", e))?; 185 .map_err(|e| format!("Failed to convert WebSocket URL to HTTP: {}", e))?;
@@ -180,18 +192,22 @@ impl Nip11DocumentTests {
180 .await 192 .await
181 .map_err(|e| format!("Failed to fetch NIP-11 document: {}", e))?; 193 .map_err(|e| format!("Failed to fetch NIP-11 document: {}", e))?;
182 194
183 let json_text = response.text().await 195 let json_text = response
196 .text()
197 .await
184 .map_err(|e| format!("Failed to read response body: {}", e))?; 198 .map_err(|e| format!("Failed to read response body: {}", e))?;
185 199
186 let doc: serde_json::Value = serde_json::from_str(&json_text) 200 let doc: serde_json::Value = serde_json::from_str(&json_text)
187 .map_err(|e| format!("Response is not valid JSON: {}", e))?; 201 .map_err(|e| format!("Response is not valid JSON: {}", e))?;
188 202
189 // 2. Verify `repo_acceptance_criteria` field exists 203 // 2. Verify `repo_acceptance_criteria` field exists
190 let criteria = doc.get("repo_acceptance_criteria") 204 let criteria = doc
205 .get("repo_acceptance_criteria")
191 .ok_or_else(|| "Missing required field: repo_acceptance_criteria".to_string())?; 206 .ok_or_else(|| "Missing required field: repo_acceptance_criteria".to_string())?;
192 207
193 // 3. Verify it's a string 208 // 3. Verify it's a string
194 let criteria_str = criteria.as_str() 209 let criteria_str = criteria
210 .as_str()
195 .ok_or_else(|| "repo_acceptance_criteria must be a string".to_string())?; 211 .ok_or_else(|| "repo_acceptance_criteria must be a string".to_string())?;
196 212
197 // 4. Verify non-empty 213 // 4. Verify non-empty
@@ -216,7 +232,9 @@ impl Nip11DocumentTests {
216 ) 232 )
217 .run(|| async { 233 .run(|| async {
218 // 1. Fetch NIP-11 document 234 // 1. Fetch NIP-11 document
219 let ws_url = client.relay_url().await 235 let ws_url = client
236 .relay_url()
237 .await
220 .map_err(|e| format!("Failed to get relay URL: {}", e))?; 238 .map_err(|e| format!("Failed to get relay URL: {}", e))?;
221 let http_url = AuditClient::ws_to_http_url(&ws_url) 239 let http_url = AuditClient::ws_to_http_url(&ws_url)
222 .map_err(|e| format!("Failed to convert WebSocket URL to HTTP: {}", e))?; 240 .map_err(|e| format!("Failed to convert WebSocket URL to HTTP: {}", e))?;
@@ -229,16 +247,19 @@ impl Nip11DocumentTests {
229 .await 247 .await
230 .map_err(|e| format!("Failed to fetch NIP-11 document: {}", e))?; 248 .map_err(|e| format!("Failed to fetch NIP-11 document: {}", e))?;
231 249
232 let json_text = response.text().await 250 let json_text = response
251 .text()
252 .await
233 .map_err(|e| format!("Failed to read response body: {}", e))?; 253 .map_err(|e| format!("Failed to read response body: {}", e))?;
234 254
235 let doc: serde_json::Value = serde_json::from_str(&json_text) 255 let doc: serde_json::Value = serde_json::from_str(&json_text)
236 .map_err(|e| format!("Response is not valid JSON: {}", e))?; 256 .map_err(|e| format!("Response is not valid JSON: {}", e))?;
237 257
238 // 2. Check if `curation` field exists 258 // 2. Check if `curation` field exists
239 if let Some(curation) = doc.get("curation") { 259 if let Some(curation) = doc.get("curation") {
240 // 3. If present: verify it's a non-empty string 260 // 3. If present: verify it's a non-empty string
241 let curation_str = curation.as_str() 261 let curation_str = curation
262 .as_str()
242 .ok_or_else(|| "curation field must be a string when present".to_string())?; 263 .ok_or_else(|| "curation field must be a string when present".to_string())?;
243 264
244 if curation_str.trim().is_empty() { 265 if curation_str.trim().is_empty() {
@@ -284,4 +305,4 @@ mod tests {
284 // Don't assert all passed yet - tests not implemented 305 // Don't assert all passed yet - tests not implemented
285 // assert!(results.all_passed(), "Some GRASP-01 NIP-11 document tests failed"); 306 // assert!(results.all_passed(), "Some GRASP-01 NIP-11 document tests failed");
286 } 307 }
287} \ No newline at end of file 308}