Skip to content

Isolate the test login route and refuse unsafe production modes - #32

Merged
TungYenTsai merged 2 commits into
mainfrom
fix/isolate-test-login
Nov 6, 2026
Merged

TungYenTsai merged 2 commits into
mainfrom
fix/isolate-test-login

Conversation

@TungYenTsai

Copy link
Copy Markdown
Collaborator

執行規劃 PR-3(S4/P10)。

測試專用登入 TestController 原本放在正式程式的 controllers/,只靠 YII_ENV_TEST 一道檢查。另外,docs/CONFIGURATION.md 寫明正式環境「強制關閉」YII_DEBUG,但程式並未強制。

修改:

  • controllers/TestController.php 移至 tests/_support/TestLoginController.php,只由 config/test.php 的 controllerMap 掛載,路由維持 /index-test.php/test/login,現有 acceptance 與 E2E 不需修改。
  • 需同時符合 Yii 測試模式與 APP_ENV=testing/test(沿用測試入口的 test-entry-policy.php),否則回 404。
  • ConfigValidator::validateProductionRuntimeMode():APP_ENV=production 時要求 YII_ENV=prod(或未設定)且 YII_DEBUG=false。正式環境原本即以 strict 模式驗證,不符時拒絕啟動並列出原因。
  • CHANGELOG(含升級注意)、CONFIGURATION、RELEASING(部署可不含 tests/ 與測試入口)、TEST_PLAN、E2E README 同步更新。

升級注意:正式機 .env 若設定 YII_ENV=dev/test 或 YII_DEBUG=true,升級後網站會拒絕啟動,請在部署前檢查。開發與測試環境不受影響。

驗證(dev6,PHP 8.2.35,HEAD 2030d9f):

  • 新增 ProductionRuntimeModeTest:模式檢查、正式驗證只在 production 套用、controllers/ 與 config/web.php 不含測試登入、非測試 APP_ENV 一律拒絕。tests/unit/config/ 22 tests/43 assertions 通過。
  • APP_ENV=testing 測試伺服器上 /index-test.php/test/login 回 200。
  • Acceptance 129 tests/379 assertions 通過(與基準相同)。
  • 本機 Chrome E2E(經 SSH tunnel)179/179 通過。
  • 完整 unit/functional 以本 PR CI 為準;Gitleaks 未發現問題。

🤖 Generated with Claude Code

TungYenTsai and others added 2 commits November 6, 2026 11:52
The test-only login controller lived in controllers/ and relied on a
single YII_ENV_TEST check. Move it under tests/_support, mount it only
from the test config, and also require APP_ENV=testing/test before it
answers. Production now refuses to start unless YII_ENV=prod and
YII_DEBUG=false, matching what the configuration guide already promised.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
APP_ENV uses production/testing/development while YII_ENV only accepts
prod/dev/test. Say so in .env.example and in the startup error, and
cover YII_ENV=production in the runtime mode test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TungYenTsai
TungYenTsai merged commit 9989c4b into main Nov 6, 2026
2 checks passed
@TungYenTsai
TungYenTsai deleted the fix/isolate-test-login branch November 6, 2026 04:59
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