Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7410026
CookieTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
CookieTest.php
View Options
<?php
namespace
Wikimedia\Tests
;
use
Cookie
;
use
MediaWikiCoversValidator
;
use
PHPUnit\Framework\TestCase
;
use
Wikimedia\TestingAccessWrapper
;
/**
* @covers \Cookie
*/
class
CookieTest
extends
TestCase
{
use
MediaWikiCoversValidator
;
/**
* @dataProvider provideCookieDomains
*/
public
function
testValidateCookieDomain
(
$expected
,
$domain
,
$origin
=
null
)
{
if
(
$origin
)
{
$ok
=
Cookie
::
validateCookieDomain
(
$domain
,
$origin
);
$msg
=
"$domain against origin $origin"
;
}
else
{
$ok
=
Cookie
::
validateCookieDomain
(
$domain
);
$msg
=
"$domain"
;
}
$this
->
assertEquals
(
$expected
,
$ok
,
$msg
);
}
public
static
function
provideCookieDomains
()
{
return
[
[
false
,
"org"
],
[
false
,
".org"
],
[
true
,
"wikipedia.org"
],
[
true
,
".wikipedia.org"
],
[
false
,
"co.uk"
],
[
false
,
".co.uk"
],
[
false
,
"gov.uk"
],
[
false
,
".gov.uk"
],
[
true
,
"supermarket.uk"
],
[
false
,
"uk"
],
[
false
,
".uk"
],
[
false
,
"127.0.0."
],
[
false
,
"127."
],
[
false
,
"127.0.0.1."
],
[
true
,
"127.0.0.1"
],
[
false
,
"333.0.0.1"
],
[
true
,
"example.com"
],
[
false
,
"example.com."
],
[
true
,
".example.com"
],
[
true
,
".example.com"
,
"www.example.com"
],
[
false
,
"example.com"
,
"www.example.com"
],
[
true
,
"127.0.0.1"
,
"127.0.0.1"
],
[
false
,
"127.0.0.1"
,
"localhost"
],
];
}
/**
* @dataProvider provideDomains
*/
public
function
testCanServeDomain
(
string
$domain
,
bool
$expected
)
{
$cookie
=
new
Cookie
(
''
,
''
,
[
'domain'
=>
'.example.com'
]
);
/** @var Cookie $cookie */
$cookie
=
TestingAccessWrapper
::
newFromObject
(
$cookie
);
$this
->
assertSame
(
$expected
,
$cookie
->
canServeDomain
(
$domain
)
);
}
/**
* @dataProvider provideDomains
*/
public
function
testCanServeDomainWithoutDomain
(
string
$domain
)
{
$cookie
=
new
Cookie
(
''
,
''
,
[
'domain'
=>
'.'
]
);
/** @var Cookie $cookie */
$cookie
=
TestingAccessWrapper
::
newFromObject
(
$cookie
);
$this
->
assertFalse
(
$cookie
->
canServeDomain
(
$domain
)
);
}
public
static
function
provideDomains
()
{
return
[
[
''
,
false
],
[
'.'
,
false
],
[
'example.com'
,
false
],
[
'example.com.'
,
false
],
[
'.Example.com'
,
true
],
[
'.example.com.'
,
false
],
[
'www.Example.com'
,
true
],
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 21, 22:46 (1 d, 21 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
75/cd/1ad2b860419b77550856ec876a7c
Default Alt Text
CookieTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment