mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Adding support for httpOnly cookies to CookieComponent. Fixes #1127
This commit is contained in:
parent
3395f4221e
commit
237b66d193
2 changed files with 46 additions and 2 deletions
|
@ -116,6 +116,16 @@ class CookieComponent extends Component {
|
|||
*/
|
||||
public $key = null;
|
||||
|
||||
/**
|
||||
* HTTP only cookie
|
||||
*
|
||||
* Set to true to make HTTP only cookies. Cookies that are HTTP only
|
||||
* are not accessible in Javascript.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $httpOnly = false;
|
||||
|
||||
/**
|
||||
* Values stored in the cookie.
|
||||
*
|
||||
|
@ -356,7 +366,10 @@ class CookieComponent extends Component {
|
|||
* @param string $value Value for cookie
|
||||
*/
|
||||
protected function _write($name, $value) {
|
||||
$this->_setcookie($this->name . $name, $this->_encrypt($value), $this->_expires, $this->path, $this->domain, $this->secure);
|
||||
$this->_setcookie(
|
||||
$this->name . $name, $this->_encrypt($value),
|
||||
$this->_expires, $this->path, $this->domain, $this->secure, $this->httpOnly
|
||||
);
|
||||
|
||||
if (!is_null($this->_reset)) {
|
||||
$this->_expires = $this->_reset;
|
||||
|
@ -371,7 +384,10 @@ class CookieComponent extends Component {
|
|||
* @return void
|
||||
*/
|
||||
protected function _delete($name) {
|
||||
$this->_setcookie($this->name . $name, '', time() - 42000, $this->path, $this->domain, $this->secure);
|
||||
$this->_setcookie(
|
||||
$this->name . $name, '',
|
||||
time() - 42000, $this->path, $this->domain, $this->secure, $this->httpOnly
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -192,6 +192,34 @@ class CookieComponentTest extends CakeTestCase {
|
|||
$this->assertEquals('value', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test write with httpOnly cookies
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testWriteHttpOnly() {
|
||||
$this->Cookie->httpOnly = true;
|
||||
$this->Cookie->secure = false;
|
||||
$this->Cookie->expects($this->once())->method('_setcookie')
|
||||
->with('CakeTestCookie[Testing]', 'value', time() + 10, '/', '', false, true);
|
||||
|
||||
$this->Cookie->write('Testing', 'value', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* test delete with httpOnly
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testDeleteHttpOnly() {
|
||||
$this->Cookie->httpOnly = true;
|
||||
$this->Cookie->secure = false;
|
||||
$this->Cookie->expects($this->once())->method('_setcookie')
|
||||
->with('CakeTestCookie[Testing]', '', time() - 42000, '/', '', false, true);
|
||||
|
||||
$this->Cookie->delete('Testing', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* testWritePlainCookieArray
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue