Files
ngit-grasp/tests/nip05_identity.rs
DanConwayDev 1ad06bae22 feat(http): support path-mounted GRASP services
Allow operators to share an authority by configuring a normalized public base path. Route HTTP, WebSocket, Git, and GRASP-06 traffic beneath that prefix and carry the path through service validation, generated relay identity, self-sync, NIP-11 icons, and landing links.

Treat NIP-05 as a domain-root capability: path-mounted services neither expose the well-known document nor advertise NIP-05 in NIP-11, and generated owner profiles omit the nip05 field. Exact relay URL matching keeps sibling mounts distinct while clone URLs may descend below the configured prefix.

This assumes reverse proxies preserve the configured public prefix. Proxy-side prefix stripping remains deliberately out of scope.

Validation:
- nix develop -c cargo test
- nix develop -c cargo clippy --all-targets -- -D warnings
- cargo fmt --all -- --check
- git diff --check
- nix-instantiate --parse nix/module.nix
2026-08-18 11:36:24 +00:00

81 lines
2.5 KiB
Rust

//! NIP-05 root-identifier integration tests.
mod common;
use common::TestRelay;
#[tokio::test]
async fn well_known_root_identity_matches_relay_pubkey() {
let relay = TestRelay::start().await;
let client = reqwest::Client::new();
let response = client
.get(format!(
"http://{}/.well-known/nostr.json?name=_",
relay.domain()
))
.header("Accept", "application/nostr+json, application/json")
.send()
.await
.expect("request NIP-05 root identity");
assert_eq!(response.status(), reqwest::StatusCode::OK);
assert_eq!(
response
.headers()
.get(reqwest::header::ACCESS_CONTROL_ALLOW_ORIGIN)
.and_then(|value| value.to_str().ok()),
Some("*")
);
assert!(response
.headers()
.get(reqwest::header::CONTENT_TYPE)
.and_then(|value| value.to_str().ok())
.is_some_and(|value| value.starts_with("application/json")));
let nip05: serde_json::Value = response.json().await.expect("parse NIP-05 document");
let root_pubkey = nip05["names"]["_"]
.as_str()
.expect("NIP-05 document should map the root identifier");
assert_eq!(root_pubkey.len(), 64);
assert!(root_pubkey
.chars()
.all(|character| character.is_ascii_digit() || ('a'..='f').contains(&character)));
let nip11: serde_json::Value = client
.get(format!("http://{}", relay.domain()))
.header("Accept", "application/nostr+json")
.send()
.await
.expect("request NIP-11 document")
.json()
.await
.expect("parse NIP-11 document");
assert_eq!(nip11["pubkey"], root_pubkey);
assert!(nip11["supported_nips"]
.as_array()
.expect("supported_nips should be an array")
.contains(&serde_json::json!(5)));
let nested_nip11 = client
.get(format!("http://{}/relay", relay.domain()))
.header("Accept", "application/nostr+json")
.send()
.await
.expect("request NIP-11 document at an unconfigured relay path");
assert_eq!(nested_nip11.status(), reqwest::StatusCode::NOT_FOUND);
let nested_response = client
.get(format!(
"http://{}/repository/.well-known/nostr.json?name=_",
relay.domain()
))
.send()
.await
.expect("request a non-root well-known path");
assert_eq!(nested_response.status(), reqwest::StatusCode::NOT_FOUND);
relay.stop().await;
}