1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use SensioLabs\Security\SecurityChecker; |
4
|
|
|
|
5
|
|
|
class CVECheckTaskTest extends SapphireTest |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
protected $usesDatabase = true; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* provide a mock to remove dependency on external service |
11
|
|
|
*/ |
12
|
|
|
protected function getSecurityCheckerMock($empty = false) |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
$mockOutput = <<<CVENOTICE |
15
|
|
|
{ |
16
|
|
|
"symfony\/symfony": { |
17
|
|
|
"version": "2.1.x-dev", |
18
|
|
|
"advisories": { |
19
|
|
|
"symfony\/symfony\/CVE-2013-1397.yaml": { |
20
|
|
|
"title": "Ability to enable\/disable object support in YAML parsing and dumping", |
21
|
|
|
"link": "http:\/\/symfony.com\/blog\/security-release-symfony-2-0-22-and-2-1-7-released", |
22
|
|
|
"cve": "CVE-2013-1397" |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
CVENOTICE; |
28
|
|
|
|
29
|
|
|
$securityCheckerMock = $this->getMockBuilder(SecurityChecker::class)->setMethods(['check'])->getMock(); |
|
|
|
|
30
|
|
|
$securityCheckerMock->expects($this->any())->method('check')->will($this->returnValue( |
|
|
|
|
31
|
|
|
$empty ? [] : json_decode($mockOutput, true) |
32
|
|
|
)); |
33
|
|
|
|
34
|
|
|
return $securityCheckerMock; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testUpdatesAreSaved() |
38
|
|
|
{ |
39
|
|
|
$securityCheckerMock = $this->getSecurityCheckerMock(); |
40
|
|
|
$checkTask = new CVECheckTask; |
41
|
|
|
$checkTask->setSecurityChecker($securityCheckerMock); |
42
|
|
|
|
43
|
|
|
$preCheck = CVE::get(); |
44
|
|
|
$this->assertCount(0, $preCheck, 'database is empty to begin with'); |
|
|
|
|
45
|
|
|
|
46
|
|
|
$checkTask->run(null); |
47
|
|
|
|
48
|
|
|
$postCheck = CVE::get(); |
49
|
|
|
$this->assertCount(1, $postCheck, 'CVE has been stored'); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
View Code Duplication |
public function testNoDuplicates() |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$securityCheckerMock = $this->getSecurityCheckerMock(); |
55
|
|
|
$checkTask = new CVECheckTask; |
56
|
|
|
$checkTask->setSecurityChecker($securityCheckerMock); |
57
|
|
|
|
58
|
|
|
$preCheck = CVE::get(); |
59
|
|
|
$this->assertCount(0, $preCheck, 'database is empty to begin with'); |
|
|
|
|
60
|
|
|
|
61
|
|
|
$checkTask->run(null); |
62
|
|
|
|
63
|
|
|
$postCheck = CVE::get(); |
64
|
|
|
$this->assertCount(1, $postCheck, 'CVE has been stored'); |
|
|
|
|
65
|
|
|
|
66
|
|
|
$checkTask->run(null); |
67
|
|
|
|
68
|
|
|
$postCheck = CVE::get(); |
69
|
|
|
$this->assertCount(1, $postCheck, 'The CVE isn\'t stored twice.'); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
View Code Duplication |
public function testCVERemovals() |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$securityCheckerMock = $this->getSecurityCheckerMock(); |
75
|
|
|
$checkTask = new CVECheckTask; |
76
|
|
|
$checkTask->setSecurityChecker($securityCheckerMock); |
77
|
|
|
|
78
|
|
|
$checkTask->run(null); |
79
|
|
|
|
80
|
|
|
$preCheck = CVE::get(); |
81
|
|
|
$this->assertCount(1, $preCheck, 'database has stored CVEs'); |
|
|
|
|
82
|
|
|
|
83
|
|
|
$securityCheckerMock = $this->getSecurityCheckerMock(true); |
84
|
|
|
$checkTask->setSecurityChecker($securityCheckerMock); |
85
|
|
|
|
86
|
|
|
$checkTask->run(null); |
87
|
|
|
|
88
|
|
|
$postCheck = CVE::get(); |
89
|
|
|
$this->assertCount(0, $postCheck, 'database is empty to finish with'); |
|
|
|
|
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.