Skip to content

Commit 37a83ff

Browse files
committed
setting private value using reflection in unit test
1 parent d0bfab4 commit 37a83ff

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ php:
33
- "5.6"
44
- "5.5"
55
- "5.4"
6-
- "5.3"
76
- "7.0"
87
- "7.1"
98
- hhvm
109
- nightly
10+
- "5.3"
11+
1112

1213
matrix:
1314
allow_failures:
1415
- php: nightly
1516
- php: hhvm
17+
- php: "5.3"
1618

1719
os:
1820
- linux
@@ -43,4 +45,4 @@ after_success:
4345
cache:
4446
directories:
4547
- vendor
46-
- $HOME/.cache/composer
48+
- $HOME/.cache/composer

libs/csrf/csrfprotector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,11 @@ public static function refreshToken()
388388
if (self::$cookieConfig === null) {
389389
if (!isset(self::$config['cookieConfig']))
390390
self::$config['cookieConfig'] = array();
391-
392391
self::$cookieConfig = new cookieConfig(self::$config['cookieConfig']);
393392
}
394393

395-
setcookie(self::$config['CSRFP_TOKEN'],
394+
setcookie(
395+
self::$config['CSRFP_TOKEN'],
396396
$token,
397397
time() + self::$cookieExpiryTime,
398398
self::$cookieConfig->path,

test/csrfprotector_test.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,13 @@ public function testSecureCookie()
183183
csrfprotector::refreshToken();
184184
$this->assertNotRegExp('/; secure/', csrfp_wrapper::getHeaderValue('Set-Cookie'));
185185

186-
csrfprotector::$config['cookieConfig'] = array('secure' => true);
186+
// this one would generally fails, as init was already called and now private static
187+
// property is set with secure as false;
188+
$csrfp = new csrfProtector;
189+
$reflection = new \ReflectionClass(get_class($csrfp));
190+
$property = $reflection->getProperty('cookieConfig');
191+
$property->setAccessible(true);
192+
$property->setValue($csrfp, new cookieConfig(array('secure' => true)));
187193
csrfprotector::refreshToken();
188194
$this->assertRegExp('/; secure/', csrfp_wrapper::getHeaderValue('Set-Cookie'));
189195
}

0 commit comments

Comments
 (0)