|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* @author Tom Klingenberg <[email protected]> |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace N98\Magento\Command\System\Check\Settings; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class CookieDomainCheckAbstractTest |
|
10
|
|
|
* |
|
11
|
|
|
* @covers N98\Magento\Command\System\Check\Settings\CookieDomainCheckAbstract |
|
12
|
|
|
*/ |
|
13
|
|
|
class CookieDomainCheckAbstractTest extends \PHPUnit_Framework_TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @see validateCookieDomainAgainstUrl |
|
17
|
|
|
*/ |
|
18
|
|
|
public function provideCookieDomainsAndBaseUrls() |
|
19
|
|
|
{ |
|
20
|
|
|
return array( |
|
21
|
|
|
array("", "", false), |
|
22
|
|
|
array("https://www.example.com/", "", false), |
|
23
|
|
|
array("", ".example.com", false), |
|
24
|
|
|
array("https://www.example.com/", ".example.com", true), |
|
25
|
|
|
array("https://www.example.com/", "www.example.com", true), |
|
26
|
|
|
|
|
27
|
|
|
array("https://images.example.com/", "www.example.com", false), |
|
28
|
|
|
array("https://images.example.com/", "example.com", true), |
|
29
|
|
|
array("https://images.example.com/", ".example.com", true), |
|
30
|
|
|
array("https://example.com/", ".example.com", false), |
|
31
|
|
|
|
|
32
|
|
|
array("https://www.example.com/", ".www.example.com", false), |
|
33
|
|
|
array("https://www.example.com/", "wwww.example.com", false), |
|
34
|
|
|
array("https://www.example.com/", "ww.example.com", false), |
|
35
|
|
|
array("https://www.example.com/", ".ww.example.com", false), |
|
36
|
|
|
array("https://www.example.com/", ".w.example.com", false), |
|
37
|
|
|
array("https://www.example.com/", "..example.com", false), |
|
38
|
|
|
|
|
39
|
|
|
// false-positives we know about, there is no check against public suffix list (the co.uk check) |
|
40
|
|
|
array("https://www.example.com/", ".com", false), |
|
41
|
|
|
array("https://www.example.co.uk/", ".co.uk", true), |
|
42
|
|
|
array("https://www.example.co.uk/", "co.uk", true), |
|
43
|
|
|
|
|
44
|
|
|
// go cases <http://gertjans.home.xs4all.nl/javascript/cookies.html> |
|
45
|
|
|
array('http://go/', 'go', false), |
|
46
|
|
|
array('http://go/', '.go', false), |
|
47
|
|
|
array('http://go.go/', 'go', false), |
|
48
|
|
|
array('http://go.go/', '.go', false), |
|
49
|
|
|
# ... some edge-cases left out |
|
50
|
|
|
array('http://www.good.go/', '.good.go', true), |
|
51
|
|
|
array('http://www.good.go/', 'www.good.go', true), |
|
52
|
|
|
array('http://good.go/', 'www.good.go', false), |
|
53
|
|
|
array('http://also.good.go/', 'www.good.go', false), |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @test |
|
59
|
|
|
* @dataProvider provideCookieDomainsAndBaseUrls |
|
60
|
|
|
*/ |
|
61
|
|
|
public function validateCookieDomainAgainstUrl($baseUrl, $cookieDomain, $expected) |
|
62
|
|
|
{ |
|
63
|
|
|
/** @var CookieDomainCheckAbstract $stub */ |
|
64
|
|
|
$stub = $this->getMockForAbstractClass(__NAMESPACE__ . '\CookieDomainCheckAbstract', [], '', false); |
|
65
|
|
|
|
|
66
|
|
|
$actual = $stub->validateCookieDomainAgainstUrl($cookieDomain, $baseUrl); |
|
67
|
|
|
|
|
68
|
|
|
$message = sprintf('%s for %s', $cookieDomain, $baseUrl); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertSame($expected, $actual, $message); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|