Skip to content

Commit cd59bfa

Browse files
Merge branch '5.2' into 5.x
* 5.2: [HttpKernel] Configure `session.cookie_secure` earlier Make sure the Psalm review CI job is working Adding a Github action to run Psalm
2 parents e2f1c46 + d978bea commit cd59bfa

File tree

7 files changed

+144
-5
lines changed

7 files changed

+144
-5
lines changed

.github/psalm/cache/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

.github/psalm/psalm.baseline.xml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<files psalm-version="4.x-dev@">
3+
</files>

.github/workflows/psalm.yml

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Static analysis
2+
3+
on:
4+
pull_request: ~
5+
6+
jobs:
7+
psalm:
8+
name: Psalm
9+
runs-on: Ubuntu-20.04
10+
11+
steps:
12+
- name: Set up PHP
13+
uses: shivammathur/setup-php@v2
14+
with:
15+
php-version: '8.0'
16+
extensions: "json,memcached,mongodb,redis,xsl,ldap,dom"
17+
ini-values: "memory_limit=-1"
18+
coverage: none
19+
20+
- name: Checkout PR
21+
uses: actions/checkout@v2
22+
with:
23+
path: pr
24+
25+
- name: Checkout base
26+
uses: actions/checkout@v2
27+
with:
28+
ref: ${{ github.base_ref }}
29+
path: base
30+
31+
- name: Configure composer
32+
run: |
33+
cd base
34+
COMPOSER_HOME="$(composer config home)"
35+
([ -d "$COMPOSER_HOME" ] || mkdir "$COMPOSER_HOME") && cp .github/composer-config.json "$COMPOSER_HOME/config.json"
36+
echo "COMPOSER_ROOT_VERSION=$(grep -m1 SYMFONY_VERSION .travis.yml | grep -o '[0-9.x]*').x-dev" >> $GITHUB_ENV
37+
38+
- name: Determine composer cache directory
39+
id: composer-cache
40+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
41+
42+
- name: Cache composer dependencies
43+
uses: actions/cache@v2
44+
with:
45+
path: ${{ steps.composer-cache.outputs.dir }}
46+
key: composer-${{ github.base_ref }}
47+
restore-keys: composer-
48+
49+
- name: Install Psalm
50+
run: |
51+
composer require psalm/phar
52+
cp ./vendor/bin/psalm.phar base/psalm.phar
53+
cp ./vendor/bin/psalm.phar pr/psalm.phar
54+
55+
- name: Install dependencies for base
56+
run: |
57+
cd base
58+
echo "::group::modify composer.json"
59+
composer remove symfony/phpunit-bridge --no-interaction --no-update
60+
composer require --no-update phpunit/phpunit php-http/discovery psr/event-dispatcher
61+
echo "::endgroup::"
62+
echo "::group::composer update"
63+
composer update --no-progress --ansi
64+
echo "::endgroup::"
65+
66+
- name: Generate Psalm baseline
67+
run: |
68+
cd base
69+
./psalm.phar --set-baseline=.github/psalm/psalm.baseline.xml --no-progress
70+
71+
- name: Copy baseline
72+
run: |
73+
cp base/.github/psalm/psalm.baseline.xml pr/.github/psalm/psalm.baseline.xml
74+
75+
- name: Install dependencies for PR
76+
run: |
77+
cd pr
78+
echo "::group::modify composer.json"
79+
composer remove symfony/phpunit-bridge --no-interaction --no-update
80+
composer require --no-update phpunit/phpunit php-http/discovery psr/event-dispatcher
81+
echo "::endgroup::"
82+
echo "::group::composer update"
83+
composer update --no-progress --ansi
84+
echo "::endgroup::"
85+
86+
- name: Cache Psalm
87+
uses: actions/cache@v2
88+
with:
89+
path: pr/.github/psalm/cache/
90+
key: psalm-${{ github.base_ref }}
91+
restore-keys: psalm-
92+
93+
- name: Psalm
94+
run: |
95+
cd pr
96+
./psalm.phar --version
97+
./psalm.phar --output-format=github --no-progress

psalm.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="5"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
cacheDirectory="./.github/psalm/cache/"
9+
errorBaseline=".github/psalm/psalm.baseline.xml"
10+
>
11+
<projectFiles>
12+
<directory name="src" />
13+
<ignoreFiles>
14+
<directory name="src/Symfony/*/*/Tests" />
15+
<directory name="src/Symfony/*/*/*/Tests" />
16+
<directory name="src/Symfony/*/*/*/*/Tests" />
17+
<directory name="vendor" />
18+
</ignoreFiles>
19+
</projectFiles>
20+
</psalm>

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

+3
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ public function setOptions(array $options)
389389
$this->emulateSameSite = $value;
390390
continue;
391391
}
392+
if ('cookie_secure' === $key && 'auto' === $value) {
393+
continue;
394+
}
392395
ini_set('url_rewriter.tags' !== $key ? 'session.'.$key : $key, $value);
393396
}
394397
}

src/Symfony/Component/HttpKernel/EventListener/SessionListener.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Psr\Container\ContainerInterface;
1515
use Symfony\Component\HttpFoundation\Session\SessionInterface;
1616
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
17+
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1718

1819
/**
1920
* Sets the session in the request.
@@ -33,10 +34,12 @@ public function __construct(ContainerInterface $container, bool $debug = false)
3334
parent::__construct($container, $debug);
3435
}
3536

36-
protected function getSession(): ?SessionInterface
37+
public function onKernelRequest(GetResponseEvent $event)
3738
{
38-
if (!$this->container->has('session')) {
39-
return null;
39+
parent::onKernelRequest($event);
40+
41+
if (!$event->isMasterRequest() || !$this->container->has('session')) {
42+
return;
4043
}
4144

4245
if ($this->container->has('session_storage')
@@ -46,6 +49,13 @@ protected function getSession(): ?SessionInterface
4649
) {
4750
$storage->setOptions(['cookie_secure' => true]);
4851
}
52+
}
53+
54+
protected function getSession(): ?SessionInterface
55+
{
56+
if (!$this->container->has('session')) {
57+
return null;
58+
}
4959

5060
return $this->container->get('session');
5161
}

src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testSessionIsSet()
6262
$listener = new SessionListener($container);
6363

6464
$event = $this->createMock(RequestEvent::class);
65-
$event->expects($this->once())->method('isMasterRequest')->willReturn(true);
65+
$event->expects($this->exactly(2))->method('isMasterRequest')->willReturn(true);
6666
$event->expects($this->once())->method('getRequest')->willReturn($request);
6767

6868
$listener->onKernelRequest($event);
@@ -206,12 +206,16 @@ public function testGetSessionIsCalledOnce()
206206
$listener = new SessionListener($container);
207207
$listener->onKernelRequest($event);
208208

209+
// storage->setOptions() should have been called already
210+
$container->set('session_storage', null);
211+
$sessionStorage = null;
212+
209213
$subRequest = $masterRequest->duplicate();
210214
// at this point both master and subrequest have a closure to build the session
211215

212216
$masterRequest->getSession();
213217

214-
// calling the factory on the subRequest should not trigger a second call to storage->sesOptions()
218+
// calling the factory on the subRequest should not trigger a second call to storage->setOptions()
215219
$subRequest->getSession();
216220
}
217221

0 commit comments

Comments
 (0)