|
11 | 11 |
|
12 | 12 | namespace CodeIgniter\HTTP;
|
13 | 13 |
|
| 14 | +use CodeIgniter\Config\Factories; |
14 | 15 | use CodeIgniter\Cookie\Cookie;
|
15 | 16 | use CodeIgniter\Cookie\CookieStore;
|
16 | 17 | use CodeIgniter\Cookie\Exceptions\CookieException;
|
@@ -135,11 +136,11 @@ public function testCookieHTTPOnly()
|
135 | 136 |
|
136 | 137 | $response->setCookie('foo', 'bar');
|
137 | 138 | $cookie = $response->getCookie('foo');
|
138 |
| - $this->assertFalse($cookie->isHTTPOnly()); |
| 139 | + $this->assertTrue($cookie->isHTTPOnly()); |
139 | 140 |
|
140 |
| - $response->setCookie(['name' => 'bee', 'value' => 'bop', 'httponly' => true]); |
| 141 | + $response->setCookie(['name' => 'bee', 'value' => 'bop', 'httponly' => false]); |
141 | 142 | $cookie = $response->getCookie('bee');
|
142 |
| - $this->assertTrue($cookie->isHTTPOnly()); |
| 143 | + $this->assertFalse($cookie->isHTTPOnly()); |
143 | 144 | }
|
144 | 145 |
|
145 | 146 | public function testCookieExpiry()
|
@@ -255,6 +256,7 @@ public function testCookieStrictSetSameSite()
|
255 | 256 |
|
256 | 257 | public function testCookieBlankSetSameSite()
|
257 | 258 | {
|
| 259 | + /** @var CookieConfig $config */ |
258 | 260 | $config = config('Cookie');
|
259 | 261 | $config->samesite = '';
|
260 | 262 | $response = new Response(new App());
|
@@ -314,6 +316,30 @@ public function testCookieInvalidSameSite()
|
314 | 316 | ]);
|
315 | 317 | }
|
316 | 318 |
|
| 319 | + public function testSetCookieConfigCookieIsUsed() |
| 320 | + { |
| 321 | + /** @var CookieConfig $config */ |
| 322 | + $config = config('Cookie'); |
| 323 | + $config->secure = true; |
| 324 | + $config->httponly = true; |
| 325 | + $config->samesite = 'None'; |
| 326 | + Factories::injectMock('config', 'Cookie', $config); |
| 327 | + |
| 328 | + $cookieAttr = [ |
| 329 | + 'name' => 'bar', |
| 330 | + 'value' => 'foo', |
| 331 | + 'expire' => 9999, |
| 332 | + ]; |
| 333 | + $response = new Response(new App()); |
| 334 | + $response->setCookie($cookieAttr); |
| 335 | + |
| 336 | + $cookie = $response->getCookie('bar'); |
| 337 | + $options = $cookie->getOptions(); |
| 338 | + $this->assertTrue($options['secure']); |
| 339 | + $this->assertTrue($options['httponly']); |
| 340 | + $this->assertSame('None', $options['samesite']); |
| 341 | + } |
| 342 | + |
317 | 343 | public function testGetCookieStore()
|
318 | 344 | {
|
319 | 345 | $response = new Response(new App());
|
|
0 commit comments