Back-compat shim for legacy auth Settings; fix js wheel exclude#261
Merged
Conversation
2a802e3 to
9f9f10a
Compare
Contributor
Test Results624 tests 616 ✅ 6m 53s ⏱️ Results for commit 0f447dd. ♻️ This comment has been updated with latest results. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #261 +/- ##
==========================================
+ Coverage 84.85% 84.91% +0.05%
==========================================
Files 139 139
Lines 14169 14229 +60
Branches 1396 1402 +6
==========================================
+ Hits 12023 12082 +59
Misses 1706 1706
- Partials 440 441 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
6c450b6 to
616b6e0
Compare
feussy
previously approved these changes
May 4, 2026
arhamchopra
reviewed
May 4, 2026
Re-adds Settings.AUTHENTICATE / Settings.API_KEY as deprecated pass-throughs that forward onto MountAPIKeyMiddleware at Gateway.start(), restoring the pre-2.5 config surface without reverting the middleware-based auth model. Also anchors the wheel 'js' exclude with a leading slash so nested csp_gateway/server/web/templates/js/common.js ships (login/logout pages reference it). Signed-off-by: Emily <emily.barrett@cubistsystematic.com>
Hardcoded 2026-04-15 made the assertion fail once the real clock walked more than ~2 days past that date. Python's mocked datetime.now doesn't propagate to Rust's Utc::now() used by Counter.current(), so the counter measures (real_now - mocked_midnight) without bound. Derive fake_now from today's real UTC date while still exercising the '01:00 UTC' / '9 PM EDT previous evening' scenario the regression originally guarded against. Signed-off-by: Emily <emily.barrett@cubistsystematic.com>
616b6e0 to
0f447dd
Compare
arhamchopra
approved these changes
May 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Settings.AUTHENTICATE/Settings.API_KEYas deprecated compatibility shims so pre-2.5 configs keep working.Gateway._apply_legacy_auth_settings()to forward those values ontoMountAPIKeyMiddlewareatstart()with aDeprecationWarning.jsexclude pattern with a leading slash so nestedcsp_gateway/server/web/templates/js/common.jsships — login/logout pages reference it.Background
In csp-gateway 2.4.x, auth was configured via two fields on
Settings:In 2.5 those moved onto
MountAPIKeyMiddlewareas module fields:The move itself was intentional, but nothing bridged the gap — configs written against the old layout still validated, but no code read them. Old configs silently deployed with auth effectively off.
Changes
1.
csp_gateway/server/settings.py— deprecatedAUTHENTICATE/API_KEYBoth reintroduced as
Optional[...]withdefault=None.Noneis the sentinel for "user didn't set this"; a concrete value (False,True, or a string) is what the shim acts on. Field descriptions mark them as deprecated and redirect users to the middleware.2.
csp_gateway/server/gateway/gateway.py—_apply_legacy_auth_settings()Called at the top of
Gateway.start(). Four cases:AUTHENTICATE=FalseMountAPIKeyMiddlewarefromself.modules. EmitDeprecationWarning. (Wins overAPI_KEY.)API_KEY="..."with middlewaremiddleware.api_key. EmitDeprecationWarning.AUTHENTICATE=Truewithout middlewareDeprecationWarning— the flag alone can't materialize a middleware; users need to add one tomodules.3.
pyproject.toml— wheeljsexclude is now anchoredOld pattern:
Hatchling's gitignore-style matcher treats unanchored
"js"as any directory namedjsat any depth. That matched both the top-level/js/(the React app source, which we do want excluded) ANDcsp_gateway/server/web/templates/js/, which holdscommon.jsreferenced fromlogin.html.j2/logout.html.j2. Installed wheels therefore shipped login/logout pages pointing at a file that wasn't in the wheel.New pattern:
/jsanchors to the build root — top-level source is still excluded; nestedtemplates/js/ships as intended.4.
csp_gateway/tests/server/gateway/test_gateway.py—TestLegacyAuthCompatFive tests, one per branch of the shim:
test_no_legacy_settings_is_quiet_no_optest_authenticate_false_strips_middlewaretest_api_key_forwarded_onto_middlewaretest_authenticate_false_without_middleware_is_harmlesstest_authenticate_true_without_middleware_warnsMigration notes
Users on the old layout will now get a
DeprecationWarningatstart()time that points at the new layout. No behavioral change for anyone already on the 2.5+ shape.Long-term: when we drop the shim, remove
AUTHENTICATE/API_KEYfromSettingsand delete_apply_legacy_auth_settings()+ its call site. The method docstring says the same.Test plan
pytest csp_gateway/tests/server/gateway/test_gateway.py::TestLegacyAuthCompat -vvhatch build) and confirm the login/logout template asset ships:unzip -l dist/*.whl | grep templates/js/common.jsSettings(AUTHENTICATE=False, ...)and confirm (a)DeprecationWarningis emitted and (b) the middleware is stripped frommodules.Drive-by fix (separate commit)
Commit
6c450b6fixes an unrelated failing test introduced by #257 (tkp/idgen):csp_gateway/tests/utils/test_id_generator.py::test_base_uses_utc_midnighthardcodedfake_now = datetime(2026, 4, 15, 1, 0, 0, tzinfo=timezone.utc). Python's mockeddatetime.now()doesn't propagate to Rust'sUtc::now()used byCounter.current(), so the counter measuresreal_now - mocked_midnight— which grows without bound as the wall clock walks forward. The assertionvalue < 200_000 * 1e9(~2.3 days) starts failing about two days after the hardcoded date.Fix: derive
fake_nowfromdatetime.now(timezone.utc)and.replace(hour=1, ...), so the '01:00 UTC / 9 PM EDT previous evening' scenario is preserved but the delta stays bounded. Test passes locally;main's CI is currently red for the same reason.Happy to split into a separate PR if preferred — it's self-contained and doesn't touch anything our auth shim cares about.