-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cs278\ComposerAudit; | ||
|
||
use Composer\Composer; | ||
use Composer\Semver\Semver; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\Process\Exception\ProcessFailedException; | ||
use Symfony\Component\Process\Process; | ||
|
||
use function Cs278\Mktemp\temporaryDir; | ||
|
||
/** | ||
* @covers Cs278\ComposerAudit\AdvisoriesManager | ||
*/ | ||
final class AdvisoriesManagerTest extends TestCase | ||
{ | ||
use SetUpTearDownTrait; | ||
|
||
/** | ||
* @dataProvider dataFindByPackageNameAndVersion | ||
* | ||
*/ | ||
public function testFindByPackageNameAndVersion(array $expected, string $packageName, string $packageVersion, string $advisories) | ||
{ | ||
$manager = $this->createManager($advisories); | ||
$results = []; | ||
|
||
foreach ($manager->findByPackageNameAndVersion($packageName, $packageVersion) as $advisory) { | ||
$results[] = $advisory['title']; | ||
|
||
self::assertEquals(sprintf('composer://%s', $packageName), $advisory['reference']); | ||
} | ||
|
||
self::assertEquals($expected, $results); | ||
} | ||
|
||
public function dataFindByPackageNameAndVersion(): iterable | ||
{ | ||
yield [ | ||
[], | ||
'foo/bar', | ||
'13.37.0', | ||
'empty', | ||
]; | ||
yield [ | ||
[ | ||
'CVE-9999-1234567: Left the front door open', | ||
], | ||
'foo/bar', | ||
'13.37', | ||
'simple', | ||
]; | ||
} | ||
|
||
private function createManager(string $advisories): AdvisoriesManager | ||
{ | ||
$installer = new class($advisories) implements AdvisoriesInstallerInterface { | ||
private $advisories; | ||
|
||
public function __construct(string $advisories) | ||
{ | ||
$this->advisories = __DIR__.'/advisories/'.$advisories; | ||
|
||
if (!is_dir($this->advisories)) { | ||
throw new \InvalidArgumentException(sprintf( | ||
'%s is invalid, `%s` is not a directory', | ||
$advisories, | ||
$this->advisories | ||
)); | ||
} | ||
} | ||
|
||
public function mustUpdate() | ||
{ | ||
return; // No op | ||
} | ||
|
||
public function install($varDirectory, $packageName, $packageConstraint) | ||
{ | ||
return $this->advisories; | ||
} | ||
}; | ||
|
||
return new AdvisoriesManager($installer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
{ | ||
"name": "sensiolabs/security-advisories", | ||
"description": "Database of known security vulnerabilities in various PHP projects and libraries", | ||
"license": "Unlicense" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
{ | ||
"name": "sensiolabs/security-advisories", | ||
"description": "Database of known security vulnerabilities in various PHP projects and libraries", | ||
"license": "Unlicense" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
title: "CVE-9999-1234567: Left the front door open" | ||
link: https://example.com/CVE-9999-1234567 | ||
cve: CVE-9999-1234567 | ||
branches: | ||
"1337": | ||
time: 2020-01-01 12:32:00 | ||
versions: ['>=13.37.0', '<13.37.100'] | ||
reference: composer://foo/bar |