Skip to content

fix(tests): override "test" sentinel in security conftest (closes #804) - #806

Closed
AndriiPasternak31 wants to merge 1 commit into
AndriiPasternak31/lint-baseline-orphan-testfrom
AndriiPasternak31/issue-804
Closed

fix(tests): override "test" sentinel in security conftest (closes #804)#806
AndriiPasternak31 wants to merge 1 commit into
AndriiPasternak31/lint-baseline-orphan-testfrom
AndriiPasternak31/issue-804

Conversation

@AndriiPasternak31

Copy link
Copy Markdown
Contributor

Summary

Fixes the fixture-precedence bug from #804tests/security/test_redis_network_isolation.py ACL tests have failed against any live stack since #589 (2026-05-04) because the global tests/conftest.py:30 setdefaults REDIS_BACKEND_PASSWORD="test" and the security conftest then tries to override from .env using setdefault (no-op when the key already exists). The bogus "test" value reached redis-cli, Redis correctly rejected it, and the tests failed with NOAUTH.

Two-line fix in tests/security/conftest.py:

  1. del os.environ[key] for REDIS_PASSWORD / REDIS_BACKEND_PASSWORD when they equal the literal "test" sentinel, before loading .env.
  2. Direct assignment (os.environ[key] = value) instead of setdefault when applying values from .env.

Plus a new file tests/security/test_redis_conftest_regression.py with 2 unit tests that lock in the precedence behavior — they'd fail under the old code and pass under the new code.

Verification

Full integration suite against a fresh stack:

========= 27 passed, 3 skipped, 3584 deselected, 8 warnings in 38.42s ==========

The three previously-failing tests now pass:

  • test_platform_container_can_authenticate
  • test_backend_acl_blocks_flushall
  • test_backend_acl_blocks_config_get

Plus the 2 new regression tests:

  • test_security_conftest_overlays_test_sentinel
  • test_dotenv_value_won_when_env_present

Stacking

Based on top of #796 (AndriiPasternak31/lint-baseline-orphan-test) — that PR baselines the pre-existing 3 sys.modules violations in test_cleanup_unreachable_orphan.py so the lint check passes. Without it, this PR's lint job fails on an unrelated pre-existing violation. #796 should land first; this PR auto-retargets to dev once #796 merges.

Test plan

Closes #804

🤖 Generated with Claude Code

`tests/conftest.py` setdefaults REDIS_PASSWORD/REDIS_BACKEND_PASSWORD to
the literal "test" at global pytest import so backend modules can be
imported without real Redis creds. `tests/security/conftest.py` was then
using `os.environ.setdefault(...)` to overlay real `.env` values — a
no-op because the sentinel was already set. Result: `redis-cli` ran with
`-a test` against a healthy stack and the ACL acceptance tests failed
for the wrong reason.

Pop the sentinel before the `.env` overlay and use direct assignment.
Add a regression test that asserts the live env value is not the
sentinel and (when `.env` defines the keys) matches the `.env` value.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@AndriiPasternak31

Copy link
Copy Markdown
Contributor Author

Duplicate of #805 — opened by mistake. Retargeting #805 onto #796 instead. Sorry for the noise.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant