From b5a5aa1c1984ae7080dfc84a17fac4b1c8a56b7f Mon Sep 17 00:00:00 2001 From: Vadim Anufriev Date: Sun, 24 May 2026 19:36:09 +0400 Subject: [PATCH 1/2] fix(cli): accept v1 endpoint with implicit port State the port check's single invariant directly: `--port 0` (let the OS pick) is incompatible with a `--pj-endpoint` URL that pins a specific port. --- payjoin-cli/src/app/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/payjoin-cli/src/app/config.rs b/payjoin-cli/src/app/config.rs index 56f3db1b0..5d3efe5eb 100644 --- a/payjoin-cli/src/app/config.rs +++ b/payjoin-cli/src/app/config.rs @@ -156,7 +156,7 @@ impl Config { { match built_config.get::("v1") { Ok(v1) => { - if v1.pj_endpoint.port().is_none() != (v1.port == 0) { + if v1.port == 0 && v1.pj_endpoint.port().is_some() { return Err(ConfigError::Message( "If --port is 0, --pj-endpoint may not have a port".to_owned(), )); From d030068057177e976dd50f3961ae74dd0b490843 Mon Sep 17 00:00:00 2001 From: Vadim Anufriev Date: Mon, 25 May 2026 15:43:07 +0400 Subject: [PATCH 2/2] test(cli): add tests for --bip78 arg --- payjoin-cli/src/app/config.rs | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/payjoin-cli/src/app/config.rs b/payjoin-cli/src/app/config.rs index 5d3efe5eb..e06d7fbb4 100644 --- a/payjoin-cli/src/app/config.rs +++ b/payjoin-cli/src/app/config.rs @@ -362,3 +362,50 @@ where .map(Some), } } + +#[cfg(all(test, feature = "v1"))] +mod tests { + use clap::Parser; + + use super::*; + use crate::cli::Cli; + + fn cli(port: &str, endpoint: &str) -> Cli { + Cli::parse_from([ + "payjoin-cli", + "--bip78", + "--port", + port, + "--pj-endpoint", + endpoint, + "receive", + "50000", + ]) + } + + #[test] + fn rejects_random_port_with_explicit_endpoint_port() { + let err = Config::new(&cli("0", "https://example.com:443/")).unwrap_err(); + assert!(err.to_string().contains("port"), "unexpected error: {err}"); + } + + #[test] + fn accepts_random_port_with_implicit_endpoint_port() { + Config::new(&cli("0", "https://example.com/")).unwrap(); + } + + #[test] + fn accepts_explicit_port_with_implicit_endpoint_port() { + Config::new(&cli("3000", "https://example.com/")).unwrap(); + } + + #[test] + fn accepts_explicit_port_with_matching_explicit_endpoint_port() { + Config::new(&cli("3000", "https://example.com:3000/")).unwrap(); + } + + #[test] + fn accepts_explicit_port_with_different_explicit_endpoint_port() { + Config::new(&cli("3000", "https://example.com:443/")).unwrap(); + } +}