Skip to content

Commit

Permalink
Add tests showing recent changes fix #9784
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 3, 2016
1 parent 27f951f commit 934bb00
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php
Expand Up @@ -153,6 +153,24 @@ public function testReadEncryptedCookieData() {
$this->assertEquals($expected, $data);
}

/**
* test read operations on corrupted cookie data.
*
* @return void
*/
public function testReadCorruptedCookieData() {
$this->Cookie->type('aes');
$this->Cookie->key = sha1('some bad key');

$data = $this->_implode(array('name' => 'jill', 'age' => 24));
// Corrupt the cookie data by slicing some bytes off.
$_COOKIE['CakeTestCookie'] = array(
'BadData' => substr(Security::encrypt($data, $this->Cookie->key), 0, -5)
);
$this->assertFalse($this->Cookie->check('BadData.name'), 'Key does not exist');
$this->assertNull($this->Cookie->read('BadData.name'), 'Key does not exist');
}

/**
* testReadPlainCookieData
*
Expand All @@ -169,6 +187,19 @@ public function testReadPlainCookieData() {
$this->assertEquals($expected, $data);
}

/**
* test read array keys from string data.
*
* @return void
*/
public function testReadNestedDataFromStrings() {
$_COOKIE['CakeTestCookie'] = array(
'User' => 'bad data'
);
$this->assertFalse($this->Cookie->check('User.name'), 'No key');
$this->assertNull($this->Cookie->read('User.name'), 'No key');
}

/**
* test read() after switching the cookie name.
*
Expand Down

0 comments on commit 934bb00

Please sign in to comment.