Skip to content

test(icaptcha-client): bind new()'s empty-API-key filter (#216) - #245

Open
beardthelion wants to merge 1 commit into
mainfrom
test/icaptcha-empty-key-filter
Open

test(icaptcha-client): bind new()'s empty-API-key filter (#216)#245
beardthelion wants to merge 1 commit into
mainfrom
test/icaptcha-empty-key-filter

Conversation

@beardthelion

@beardthelion beardthelion commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a guard test that drives an empty GITLAWB_ICAPTCHA_API_KEY through IcaptchaCfg::new on a trusted operator origin and asserts it normalizes to None, with a contrast arm showing a real key still attaches.

Motivation & context

Closes #216

new() normalizes an empty key to None via .filter(|s| !s.is_empty()) (crates/icaptcha-client/src/lib.rs:213). No test exercised the empty-string value, so dropping the filter shipped green and a trusted-origin solve would send an empty bearer token on the challenge and answer requests (lib.rs:317, lib.rs:342).

Kind of change

  • Bug fix
  • Feature
  • Security fix
  • Docs
  • Tests / CI
  • Refactor (no behavior change)
  • Breaking or protocol change (issue required first)

What changed

  • crates/icaptcha-client/src/lib.rs: added new_normalizes_empty_api_key_to_none_on_trusted_origin

How a reviewer can verify

cargo test -p icaptcha-client

Mutation check: remove .filter(|s| !s.is_empty()) from the api_key read in new(). The new test fails; the other 21 lib tests stay green.

Before you request review

Protocol & signing impact

No protocol impact.

Notes for reviewers

The test follows the same env-handling pattern as the sibling tests in the file: it saves and restores both env vars and releases ICAPTCHA_ENV_LOCK before asserting, so a failure cannot poison the shared lock or cascade into a sibling.

Summary by CodeRabbit

  • Tests
    • Added coverage confirming that an empty CAPTCHA API key is treated as unset for trusted origins.
    • Verified that non-empty API keys remain preserved.

IcaptchaCfg::new normalizes an empty GITLAWB_ICAPTCHA_API_KEY to None
via .filter(|s| !s.is_empty()) before storing api_key. No test drove
the empty-string value through new(), so a regression would attach an
empty bearer token to the challenge and answer requests and ship green.

The new test drives an empty key through new() on a trusted operator
origin and asserts it normalizes to None, with a contrast arm showing
a real key still attaches. Mutation check: removing the filter fails
this test and no other.
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 91782455-fe51-40bf-8b51-235c39878a9f

📥 Commits

Reviewing files that changed from the base of the PR and between 111cff7 and f35d9a7.

📒 Files selected for processing (1)
  • crates/icaptcha-client/src/lib.rs

📝 Walkthrough

Walkthrough

Adds a unit test covering empty API key normalization and preservation of non-empty keys for trusted iCaptcha origins, with environment isolation and restoration.

Changes

iCaptcha API key normalization coverage

Layer / File(s) Summary
Trusted-origin API key normalization test
crates/icaptcha-client/src/lib.rs
Adds coverage verifying an empty GITLAWB_ICAPTCHA_API_KEY becomes None, while a non-empty value remains present, with environment state restored after the test.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related issues

Possibly related PRs

  • Gitlawb/node#213 — Adds related IcaptchaCfg::new tests for origin-scoped API key behavior.
  • Gitlawb/node#168 — Adds iCaptcha client coverage around environment-derived trust and API key handling.

Suggested labels: kind:test, kind:bug

Suggested reviewers: kevincodex1

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the PR's main change: a regression test for empty API-key normalization in icaptcha-client.
Description check ✅ Passed The description follows the template and fills the required sections with a clear summary, motivation, change list, and verification steps.
Linked Issues check ✅ Passed The added test matches #216 by covering empty API-key normalization, preserving a real key, and using the shared env lock.
Out of Scope Changes check ✅ Passed The PR stays within scope by changing only the icaptcha-client test file and introducing no unrelated behavior changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/icaptcha-empty-key-filter

Comment @coderabbitai help to get the list of available commands.

@beardthelion beardthelion added the kind:test Test coverage or harness label Jul 23, 2026

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@beardthelion

Copy link
Copy Markdown
Collaborator Author

@kevincodex1 ready for merge. jatmn approved the current head (f35d9a7), CI is green. Test-only change: binds the empty-API-key filter in new() per #216.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:test Test coverage or harness

Projects

None yet

Development

Successfully merging this pull request may close these issues.

icaptcha-client: no test binds new()'s empty-API-key filter, so a Some("") regression would ship green

2 participants