test(api-gateway): unit tests for OIDC auth-config + CLI (crate ~0%→71%)#1327
test(api-gateway): unit tests for OIDC auth-config + CLI (crate ~0%→71%)#1327SharedQA wants to merge 7 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR expands api-gateway test coverage for auth config responses, CLI argument parsing, and proxy forwarding behavior, while extracting shared auth response construction logic and updating test dependencies for JSON-based assertions. ChangesAPI gateway coverage expansion
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Please wait for a while, the project is migrating to gears version, so there will be some changes. |
…s (22 tests) Rebased onto main after the cf-modkit -> cf-gears-toolkit migration (constructorfabric#1314), which restructured these files. Adapts the suite to the gears API: - auth_info: re-extract AuthInfoResponse::from_config as a pure fn (called by register_rest) so scope-splitting / response_type / config parsing stay unit-testable; constructorfabric#1314 had inlined it into the gear method. 9 tests. - proxy: keep is_hop_by_hop, RouteConfig/ProxyConfig defaults, and forward_request plumbing (prefix strip, query, end-to-end headers). The unreachable-upstream path is now a canonical 503 (was 502); assert that. Drop the not_found_problem / RFC9457 fallback tests — gears removed that helper (404 fallback 'not yet wired up against cf-gears-api-gateway'). 8 tests. - main: clap CLI surface — subcommands, flags, verbosity, unknown-flag. 5 tests. - Cargo.toml: swap unused tower dev-dep for serde_json. cargo test + clippy -D warnings + fmt all clean against current main. Signed-off-by: Kenan Salim <kenan.salim@rolos.com>
a6f1e8f to
a30cd77
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/backend/services/api-gateway/src/proxy.rs (1)
466-469: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert hop-by-hop header removal explicitly.
Line 467 currently verifies
authorizationforwarding, but this test doesn’t proveconnectionwas dropped. Add a second assertion forconnectionabsence so the test matches its name and intent.Proposed test tightening
- let upstream = Router::new().route( - "/v1/h", - get(|headers: axum::http::HeaderMap| async move { - let auth = headers.contains_key("authorization"); - (StatusCode::OK, format!("auth={auth}")) - }), - ); + let upstream = Router::new().route( + "/v1/h", + get(|headers: axum::http::HeaderMap| async move { + let auth = headers.contains_key("authorization"); + let conn = headers.contains_key("connection"); + (StatusCode::OK, format!("auth={auth};conn={conn}")) + }), + ); @@ - assert_eq!( - &body[..], - b"auth=true", - "authorization forwarded end-to-end" - ); + assert_eq!(&body[..], b"auth=true;conn=false");Also applies to: 474-485
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/backend/services/api-gateway/src/proxy.rs` around lines 466 - 469, The test handler in the anonymous route handler starting at line 466 currently only checks for the presence of the "authorization" header but does not verify that the "connection" hop-by-hop header was removed as intended. Modify the handler to also check for the absence of the "connection" header and include both checks in the response format (e.g., "auth={auth},connection={has_connection}"). This will ensure the test explicitly verifies both that authorization headers are forwarded and that hop-by-hop headers like connection are properly dropped, matching the test's intended purpose. Apply the same fix to the other similar test cases mentioned in the comment range.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/backend/services/api-gateway/src/proxy.rs`:
- Around line 466-469: The test handler in the anonymous route handler starting
at line 466 currently only checks for the presence of the "authorization" header
but does not verify that the "connection" hop-by-hop header was removed as
intended. Modify the handler to also check for the absence of the "connection"
header and include both checks in the response format (e.g.,
"auth={auth},connection={has_connection}"). This will ensure the test explicitly
verifies both that authorization headers are forwarded and that hop-by-hop
headers like connection are properly dropped, matching the test's intended
purpose. Apply the same fix to the other similar test cases mentioned in the
comment range.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5f7793e8-538b-4f5d-8405-b83b6b334f15
⛔ Files ignored due to path filters (1)
src/backend/Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (4)
src/backend/services/api-gateway/Cargo.tomlsrc/backend/services/api-gateway/src/auth_info.rssrc/backend/services/api-gateway/src/main.rssrc/backend/services/api-gateway/src/proxy.rs
…t just auth forwarded The test named ..._forwards_end_to_end_headers_not_hop_by_hop only checked that authorization (end-to-end) reached upstream; it never proved connection (hop-by-hop) was stripped, so it didn't test the second half of its own name. Upstream now also reports the connection header and the test asserts auth=true;conn=false. Verified: passes (the gateway does strip it); clippy -D warnings clean. Signed-off-by: Kenan Salim <ks@constructor.tech>
|
OIDC and API Gateway are reworked in scope of #1583 |
Unit-test coverage for the
api-gatewaycrate, the workspace's biggest unit gap (was 2 tests, onlyproxy.rspartial).Result (measured,
cargo-llvm-cov)auth_info.rsmain.rs(CLI)proxy.rscore_types.rs27 tests pass;
cargo clippy --all-targets --all-featuresclean (nounwrap/expectin tests, per the workspace lint).What's covered
AuthInfoResponse::from_config(scopes split on whitespace,response_typepinned tocode, field passthrough); configdefault+deny_unknown_fields; JSON wire-shape roundtrip.run, all subcommands,-v/-vvcount,--config/-c,--print-config, unknown-subcommand rejection, clap self-check.Not unit-tested
main()→run_server/run_migrate,register_rest, andcore_types::initneed the livemodkitruntime (ModuleCtx, client hub) — that's integration scope (tracked separately), not unit. This PR covers the crate's pure/testable surface.Opened as draft for review before it's marked ready.
Summary by CodeRabbit
Release Notes