test(sync): cover URL hygiene with stricter SDK parsing

The pinned SDK rejects relay URLs above 1 KiB before our independent
2 KiB raw-tag guard runs. Two tests relied on constructing such RelayUrls
and failed during fixture setup instead of exercising our boundary.

Keep the raw guard tested independently with a valid parsed target, and
assert the upstream parser also rejects the oversized input. Use generic
URL parsing only to demonstrate normalization shortening the wire form.
No production limit or rejection rule changes.

Validation: all nine target_hygiene unit tests pass. The full suite found
only these two fixture failures in the completed server library run.
This commit is contained in:
DanConwayDev
2026-09-12 16:03:09 +00:00
parent 99adfcbf66
commit 7a960efda4
+12 -5
View File
@@ -287,8 +287,13 @@ mod tests {
"a".repeat(MAX_PEER_RELAY_URL_BYTES - base.len())
);
assert_eq!(at_limit.len(), MAX_PEER_RELAY_URL_BYTES);
assert!(!rejected(&at_limit));
assert!(rejected(&format!("{at_limit}a")));
// The SDK now rejects URLs above 1 KiB before this layer runs.
// Exercise our independent raw-byte guard using an ordinary parsed
// target, without relying on construction of an oversized RelayUrl.
let parsed = relay(base);
assert!(RelayUrl::parse(&at_limit).is_err());
assert_eq!(rejection_reason(&at_limit, &parsed, &strict()), None);
assert!(rejection_reason(&format!("{at_limit}a"), &parsed, &strict()).is_some());
}
#[test]
@@ -302,9 +307,11 @@ mod tests {
"a".repeat(MAX_PEER_RELAY_URL_BYTES + 1 - base.len())
);
assert_eq!(oversized.len(), MAX_PEER_RELAY_URL_BYTES + 1);
let parsed = relay(&oversized);
assert!(parsed.as_str().len() <= MAX_PEER_RELAY_URL_BYTES);
assert!(rejection_reason(&oversized, &parsed, &strict()).is_some());
let normalized = Url::parse(&oversized).unwrap();
assert!(normalized.as_str().len() <= MAX_PEER_RELAY_URL_BYTES);
assert!(RelayUrl::parse(&oversized).is_err());
// Raw-byte rejection must not depend on the parsed target's length.
assert!(rejection_reason(&oversized, &relay(base), &strict()).is_some());
}
#[test]