Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(icaptcha-client): cover operator+hostile-advert and no-operator+…
…no-advert arms
  • Loading branch information
Gravirei committed Jul 20, 2026
commit 82fec97a97d39a44c8a2f8b60ebaacbf933526ac
32 changes: 32 additions & 0 deletions crates/icaptcha-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,11 @@ mod tests {
let untrusted =
IcaptchaCfg::new("did:key:zTEST", Some("https://evil.example".into()), None);

// Arm 1b: No operator configured, no URL advertised. The fallback goes
// to the default public origin, and with no operator to trust, the key
// must not ride.
let no_operator_no_advert = IcaptchaCfg::new("did:key:zTEST", None, None);

// Arm 2: Operator origin configured and advertised — key attached.
std::env::set_var("GITLAWB_ICAPTCHA_URL", "https://icap.mynode.example");
let operator_match = IcaptchaCfg::new(
Expand All @@ -544,6 +549,14 @@ mod tests {
// and fail against the protected operator service.
let operator_fallback = IcaptchaCfg::new("did:key:zTEST", None, Some(3));

// Arm 5: Operator configured, node advertises an attacker origin.
// The advert is rejected and the solver falls back to the operator's
// own origin, which keeps the key trusted — this is the exfiltration
// scenario the test name describes (withhold key from *untrusted*
// origin, not from the operator's fallback).
let operator_hostile_advert =
IcaptchaCfg::new("did:key:zTEST", Some("https://evil.example".into()), None);

// Restore env and release the lock BEFORE asserting, so a failing
// assertion can't poison the shared lock or cascade into a sibling.
match prev_key {
Expand All @@ -565,6 +578,15 @@ mod tests {
"attacker advert must fall back to default URL"
);

assert_eq!(
no_operator_no_advert.api_key, None,
"key must not ride with no operator and no advert"
);
assert_eq!(
no_operator_no_advert.url, DEFAULT_URL,
"no-advert path without operator must resolve to default URL"
);

assert_eq!(operator_match.api_key.as_deref(), Some("secret-bearer"));
assert_eq!(operator_match.url, "https://icap.mynode.example/v1");

Expand All @@ -583,5 +605,15 @@ mod tests {
operator_fallback.url, "https://icap.mynode.example",
"no-advert path must resolve to operator URL"
);

assert_eq!(
operator_hostile_advert.api_key.as_deref(),
Some("secret-bearer"),
"key stays with operator origin when attacker advert is rejected"
);
assert_eq!(
operator_hostile_advert.url, "https://icap.mynode.example",
"hostile advert must fall back to operator URL"
);
}
}
Loading