Repository navigation
Restore session.use_strict_mode after session tests. - #21133
terabytesoftw merged 3 commits into
Conversation
Reviewer's GuideUpdates session test teardown to prevent tests from leaking an active native session or modified File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Capture and restore native session state tests/framework/web/session/AbstractDbSessionTest.php, tests/framework/web/session/SessionTest.php |
Both test classes close active native sessions and clear the session ID during setup and teardown. They save session.use_strict_mode during setup and restore it during teardown unless its saved value was false. |
Possibly related PRs
- yiisoft/yii2#21098: Changes strict-mode handling and adds cleanup in related session tests.
- yiisoft/yii2#21132: Adds matching native-session cleanup and strict-mode restoration to
CacheSessionTest.
Priority:
Change: Other
Merge Risk: 
Minimal · up to 3b6f2
-
No merge-blocking issue is established in the session-test cleanup changes. Merge after normal test checks pass.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 2 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks the session state,
Closes it before tests await.
The strict-mode setting rests in store,
Then comes back as it was before.
Clean starts hop from test to test.
Comment @coderabbitai help to get the list of available commands.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #21133 +/- ##
=========================================
Coverage 81.86% 81.86%
Complexity 11595 11595
=========================================
Files 374 374
Lines 30368 30368
=========================================
Hits 24862 24862
Misses 5506 5506 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/framework/web/session/SessionTest.php" line_range="245" />
<code_context>
+ private function closeNativeSession(): void
+ {
+ if (session_status() === PHP_SESSION_ACTIVE) {
+ session_write_close();
+ }
+ }
</code_context>
<issue_to_address>
**Previous session data leaks**
When a later test starts a session without setting a fresh ID, `closeNativeSession()` calls `session_write_close()`, which leaves the selected ID in PHP’s process-wide state, so `session_start()` or `Session::open()` reuses the prior test’s session and exposes its data to another test.
Clear the session ID after closing the active native session.
Also at `tests/framework/web/session/AbstractDbSessionTest.php:324-329`, `tests/framework/web/session/SessionTest.php:246`.
</issue_to_address>
### Comment 2
<location path="tests/framework/web/session/AbstractDbSessionTest.php" line_range="327" />
<code_context>
+ private function closeNativeSession(): void
+ {
+ if (session_status() === PHP_SESSION_ACTIVE) {
+ session_write_close();
+ }
+ }
</code_context>
<issue_to_address>
**Previous session data leaks**
When a later test opens a native session without setting a fresh ID, `closeNativeSession()` calls `session_write_close()`, which leaves the selected ID set, so the later test reopens the prior session and loads its stored data.
Clear the session ID after closing the active native session.
Also at `tests/framework/web/session/SessionTest.php:36`, `tests/framework/web/session/SessionTest.php:245`, `tests/framework/web/session/AbstractDbSessionTest.php:54`.
</issue_to_address>
### Comment 3
<location path="tests/framework/web/session/SessionTest.php" line_range="31" />
<code_context>
{
parent::setUp();
+ $this->useStrictModeBackup = ini_get('session.use_strict_mode');
+
$this->mockApplication();
</code_context>
<issue_to_address>
**Tests can inherit an active session**
When an earlier test leaves a native session active in the same PHP process, `setUp()` captures the ini setting without first closing any session left active by an earlier test. Session tests that call `open()` can then reuse that active session instead of starting one with their own ID and configuration, producing order-dependent test results.
Close any active native session at the start of both `setUp()` methods before capturing or changing session state.
Also at `tests/framework/web/session/AbstractDbSessionTest.php:44`.
</issue_to_address>Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: tests/framework/web/session/SessionTest.php:245, tests/framework/web/session/AbstractDbSessionTest.php:327, tests/framework/web/session/SessionTest.php:31
* Fix #21072: Use the full 64-bit keyspace for PostgreSQL advisory lock keys in `PgsqlMutex` * Fix #21073: Fix `MultipartFormDataParser` boundary extraction when `Content-Type` has additional parameters * Restore `session.use_strict_mode` after session tests. (#21133) * Fix #21074: Fix Gettext PO file escaping of backslashes and parsing of escaped quotes * Fix PHPStan level 4 errors in tests (#21135) - Fix `@return` annotation for `yii\db\Command::getSql()` - Fix `@property` annotation for `yii\db\Command::$sql` - Fix `@return` annotations for `cssStyleFromArray()` and `getAttributeValue()` in `yii\helpers\BaseHtml` - Fix `@return` annotations for `format()` and `asRaw()` in `yii\i18n\Formatter` - Fix `@return` annotation for `yii\web\HeaderCollection::get()` - Fix `@return` annotations for `getInstance()`, `getInstanceByName()`, `getInstances()` and `getInstancesByName()` in `yii\web\UploadedFile` - Add `@throws` annotation for `InvalidConfigException` in `yii\db\Connection::open()` - Add `@phpstan-impure` annotations for `yii\db\Connection::open()`, `save()` and `link()` in `yii\db\BaseActiveRecord`, `yii\web\AssetBundle::register()`, `yii\test\ArrayFixture::load()`, `yii\filters\RateLimiter::beforeAction()`, `validateAttribute()` and `validateAttributes()` in `yii\validators\Validator` * Verify the rollback that testTransactionShortcutException never checked (#21134) * Fix #21131: Reject non-string tokens in `yii\web\User::loginByAccessToken()` before the identity lookup, hardening against type-juggling Signed-off-by: Guido Pannenbecker <info@sd-gp.de> * Update PHPStan level from 3 to 4 (#21136) - Fix `@var` annotation for `yii\base\ErrorHandler::$_hhvmException` (mspirkov) - Fix `@return` annotation for `yii\base\Theme::getBasePath()` (mspirkov) - Separate the `@property` annotations for `yii\base\Theme::$basePath` (mspirkov) - Fix `@var` annotation for `yii\caching\DbQueryDependency::$db` (mspirkov) - Fix `@var` annotation for `yii\data\ArrayDataProvider::$allModels` (mspirkov) - Fix `@var` annotation for `yii\db\ActiveQueryTrait::$asArray` (mspirkov) - Fix `@var` annotation for `yii\db\ActiveRelationTrait::$primaryModel` (mspirkov) - Fix `@param` annotation for `$models` in `yii\db\ActiveRelationTrait::populateInverseRelation()` (mspirkov) - Fix `@param` and `@return` annotations for `yii\db\QueryTrait::filterCondition()` (mspirkov) - Fix `@param` annotations for `$content` in `isOperator()`, `isIdentifier()`, `isStringLiteral()` and `isKeyword()` of `yii\db\SqlTokenizer` (mspirkov) - Fix `@param` annotation for `$columns` in `yii\db\conditions\InConditionBuilder::buildSubqueryInCondition()` (mspirkov) - Fix `@param` and `@return` annotations for `yii\di\Container::normalizeDefinition()` (mspirkov) - Fix `@var` annotation for `yii\filters\AccessRule::$matchCallback` (mspirkov) - Fix `@var` annotation for `yii\filters\ContentNegotiator::$request` (mspirkov) - Fix `@var` annotation for `yii\filters\auth\CompositeAuth::$authMethods` (mspirkov) - Fix `@var` annotation for `yii\grid\GridView::$filterSelector` (mspirkov) - Fix `@param` annotations for `$models` in `errorSummary()` and `collectErrors()` of `yii\helpers\BaseConsole`, `yii\helpers\BaseHtml` and `yii\helpers\BaseJson`, and in `yii\widgets\ActiveForm::errorSummary()` (mspirkov) - Fix `@var` annotation for `yii\helpers\BaseUrl::$urlManager` (mspirkov) - Fix `@var` annotation for `yii\log\Logger::$dispatcher` (mspirkov) - Fix `@var` annotation for `yii\rest\IndexAction::$prepareSearchQuery` (mspirkov) - Fix `@var` annotation for `yii\web\Cookie::$sameSite` (mspirkov) - Fix inline `@var` annotations in `yii\db\ActiveRelationTrait::findJunctionRows()`, `refresh()` and `refreshTableSchema()` in `yii\db\Schema`, and `yii\log\Target::getMessagePrefix()` (mspirkov) - Add `@throws` annotation for `UrlNormalizerRedirectException` in `yii\web\Request::resolve()` (mspirkov) - Add `@phpstan-impure` annotations for `yii\base\Component::attachBehavior()`, `yii\base\Model::clearErrors()`, `yii\data\DataFilter::setSearchModel()`, `yii\db\Command::addCheck()`, `yii\db\Connection::close()`, `yii\db\Schema::getTableSchema()`, `getTablePrimaryKey()` and `getTableChecks()` in `yii\db\ConstraintFinderInterface` and `yii\db\ConstraintFinderTrait`, `yii\validators\Validator::validate()`, `yii\web\CompositeUrlRule::iterateRules()` and `yii\web\User::setIdentity()` (mspirkov) * Fix PHPStan errors (#21139) * Fix dead php.net intl and OPcache links in the guide (#21140) * Bump `phpstan/phpstan` to `2.3.7` (#21142) * Allow the `__class` key in configuration arrays in `@return` annotations (#21141) * Fix #21147: Add `@template` annotation for `$default` in `yii\web\HeaderCollection::get()` * Update workflow configurations to support PHP `8.6` and adjust dependencies. (#21148) * Update dependencies in `composer.lock` to latest versions. * Add overrides for `glob` and `minimatch` in `package.json`. * Update PHP version to `8.6` and add `ignore-platform-reqs` for CI workflows. --------- Signed-off-by: Guido Pannenbecker <info@sd-gp.de> Co-authored-by: Ilia Alshanetsky <ilia@ilia.ws> Co-authored-by: Maksim Spirkov <63721828+mspirkov@users.noreply.github.com> Co-authored-by: Dylan Pulver <35541198+dylanpulver@users.noreply.github.com> Co-authored-by: took <info@sd-gp.de> Co-authored-by: Faris Basha TM <72191505+farisbasha@users.noreply.github.com>
Fix comment: #21133 (comment)
Summary by Sourcery
Restore session configuration and state between session tests to prevent test leakage.
Bug Fixes:
session.use_strict_modesetting after session tests and ensure native sessions are reset between tests.Tests: