Skip to content
This repository was archived by the owner on Jan 23, 2021. It is now read-only.

Commit 9847a3b

Browse files
authored
Merge pull request #15 from shochdoerfer/fix/upgrade_securitychecker
Fix logic to cope with changes after securitychecker upgrade
2 parents 1cfa758 + b7ba766 commit 9847a3b

5 files changed

Lines changed: 33 additions & 11 deletions

File tree

build.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<project name="securitychecker" basedir="." default="check">
2+
<project name="securitychecker" basedir="." default="security:check">
33

44
<taskdef name="securitychecker" classpath="${phing.dir.securitychecker}/src" classname="bitExpert\Phing\SecurityChecker\SecurityCheckerTask" />
55

@@ -16,6 +16,15 @@
1616
</then>
1717
</if>
1818

19+
<if>
20+
<not>
21+
<isset property="securitychecker.endpoint" />
22+
</not>
23+
<then>
24+
<property name="securitychecker.endpoint" value="" override="true" />
25+
</then>
26+
</if>
27+
1928
<securitychecker lockfile="${securitychecker.lockfile}" endpoint="${securitychecker.endpoint}" />
2029
</target>
2130
</project>

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"license": "Apache-2.0",
1818
"require": {
1919
"php": "^7.1",
20+
"ext-json": "*",
2021
"phing/phing": "^2.8.0",
2122
"sensiolabs/security-checker": "^5.0"
2223
},

composer.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bitExpert/Phing/SecurityChecker/SecurityCheckerTask.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ public function main()
6767
}
6868

6969
$checker = $this->getSecurityChecker();
70-
$vulnerabilities = [];
71-
7270
try {
7371
if (!empty($this->timeout)) {
7472
$checker->getCrawler()->setTimeout($this->timeout);
@@ -77,8 +75,22 @@ public function main()
7775
$checker->getCrawler()->setEndPoint($this->endPoint);
7876
}
7977

80-
$vulnerabilities = $checker->check($this->lockFile);
81-
foreach ($vulnerabilities as $dependency => $issues) {
78+
$vulnerabilities = $checker->check($this->lockFile, 'json');
79+
if ($vulnerabilities->count() === 0) {
80+
$this->log('No vulnerabilities found!');
81+
return;
82+
}
83+
84+
if ($vulnerabilities->getFormat() !== 'json') {
85+
throw new \BuildException('Was expecting JSON response, but got "' . $vulnerabilities->getFormat().'"');
86+
}
87+
88+
$dependencies = json_decode($vulnerabilities->__toString(), true);
89+
if (!is_array($dependencies)) {
90+
throw new \BuildException('The web service response could not be parsed!');
91+
}
92+
93+
foreach ($dependencies as $dependency => $issues) {
8294
$dependencyFullName = $dependency . ' (' . $issues['version'] . ')';
8395
$this->log($dependencyFullName);
8496
$this->log(str_repeat('-', strlen($dependencyFullName)));
@@ -101,9 +113,7 @@ public function main()
101113
throw new \BuildException($e);
102114
}
103115

104-
if (count($vulnerabilities) > 0) {
105-
throw new \BuildException('Vulnerabilities found!');
106-
}
116+
throw new \BuildException('Vulnerabilities found!');
107117
}
108118

109119
/**

tests/bitExpert/Phing/SecurityChecker/SecurityCheckerTaskUnitTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use SensioLabs\Security\Crawler;
16+
use SensioLabs\Security\Result;
1617
use SensioLabs\Security\SecurityChecker;
1718

1819
/**
@@ -162,7 +163,7 @@ protected function createMockObjects(array $vulnerabilities = [])
162163
$this->checker = $this->createMock(SecurityChecker::class);
163164
$this->checker->expects($this->any())
164165
->method('check')
165-
->willReturn($vulnerabilities);
166+
->willReturn(new Result(count($vulnerabilities), json_encode($vulnerabilities), 'json'));
166167
$this->checker->expects($this->any())
167168
->method('getCrawler')
168169
->willReturn($this->crawler);

0 commit comments

Comments
 (0)