Repository navigation
fix: address v0.21.0 pre-release findings - #694
Conversation
`reject_invalid_tokens` only applies to schemes naming FOCA's `validate_token`, so functions wrapping it silently get no effect. Warn at startup, once per function, for operations with optional authentication. Refs #693 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The job is part of the gate, so a new uv could fail unrelated pull requests. It now uses the version of `test-lowest` (0.13.4), from a workflow-level variable; the requirements check passes with it. The composite action of the chart install keeps its own pin, as it's also used outside this workflow. Refs #693 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Run the gateway example a second time with `trust_incoming: false`, and test the response header and a client's value through Gunicorn under both settings. Both are set explicitly, so that the test doesn't depend on the default. Refs #693 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add fatal `log` sections, the log of invalid responses, `is_admin()` and resources without owners, stored documents failing lists, the foca-plugins cap and the chart, with `PORT` and duplicates of `extraEnv`. Narrow the claim on the audit log and list the themes. Refs #693 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The chart sets `PORT` from foca-common 0.5.0. `foca` can't target apps whose factory returns the Connexion app, and what such a factory does runs before the command exits with 2. The comments on the release's assets now also name the image requirements. Refs #693 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The warning now also covers `x-tokenInfoFunc`, and its remedy holds for OAuth 2.0 schemes. In the guide, separate the changed log texts, narrow the heading of the fatal `log` checks, and list what the library's checks mean for charts with their own `extraEnv`. The integration test checks the form of generated identifiers. Refs #693 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR addresses v0.21.0 pre-release findings by documenting migration-impacting behavior, adding optional-token diagnostics and gateway request-ID coverage, aligning deployment/CI documentation and uv configuration, and clarifying release workflow expectations. Sequence diagram for optional-token validator warningssequenceDiagram
participant App as Application startup
participant Resolver as InvalidTokenResolver
participant Operation as Connexion operation
participant Logger as foca.security.auth logger
App->>Resolver: resolve(operation)
Resolver->>Operation: _validates_optional_token(operation)
alt Optional token validation is not handled by FOCA
Resolver->>Operation: _other_token_validators(operation)
Operation-->>Resolver: validator function names
Resolver->>Logger: warning(function)
else FOCA handles optional bearer validation
Resolver-->>App: Resolution with _reject_invalid_token
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #694 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 65 65
Lines 8511 8523 +12
=========================================
+ Hits 8511 8523 +12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="foca/security/auth.py" line_range="371-372" />
<code_context>
"""
resolution = self.resolver.resolve(operation)
if not _validates_optional_token(operation):
+ self._warn_other_validators(operation)
return resolution
return Resolution(
</code_context>
<issue_to_address>
**Other validators receive no warning**
When an optional operation has a FOCA bearer scheme and another scheme with a validator function, `_validates_optional_token(operation)` returns true, so `resolve()` skips `_warn_other_validators()` and the other validator receives no warning despite the documented warning contract.
Check for uncovered validator functions before treating the operation as covered by the FOCA bearer validator.
Also at `docs/authentication.md:92-94`.
</issue_to_address>Linked issues
#693 fix: address v0.21.0 pre-release review findings · 14 of 14 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Add an intro listing the migration themes and the missing blank line before ## Audit log. |
✅ Met | The intro lists the themes, and the Audit log section is separated by a blank line. |
| 2 | Document that invalid log sections now stop the app rather than falling back with a warning. |
✅ Met | The guide explains which unknown filters and handlers fail validation and gives an example fix. |
| 3 | Document the changed log text for invalid responses. | ✅ Met | The guide describes the filtered Connexion message and the replacement FOCA error log. |
| 4 | Document that foca-common 0.5.0 is unreleased, apps may stay on 0.4.0, it sets and reserves PORT, and charts that add extraEnv themselves render duplicates. |
✅ Met | These details are covered in the App charts section, including the proTES example. |
| 5 | Document when is_admin() is False for custom models and that admins can reach resources without owners through ownership_server. |
✅ Met | The guide covers the required matcher prefix and the ownerless-resource operations. |
| 6 | Document that one stored document can fail a whole list, including for uri values. |
✅ Met | The stricter request checks section gives a uri example and explains that the list can return 500. |
| 7 | Document the foca-plugins version cap and the order: FOCA tag, foca-plugins with <0.22 tested against 0.21, then proTES. |
✅ Met | The guide describes the cap, the tested <0.22 sequence, and identifies proTES as an affected app. |
| 8 | Narrow the audit-log claim to exclude configured rules, foca sync-policies, and policies_force. |
✅ Met | The guide states that these changes leave no audit event. |
| 9 | Add an integration test for X-Request-ID and a client-supplied value under both trust_incoming settings. |
✅ Met | The parametrized test checks both app instances, including generated IDs and client-supplied IDs. |
| 10 | Make foca/gunicorn_config.py, docs/deployment.md, and the migration guide’s App charts section agree with the chart on PORT. |
✅ Met | The comment and both documentation sections describe the chart setting PORT to the Service port. |
| 11 | Document that apps whose factory returns the Connexion app cannot be targeted by the CLI, and that the factory’s writes happen before foca exits with 2. |
✅ Met | The CLI guide states both limitations and gives the required app change. |
| 12 | Update the release-step comments to mention the image requirements as well as distributions. | ✅ Met | The release workflow comment now names both distributions and image requirements. |
| 13 | Warn at startup when reject_invalid_tokens cannot apply to optional-token validator functions. |
✅ Met | The resolver warns for other x-bearerInfoFunc and x-tokenInfoFunc functions, once per function per resolver/specification. |
| 14 | Pin uv for image-constraints in one shared place with test-lowest. |
✅ Met | Both jobs use the workflow-level UV_VERSION value of 0.13.4. |
Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: foca/security/auth.py:372
Debug records of PyMongo's background threads, left by earlier tests, could land in `caplog.text` and fail these tests at random. Only look at FOCA's records. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Operations with both FOCA's and another function do get the option, and no warning. Refs #693 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes #693
Summary
Fixes findings of the v0.21.0 pre-release review.
logstop the app; the log of invalid responses;is_admin()with the required matcher prefix and resources without owners; one stored document fails a whole list, also forurivalues; the foca-plugins cap, with the order FOCA tag, foca-plugins with<0.22tested against 0.21, then proTES; foca-common 0.5.0 being unreleased, with apps free to stay on 0.4.0, plusPORTand the duplicates ofprotes.extraEnv; the audit claim narrowed to what it covers; the heading spacing.test_request_id_headerchecks the response header and a client's value through Gunicorn under bothtrust_incomingsettings. The gateway example runs a second app (app-no-trust, port 8082, overlayno-trust.yaml) and setstrueexplicitly in its config, so the test doesn't depend on the default.PORTdocs:foca/gunicorn_config.py,docs/deployment.mdand the guide's "App charts" now agree with the chart.image-constraintsandtest-lowestuse one workflow-levelUV_VERSION, 0.13.4, whichtest-lowestalready used. The composite action of the chart install keeps its own pin, also 0.13.4, asrelease-chart.ymluses it too; a comment links the two.reject_invalid_tokens: startup warns, once per function and specification, of functions on operations with optional authentication that the option doesn't reach.docs/cli.mdstates that apps whose factory returns the Connexion app can't be targeted, and that the factory's own work runs beforefocaexits with 2.Not in this PR, left for the maintainer: the default of
trust_incominganddocs/configuration/server.md:86-95, so the guide doesn't name that option yet; release prep; the dry run; #528; #625 and PR 691. The release checklist also doesn't get the foca-plugins step.Verification
Locally on Python 3.12 with MongoDB 7.0.34:
coverage run -m pytest: 4244 passed, 3 skipped, 100% coverage. Run before the last review round; after it,tests/security/test_optional_tokens.pyandtests/examples/test_gateway.pypassed (48).ruff check,ruff format --check,mypy,ast-grep scan,semgrep scan --config .semgrep --error,mkdocs build --strict: all clean.pre-commit run --files <15 changed files>: passed.tests/integration_gateway_tests.pyagainstdocker composeof the gateway example: 8 passed, before the last round, which tightened the test's assertions on generated identifiers. CI runs the final version.scripts/compile-image-requirements.sh --checkwith uv 0.13.4: passed.actionlintonci.ymlandrelease.yml: clean.Not run locally: chart tests and chart install (no usable Helm), the petstore integration test, other Python versions, MongoDB 8.0, the release workflow.
CI on 816d968: all 29 checks passed, including the gateway integration tests with the final test on Python 3.13 and 3.15;
Push image,Publish imageandTrivyreported as skipped.CI on db3ad81, the merged head: all 30 checks passed; the same three skipped.
Unrelated fixes
tests/security/test_auth.py: two assertions oncaplog.textfailed at random on debug records of PyMongo's background threads (one CI run on Python 3.12). They now look at FOCA's records only.Declined review findings
dev: wrong.charts/foca-common/templates/_deployment.tplondevsetsPORT, and_helpers.tplhasfoca-common.extraEnv.- {None}fails mypy: mypy passed; the code was rewritten anyway whenx-tokenInfoFuncwas added.security_schemes=Noneand unknown schemes: these aren't separate branches for coverage, and the existing_validates_optional_tokenhas the same defensive shape.release-chart.yml, whereci.yml's variable doesn't exist; changing that workflow is out of scope. The comment states the link.BEARERINFO_FUNC: it's in the environment, not the specification; the docs say it gets no warning.Open questions
None.
🤖 Generated with Claude Code