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-11-05 20:13:22 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-11-05 20:25:38 +0000
commit396da002fefeeb4549e11ff51abf824e91a6ed88 (patch)
treed5a61d081d97b52a38f7ce8f4a28d8c200eeede3 /grasp-audit/src/specs/grasp01/nip11_document.rs
parentb22cb23928ef799b0a5d362003d3084d2ab267b4 (diff)
restructure grasp01 audit tests and add event acceptance
Diffstat (limited to 'grasp-audit/src/specs/grasp01/nip11_document.rs')
-rw-r--r--grasp-audit/src/specs/grasp01/nip11_document.rs165
1 files changed, 165 insertions, 0 deletions
diff --git a/grasp-audit/src/specs/grasp01/nip11_document.rs b/grasp-audit/src/specs/grasp01/nip11_document.rs
new file mode 100644
index 0000000..3f9c04a
--- /dev/null
+++ b/grasp-audit/src/specs/grasp01/nip11_document.rs
@@ -0,0 +1,165 @@
1//! GRASP-01 NIP-11 Document
2//!
3//! Tests for GRASP-01 NIP-11 relay information document requirements (lines 11-14 of ../grasp/01.md)
4//!
5//! These tests validate that a GRASP-01 compliant relay:
6//! - Serves a valid NIP-11 relay information document
7//! - Includes supported_grasps field listing supported GRASPs
8//! - Includes repo_acceptance_criteria field describing acceptance policy
9//! - Handles curation field correctly (present if curated, absent otherwise)
10
11use crate::{AuditClient, AuditResult, TestResult};
12use nostr_sdk::prelude::*;
13
14pub struct Nip11DocumentTests;
15
16impl Nip11DocumentTests {
17 /// Run all NIP-11 document tests
18 pub async fn run_all(client: &AuditClient) -> AuditResult {
19 let mut results = AuditResult::new("GRASP-01 NIP-11 Document Tests");
20
21 // NIP-11 relay information tests
22 results.add(Self::test_nip11_document_exists(client).await);
23 results.add(Self::test_nip11_supported_grasps_field(client).await);
24 results.add(Self::test_nip11_repo_acceptance_criteria_field(client).await);
25 results.add(Self::test_nip11_curation_field(client).await);
26
27 results
28 }
29
30 // =========================================================================
31 // NIP-11 Relay Information Tests
32 // =========================================================================
33
34 /// Test: Serve NIP-11 document
35 ///
36 /// Spec: Line 11 of ../grasp/01.md
37 /// Requirement: MUST serve NIP-11 document
38 async fn test_nip11_document_exists(client: &AuditClient) -> TestResult {
39 TestResult::new(
40 "nip11_document_exists",
41 "GRASP-01:nostr-relay:11",
42 "Serve NIP-11 relay information document",
43 )
44 .run(|| async {
45 // TODO: Implementation
46 // 1. Extract HTTP(S) URL from client's WebSocket URL
47 // - ws://localhost:8081 -> http://localhost:8081
48 // - wss://relay.example.com -> https://relay.example.com
49 // 2. HTTP GET to base URL with header:
50 // - Accept: application/nostr+json
51 // 3. Verify 200 OK response
52 // 4. Verify response is valid JSON
53 // 5. Parse as NIP-11 document
54 // 6. Verify has required fields (name, description, etc.)
55
56 Err("Not implemented yet".to_string())
57 })
58 .await
59 }
60
61 /// Test: NIP-11 includes supported_grasps field
62 ///
63 /// Spec: Line 12 of ../grasp/01.md
64 /// Requirement: MUST list supported GRASPs as string array
65 async fn test_nip11_supported_grasps_field(client: &AuditClient) -> TestResult {
66 TestResult::new(
67 "nip11_supported_grasps_field",
68 "GRASP-01:nostr-relay:12",
69 "NIP-11 document includes supported_grasps field with GRASP-01",
70 )
71 .run(|| async {
72 // TODO: Implementation
73 // 1. Fetch NIP-11 document (same as above)
74 // 2. Verify `supported_grasps` field exists
75 // 3. Verify it's a JSON array of strings
76 // 4. Verify array includes "GRASP-01"
77 // 5. Verify format: each entry matches pattern "GRASP-\d{2}"
78 // 6. Document other GRASPs found (for info)
79
80 Err("Not implemented yet".to_string())
81 })
82 .await
83 }
84
85 /// Test: NIP-11 includes repo_acceptance_criteria field
86 ///
87 /// Spec: Line 13 of ../grasp/01.md
88 /// Requirement: MUST list repository acceptance criteria
89 async fn test_nip11_repo_acceptance_criteria_field(client: &AuditClient) -> TestResult {
90 TestResult::new(
91 "nip11_repo_acceptance_criteria_field",
92 "GRASP-01:nostr-relay:13",
93 "NIP-11 document includes repo_acceptance_criteria field",
94 )
95 .run(|| async {
96 // TODO: Implementation
97 // 1. Fetch NIP-11 document
98 // 2. Verify `repo_acceptance_criteria` field exists
99 // 3. Verify it's a string (human-readable)
100 // 4. Verify non-empty
101 // 5. Document the criteria (for info)
102 // Examples: "Must list this relay in clone and relays tags"
103 // "Pre-payment required via Lightning invoice"
104
105 Err("Not implemented yet".to_string())
106 })
107 .await
108 }
109
110 /// Test: NIP-11 curation field handling
111 ///
112 /// Spec: Line 14 of ../grasp/01.md
113 /// Requirement: MUST include curation if curated, omit otherwise
114 async fn test_nip11_curation_field(client: &AuditClient) -> TestResult {
115 TestResult::new(
116 "nip11_curation_field",
117 "GRASP-01:nostr-relay:14",
118 "NIP-11 curation field present if curated, absent otherwise",
119 )
120 .run(|| async {
121 // TODO: Implementation
122 // 1. Fetch NIP-11 document
123 // 2. Check if `curation` field exists
124 // 3. If present:
125 // - Verify it's a non-empty string
126 // - Document the curation policy
127 // 4. If absent:
128 // - Document that no curation beyond SPAM prevention
129 // 5. Both cases are valid per spec
130
131 Err("Not implemented yet".to_string())
132 })
133 .await
134 }
135
136}
137
138#[cfg(test)]
139mod tests {
140 use super::*;
141 use crate::AuditConfig;
142
143#[tokio::test]
144#[ignore] // Requires running relay
145async fn test_grasp01_nip11_document_against_relay() {
146 // Read relay URL from environment variable - must be supplied
147 let relay_url = std::env::var("RELAY_URL")
148 .expect("RELAY_URL environment variable must be set. Example: RELAY_URL=ws://localhost:18081");
149
150 let config = AuditConfig::ci();
151 let client = AuditClient::new(&relay_url, config)
152 .await
153 .expect(&format!(
154 "Failed to connect to relay at {}. Ensure relay is running and accessible. \
155 Try: docker run --rm -p 18081:8081 ghcr.io/danconwaydev/ngit-relay:latest",
156 relay_url
157 ));
158
159 let results = Nip11DocumentTests::run_all(&client).await;
160 results.print_report();
161
162 // Don't assert all passed yet - tests not implemented
163 // assert!(results.all_passed(), "Some GRASP-01 NIP-11 document tests failed");
164 }
165} \ No newline at end of file