|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* MIT License |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2016 Bernardo Secades |
|
7
|
|
|
* |
|
8
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
9
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
10
|
|
|
* in the Software without restriction, including without limitation the rights |
|
11
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
12
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
13
|
|
|
* furnished to do so, subject to the following conditions: |
|
14
|
|
|
* |
|
15
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
16
|
|
|
* copies or substantial portions of the Software. |
|
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
23
|
|
|
* SOFTWARE. |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace BernardoSecades\Packagist\SecurityChecker\Tests\Unit; |
|
27
|
|
|
|
|
28
|
|
|
use BernardoSecades\Packagist\SecurityChecker\PackagistSecurityChecker; |
|
29
|
|
|
use BernardoSecades\Packagist\SecurityChecker\ValueObject\FilterCheck; |
|
30
|
|
|
use BernardoSecades\Packagist\SecurityChecker\ValueObject\Package; |
|
31
|
|
|
use BernardoSecades\Packagist\SecurityChecker\Exception\File\FileNotFoundException; |
|
32
|
|
|
|
|
33
|
|
|
class PackagistSecurityCheckerTest extends \PHPUnit_Framework_TestCase |
|
34
|
|
|
{ |
|
35
|
|
|
/** @var PackagistSecurityChecker */ |
|
36
|
|
|
protected $checkerDefaultClient; |
|
37
|
|
|
|
|
38
|
|
|
protected function setUp() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->checkerDefaultClient = new PackagistSecurityChecker(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testFailLoadComposerLock() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->expectException(FileNotFoundException::class); |
|
46
|
|
|
$this->checkerDefaultClient->check('no-exist.lock'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testDependenciesWithoutBugs() |
|
50
|
|
|
{ |
|
51
|
|
|
$packages = $this->checkerDefaultClient->check($this->getComposerLockPathWithoutBugs(), FilterCheck::BUG); |
|
52
|
|
|
$this->assertCount(0, $packages); |
|
53
|
|
|
$this->assertFalse($this->checkerDefaultClient->hasBugs()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return Package[] |
|
58
|
|
|
*/ |
|
59
|
|
|
public function testNumberPackagesCheck() |
|
60
|
|
|
{ |
|
61
|
|
|
$packages = $this->checkerDefaultClient->check($this->getComposerLockPathWithBugs()); |
|
62
|
|
|
$this->assertCount(56, $packages); |
|
63
|
|
|
$this->assertTrue($this->checkerDefaultClient->hasBugs()); |
|
64
|
|
|
|
|
65
|
|
|
return $packages; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return Package[] |
|
70
|
|
|
*/ |
|
71
|
|
|
public function testNumberPackagesCheckOnlyBugs() |
|
72
|
|
|
{ |
|
73
|
|
|
$packages = $this->checkerDefaultClient->check($this->getComposerLockPathWithBugs(), FilterCheck::BUG); |
|
74
|
|
|
$this->assertCount(4, $packages); |
|
75
|
|
|
|
|
76
|
|
|
return $packages; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @depends testNumberPackagesCheck |
|
81
|
|
|
* @param Package[] $packages |
|
82
|
|
|
*/ |
|
83
|
|
|
public function testNotFollowSemanticVersioning(array $packages) |
|
84
|
|
|
{ |
|
85
|
|
|
$this->assertArrayHasKey('phenx/php-font-lib', $packages); |
|
86
|
|
|
$this->assertArrayHasKey('phenx/php-svg-lib', $packages); |
|
87
|
|
|
|
|
88
|
|
|
$packageA = $packages['phenx/php-font-lib']; |
|
89
|
|
|
$packageB = $packages['phenx/php-svg-lib']; |
|
90
|
|
|
$this->assertInstanceOf(Package::class, $packageA); |
|
91
|
|
|
$this->assertInstanceOf(Package::class, $packageB); |
|
92
|
|
|
|
|
93
|
|
|
$this->assertFalse($packageA->supportSemanticVersioning()); |
|
94
|
|
|
$this->assertFalse($packageB->supportSemanticVersioning()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @depends testNumberPackagesCheck |
|
99
|
|
|
* @param Package[] $packages |
|
100
|
|
|
*/ |
|
101
|
|
|
public function testPackageNoExistInPackagist(array $packages) |
|
102
|
|
|
{ |
|
103
|
|
|
$this->assertArrayHasKey('doctrine/no-exist', $packages); |
|
104
|
|
|
|
|
105
|
|
|
$package = $packages['doctrine/no-exist']; |
|
106
|
|
|
$this->assertInstanceOf(Package::class, $package); |
|
107
|
|
|
|
|
108
|
|
|
$this->assertFalse($package->hasPackagist()); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @depends testNumberPackagesCheckOnlyBugs |
|
113
|
|
|
* @param Package[] $packages |
|
114
|
|
|
*/ |
|
115
|
|
|
public function testNamePackagesWitBugs(array $packages) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->assertArrayHasKey('psr/log', $packages); |
|
118
|
|
|
$this->assertArrayHasKey('symfony/symfony', $packages); |
|
119
|
|
|
$this->assertArrayHasKey('twig/twig', $packages); |
|
120
|
|
|
$this->assertArrayHasKey('zendframework/zend-diactoros', $packages); |
|
121
|
|
|
|
|
122
|
|
|
$logPackage = $packages['psr/log']; |
|
123
|
|
|
$this->assertInstanceOf(Package::class, $logPackage); |
|
124
|
|
|
$this->assertTrue($logPackage->hasBug()); |
|
125
|
|
|
|
|
126
|
|
|
$symfonyPackage = $packages['symfony/symfony']; |
|
127
|
|
|
$this->assertInstanceOf(Package::class, $symfonyPackage); |
|
128
|
|
|
$this->assertTrue($symfonyPackage->hasBug()); |
|
129
|
|
|
|
|
130
|
|
|
$twigPackage = $packages['twig/twig']; |
|
131
|
|
|
$this->assertInstanceOf(Package::class, $twigPackage); |
|
132
|
|
|
$this->assertTrue($twigPackage->hasBug()); |
|
133
|
|
|
|
|
134
|
|
|
$zendPackage = $packages['zendframework/zend-diactoros']; |
|
135
|
|
|
$this->assertInstanceOf(Package::class, $zendPackage); |
|
136
|
|
|
$this->assertTrue($zendPackage->hasBug()); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @return string |
|
141
|
|
|
*/ |
|
142
|
|
|
protected function getComposerLockPathWithBugs() |
|
143
|
|
|
{ |
|
144
|
|
|
return __DIR__.'/../fixtures/composerWithBugs.lock'; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @return string |
|
149
|
|
|
*/ |
|
150
|
|
|
protected function getComposerLockPathWithoutBugs() |
|
151
|
|
|
{ |
|
152
|
|
|
return __DIR__.'/../fixtures/composerWithoutBugs.lock'; |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|