Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4506480
fix(node): gate GET /ipfs/{cid} on reachable allowed-set, not deny-se…
Gravirei Jun 30, 2026
3aa7bf0
perf(ipfs): check object existence before allowed-blob walk
Gravirei Jun 30, 2026
63580c7
refactor(ipfs): improve formatting and readability in get_by_cid func…
Gravirei Jun 30, 2026
002f354
refactor(ipfs): streamline object retrieval by separating type and co…
Gravirei Jun 30, 2026
f2c91a8
docs(ipfs): update get_by_cid comment to reflect split object retrieval
Gravirei Jul 1, 2026
0b7c494
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 1, 2026
03ba714
Run cargo fmt on store.rs
Gravirei Jul 1, 2026
03c90f8
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 2, 2026
94bb216
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 3, 2026
79650df
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 5, 2026
26d8d48
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 6, 2026
8c51c63
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 7, 2026
69d64c5
Merge remote-tracking branch 'upstream/main'
Gravirei Jul 9, 2026
8d0f41c
test(gl): add tests for iCaptcha transparent retry flow (#167)
Gravirei Jul 9, 2026
cb8761d
fix(clippy): remove redundant borrow in format! arg
Gravirei Jul 9, 2026
d98e202
fix(review): use runtime GITLAWB_ICAPTCHA_INSECURE flag instead of cf…
Gravirei Jul 9, 2026
41d277e
fix(review): set mock expectations at creation time, tighten insecure…
Gravirei Jul 9, 2026
5698c2e
fix(test): serialize icaptcha integration tests with global Mutex to …
Gravirei Jul 9, 2026
edaf238
fix(icaptcha): compare origins (scheme+host+port) in resolve_solver_u…
Gravirei Jul 10, 2026
2f25fb3
fix(test): save/restore inherited iCaptcha env vars instead of uncond…
Gravirei Jul 10, 2026
58769e7
fix(test): constrain negative send_once mocks with Matcher::Missing s…
Gravirei Jul 10, 2026
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
fix(review): use runtime GITLAWB_ICAPTCHA_INSECURE flag instead of cf…
…g(test), add mock assertions
  • Loading branch information
Gravirei committed Jul 9, 2026
commit d98e20247d1df4c58fbcc671f04fd60d3883d2a4
49 changes: 32 additions & 17 deletions crates/gl/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,27 +411,31 @@ mod tests {

// ── send_signed iCaptcha retry (full integration) ────────────────────

/// Helper: set GITLAWB_ICAPTCHA_URL so the iCaptcha client trusts the mock
/// server URL and clean it up on drop.
/// Set GITLAWB_ICAPTCHA_URL and GITLAWB_ICAPTCHA_INSECURE so the iCaptcha
/// client trusts a local mockito HTTP server, cleaning them up on drop.
struct IcaptchaEnv;

impl IcaptchaEnv {
fn new(url: &str) -> Self {
std::env::set_var("GITLAWB_ICAPTCHA_URL", url);
std::env::set_var("GITLAWB_ICAPTCHA_INSECURE", "1");
IcaptchaEnv
}
}

impl Drop for IcaptchaEnv {
fn drop(&mut self) {
std::env::remove_var("GITLAWB_ICAPTCHA_URL");
std::env::remove_var("GITLAWB_ICAPTCHA_INSECURE");
}
}

/// Helper: set up a mock iCaptcha server that responds to challenge + answer.
/// Set up a mock iCaptcha server that responds to challenge + answer.
/// The caller MUST call `.assert()` on the returned mocks after the test
/// action to verify they were actually hit by the solve loop.
struct MockIcaptcha {
_c: mockito::Mock,
_a: mockito::Mock,
challenge: mockito::Mock,
answer: mockito::Mock,
_guard: IcaptchaEnv,
url: String,
}
Expand All @@ -440,7 +444,7 @@ mod tests {
async fn new(server: &mut mockito::ServerGuard) -> Self {
let url = server.url();
let guard = IcaptchaEnv::new(&url);
let _c = server
let challenge = server
.mock("POST", "/v1/challenge")
.with_status(200)
.with_header("content-type", "application/json")
Expand All @@ -449,16 +453,16 @@ mod tests {
)
.create_async()
.await;
let _a = server
let answer = server
.mock("POST", "/v1/answer")
.with_status(200)
.with_header("content-type", "application/json")
.with_body(r#"{"status":"passed","proof":"mock.proof"}"#)
.create_async()
.await;
Self {
_c,
_a,
challenge,
answer,
_guard: guard,
url,
}
Expand All @@ -469,23 +473,25 @@ mod tests {
async fn send_signed_solves_icaptcha_and_retries_to_success() {
let mut node = Server::new_async().await;
let mut icaptcha = Server::new_async().await;
let _ic = MockIcaptcha::new(&mut icaptcha).await;
let ic = MockIcaptcha::new(&mut icaptcha).await;

let _n1 = node
let n1 = node
.mock("POST", "/api/register")
.with_status(403)
.with_header("content-type", "application/json")
.with_header("x-icaptcha-url", &_ic.url)
.with_header("x-icaptcha-url", &ic.url)
.with_header("x-icaptcha-level", "3")
.with_body(r#"{"error":"icaptcha_proof_required"}"#)
.expect(1)
.create_async()
.await;
let _n2 = node
let n2 = node
.mock("POST", "/api/register")
.match_header("x-icaptcha-proof", mockito::Matcher::Any)
.with_status(201)
.with_header("content-type", "application/json")
.with_body(r#"{"status":"created"}"#)
.expect(1)
.create_async()
.await;

Expand All @@ -495,23 +501,29 @@ mod tests {
.await
.unwrap();
assert_eq!(resp.status(), 201);
n1.assert();
n2.assert();
ic.challenge.assert();
ic.answer.assert();
}

#[tokio::test]
async fn send_signed_returns_403_after_icaptcha_retries_exhausted() {
let mut node = Server::new_async().await;
let mut icaptcha = Server::new_async().await;
let _ic = MockIcaptcha::new(&mut icaptcha).await;
let ic = MockIcaptcha::new(&mut icaptcha).await;

// Every call to the node returns 403 with iCaptcha headers, exhausting
// MAX_ICAPTCHA_RETRIES (2). The original + 2 retries = 3 node calls.
let _n = node
// MAX_ICAPTCHA_RETRIES (2). The original + 2 retries → 3 node calls,
// each triggering a fresh challenge/answer cycle (2 cycles = 2 each).
let n = node
.mock("POST", "/api/register")
.with_status(403)
.with_header("content-type", "application/json")
.with_header("x-icaptcha-url", &_ic.url)
.with_header("x-icaptcha-url", &ic.url)
.with_header("x-icaptcha-level", "3")
.with_body(r#"{"error":"icaptcha_proof_required"}"#)
.expect(3)
.create_async()
.await;

Expand All @@ -521,5 +533,8 @@ mod tests {
.await
.unwrap();
assert_eq!(resp.status(), 403);
n.assert();
ic.challenge.expect(2).assert();
ic.answer.expect(2).assert();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
}
16 changes: 8 additions & 8 deletions crates/icaptcha-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ fn sanitize_excerpt(s: &str) -> String {
}

/// Whether `u` parses as a trusted URL (https in production; also allows
/// localhost/127.0.0.1 in tests so the full iCaptcha retry path can be
/// exercised against a mockito server).
/// http://127.0.0.1 and http://localhost when `GITLAWB_ICAPTCHA_INSECURE` is
/// set, so the full iCaptcha retry path can be exercised against a mockito
/// server in integration tests without shipping the backdoor to production).
fn is_https(u: &str) -> bool {
let parsed = reqwest::Url::parse(u);
if parsed
Expand All @@ -93,12 +94,11 @@ fn is_https(u: &str) -> bool {
{
return true;
}
// Allow local test servers in test builds (mockito runs on 127.0.0.1:PORT).
#[cfg(test)]
if parsed
.as_ref()
.map(|p| p.host_str() == Some("127.0.0.1") || p.host_str() == Some("localhost"))
.unwrap_or(false)
if std::env::var_os("GITLAWB_ICAPTCHA_INSECURE").is_some()
&& parsed
.as_ref()
.map(|p| p.host_str() == Some("127.0.0.1") || p.host_str() == Some("localhost"))
.unwrap_or(false)
{
return true;
}
Expand Down
Loading