From 4f6bba8aa75e0a35393167dd305177474ccd8b76 Mon Sep 17 00:00:00 2001 From: TaprootFreak <142087526+TaprootFreak@users.noreply.github.com> Date: Tue, 2 Jun 2026 01:47:46 +0200 Subject: [PATCH] test(router/lnurl): cover localhost branch of lnurlp_handler scheme selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit lnurlp_handler picks http:// for hosts containing 'localhost' and https:// otherwise. The https arm is already pinned by lnurlp_known_address_returns_pay_request; the http arm (router.rs:2647) was uncovered, which broke the 100%-line coverage gate at 3265/3266 lines = 99.97%. New test lnurlp_localhost_host_returns_http_callback issues the same .well-known/lnurlp/ request the existing test does, but with Host: localhost:8080, and asserts the callback URL starts with http://localhost:8080/. Closes the 1-line gap without changing production code. Surfaced as part of the dfxai runner pool smoke test on PR #169 — see DFXServer/server commit 4347a4a for the new dfxai CI host. --- node/src/router_tests.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/node/src/router_tests.rs b/node/src/router_tests.rs index f1e373da..651b30e5 100644 --- a/node/src/router_tests.rs +++ b/node/src/router_tests.rs @@ -499,6 +499,38 @@ async fn lnurlp_known_address_returns_pay_request() { assert!(resp.metadata.contains("zkCoins")); } +#[cfg(feature = "lnurl")] +#[tokio::test] +async fn lnurlp_localhost_host_returns_http_callback() { + // Pins the `host.contains("localhost")` branch of `lnurlp_handler`'s + // scheme selection: when the request's Host header points at a local + // dev instance, the LNURL callback URL must be served back as `http://` + // so wallets following the redirect don't hit a TLS error against + // the dev node. The api.zkcoins.app path (covered by + // `lnurlp_known_address_returns_pay_request`) already pins the + // `https://` arm. + let full_hex = hex::encode(zkcoins_program::hash::digest_to_bytes( + &zkcoins_program::types::MINTING_ADDRESS, + )); + let prefix = &full_hex[..8]; + + let uri = format!("/.well-known/lnurlp/{}", prefix); + let req = Request::get(&uri) + .header("host", "localhost:8080") + .body(Body::empty()) + .unwrap(); + let (status, body) = send_request(req).await; + + assert_eq!(status, StatusCode::OK); + + let resp: LnurlpResponse = serde_json::from_str(&body).expect("valid JSON"); + assert!( + resp.callback.starts_with("http://localhost:8080/"), + "callback should use http://localhost:8080 — got {}", + resp.callback + ); +} + // --- GET /lnurl/pay/{username} --- #[cfg(feature = "lnurl")]