fix(error): map vertex/azure credential-validity errors to 401, not 500 (follow-up to #511) - #515
Conversation
…ollow-up to #367/#511) #511 split customer-fixable upstream config into 400 (invalid_request_error) vs 401 (authentication_error) for credential material, but two pre-existing credential checks still mapped to Config → HTTP 500, inconsistent with the empty-secret/invalid-key cases on the other providers (now 401): - VertexSecret::parse: empty secret, malformed JSON, empty access_token, both-modes-set, neither-mode-set → InvalidUpstreamCredentials (401). - Azure AAD AadCredentials::validate: empty tenant_id/client_id/client_secret and URL-control chars in tenant/client → InvalidUpstreamCredentials (401); authority_host URL-shape guards (scheme/userinfo/embedded-path) → InvalidUpstreamConfig (400), matching #367's api_base-shape treatment. Runtime token-mint/HTTP fetch failures and internal invariants stay Config (500). Unit tests updated to assert the new status classes.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR reclassifies credential and configuration validation errors in Azure AAD and Vertex provider implementations from generic ChangesCredential and Configuration Validation Error Reclassification
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
Problem
PR #511 (closing #367) introduced
BridgeError::InvalidUpstreamCredentials→ 401authentication_errorfor customer-supplied credential problems (empty secret, invalid api-key header bytes, malformed credential JSON), keeping 400invalid_request_errorfor request/config shape. But two pre-existing credential checks in Vertex and Azure still mapped toBridgeError::Config→ HTTP 500, inconsistent with the empty-secret/invalid-key cases on the other providers (now 401) and with the issue's intent.Fix
Credential-material validity → 401
InvalidUpstreamCredentials:VertexSecret::parse— empty secret, malformed JSON, emptyaccess_token, both-modes-set, neither-mode-set.AadCredentials::validate— emptytenant_id/client_id/client_secret, and URL-control characters intenant_id/client_id.Config/URL shape → 400
InvalidUpstreamConfig(matching #367'sapi_base-shape treatment):authority_hostguards (must have http(s) scheme, no userinfo/query/fragment, no embedded path).Runtime token-mint / HTTP token-fetch failures and internal invariants intentionally stay
Config→ 500 (we caused them, not the customer).Tests
Unit tests in
aisix-provider-vertex(6 secret-parse + chat-before-dispatch) andaisix-provider-azure-openai(empty-field, URL-injection, authority_host shape) updated to assert the new 401/400 classes. Admin schema already rejects an emptysecretbefore dispatch, so these are unit-level (no e2e change). vertex (69) + azure (93) suites green; clippy-D warningsclean.🤖 Generated with Claude Code
Summary by CodeRabbit