This repository was archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
fixes case sensitivity for SameSite directive #207
Closed
wilcol
wants to merge
7
commits into
zendframework:develop
from
wilcol:feature/bug-#206-samesite-directive-case-sensitivity
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f0d279b
fixed case sensitivity for SameSite directive
wilcol f88c812
updated with PR suggestions
wilcol 42bda18
second update with PR suggestions
wilcol c2026a1
fixed cs opening brace on new line
wilcol e8c6b6d
added lowercase keys to same site values
wilcol af92ffa
added same site directive canonical return value test and restructed …
wilcol 2eddb50
added use function statements and updated test
wilcol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,9 @@ | |
use Zend\Http\Header\MultipleHeaderInterface; | ||
use Zend\Http\Header\SetCookie; | ||
|
||
use function strtolower; | ||
use function strtoupper; | ||
|
||
class SetCookieTest extends TestCase | ||
{ | ||
/** | ||
|
@@ -69,6 +72,32 @@ public function testSetCookieConstructorWithSameSite() | |
$this->assertEquals('Strict', $setCookieHeader->getSameSite()); | ||
} | ||
|
||
public function testSetCookieConstructorWithSameSiteCaseInsensitive() | ||
{ | ||
$setCookieHeader = new SetCookie( | ||
'myname', | ||
'myvalue', | ||
'Wed, 13-Jan-2021 22:23:01 GMT', | ||
'/accounts', | ||
'docs.foo.com', | ||
true, | ||
true, | ||
99, | ||
9, | ||
strtolower(SetCookie::SAME_SITE_STRICT) | ||
); | ||
$this->assertEquals('myname', $setCookieHeader->getName()); | ||
$this->assertEquals('myvalue', $setCookieHeader->getValue()); | ||
$this->assertEquals('Wed, 13-Jan-2021 22:23:01 GMT', $setCookieHeader->getExpires()); | ||
$this->assertEquals('/accounts', $setCookieHeader->getPath()); | ||
$this->assertEquals('docs.foo.com', $setCookieHeader->getDomain()); | ||
$this->assertTrue($setCookieHeader->isSecure()); | ||
$this->assertTrue($setCookieHeader->isHttpOnly()); | ||
$this->assertEquals(99, $setCookieHeader->getMaxAge()); | ||
$this->assertEquals(9, $setCookieHeader->getVersion()); | ||
$this->assertEquals(SetCookie::SAME_SITE_STRICT, $setCookieHeader->getSameSite()); | ||
} | ||
|
||
public function testSetCookieWithInvalidSameSiteValueThrowException() | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
|
@@ -105,6 +134,29 @@ public function testSetInvalidSameSiteDirectiveValueViaSetter() | |
$setCookieHeader->setSameSite('InvalidValue'); | ||
} | ||
|
||
public function testSameSiteGetterReturnsCanonicalValue() | ||
{ | ||
$setCookieHeader = new SetCookie( | ||
'myname', | ||
'myvalue', | ||
'Wed, 13-Jan-2021 22:23:01 GMT', | ||
'/accounts', | ||
'docs.foo.com', | ||
true, | ||
true, | ||
99, | ||
9, | ||
SetCookie::SAME_SITE_STRICT | ||
); | ||
$this->assertEquals(SetCookie::SAME_SITE_STRICT, $setCookieHeader->getSameSite()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also test |
||
|
||
$setCookieHeader->setSameSite(strtolower(SetCookie::SAME_SITE_LAX)); | ||
$this->assertEquals(SetCookie::SAME_SITE_LAX, $setCookieHeader->getSameSite()); | ||
|
||
$setCookieHeader->setSameSite(strtoupper(SetCookie::SAME_SITE_NONE)); | ||
$this->assertEquals(SetCookie::SAME_SITE_NONE, $setCookieHeader->getSameSite()); | ||
} | ||
|
||
public function testSetCookieFromStringWithQuotedValue() | ||
{ | ||
$setCookieHeader = SetCookie::fromString('Set-Cookie: myname="quotedValue"'); | ||
|
@@ -161,6 +213,39 @@ public function testSetCookieFromStringCanCreateSingleHeader() | |
$this->assertTrue($setCookieHeader->isSecure()); | ||
$this->assertTrue($setCookieHeader->isHttponly()); | ||
$this->assertEquals(setCookie::SAME_SITE_STRICT, $setCookieHeader->getSameSite()); | ||
|
||
$setCookieHeader = SetCookie::fromString( | ||
wilcol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'set-cookie: myname=myvalue; Domain=docs.foo.com; Path=/accounts;' | ||
. 'Expires=Wed, 13-Jan-2021 22:23:01 GMT; Secure; HttpOnly; SameSite=strict' | ||
); | ||
$this->assertInstanceOf(MultipleHeaderInterface::class, $setCookieHeader); | ||
$this->assertEquals('myname', $setCookieHeader->getName()); | ||
$this->assertEquals('myvalue', $setCookieHeader->getValue()); | ||
$this->assertEquals('docs.foo.com', $setCookieHeader->getDomain()); | ||
$this->assertEquals('/accounts', $setCookieHeader->getPath()); | ||
$this->assertEquals('Wed, 13-Jan-2021 22:23:01 GMT', $setCookieHeader->getExpires()); | ||
$this->assertTrue($setCookieHeader->isSecure()); | ||
$this->assertTrue($setCookieHeader->isHttponly()); | ||
$this->assertEquals(setCookie::SAME_SITE_STRICT, $setCookieHeader->getSameSite()); | ||
} | ||
|
||
public function testFieldValueWithSameSiteCaseInsensitive() | ||
{ | ||
$setCookieHeader = SetCookie::fromString( | ||
'set-cookie: myname=myvalue; SameSite=Strict' | ||
); | ||
$this->assertEquals( | ||
'myname=myvalue; SameSite=Strict', | ||
$setCookieHeader->getFieldValue() | ||
); | ||
|
||
$setCookieHeader = SetCookie::fromString( | ||
'set-cookie: myname=myvalue; SameSite=strict' | ||
); | ||
$this->assertEquals( | ||
'myname=myvalue; SameSite=Strict', | ||
$setCookieHeader->getFieldValue() | ||
); | ||
} | ||
|
||
public function testSetCookieFromStringCanCreateMultipleHeaders() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coding style: used functions must be imported with
use function
statements (underuse
block, separated by blank line)Import just those you touched, that will be enough.