Skip to content

Commit

Permalink
Merge pull request #71 from packagist/security-issues
Browse files Browse the repository at this point in the history
SecurityIssues: add endpoints to view, open, and close issues
  • Loading branch information
pscheit committed Nov 2, 2023
2 parents 4b7b2ce + cb723e8 commit 32d958b
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/Api/SecurityIssues.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,19 @@ public function all(array $filters = [])
{
return $this->get('/security-issues/', $filters);
}

public function show(int $issueId): array
{
return $this->get('/security-issues/' . $issueId);
}

public function open(int $issueId): array
{
return $this->post('/security-issues/' . $issueId . '/open');
}

public function close(int $issueId, string $state): array
{
return $this->post('/security-issues/' . $issueId . '/close/' . $state);
}
}
84 changes: 81 additions & 3 deletions tests/Api/SecurityIssuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class SecurityIssuesTest extends ApiTestCase
{
public function testAll()
public function testAll(): void
{
$expected = [
[
Expand Down Expand Up @@ -41,7 +41,7 @@ public function testAll()
$this->assertSame($expected, $api->all());
}

public function testAllWithFilters()
public function testAllWithFilters(): void
{
$expected = [
[
Expand Down Expand Up @@ -73,7 +73,85 @@ public function testAllWithFilters()
$this->assertSame($expected, $api->all($filters));
}

protected function getApiClass()
public function testShow(): void
{
$expected = [
'packageName' => 'acme-website/package',
'state' => 'open',
'branch' => 'dev-master',
'installedPackage' => 'acme/library',
'installedVersion' => '1.0.0',
'advisory' => [
'title' => 'CVE-1999: Remote code execution',
'link' =>'https://acme.website/security-advisories',
'cve' => 'CVE-1999',
'affectedVersions' => '>=1.0',
],
];

/** @var SecurityIssues&MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($this->equalTo('/security-issues/12'))
->willReturn($expected);

$this->assertSame($expected, $api->show(12));
}

public function testOpen(): void
{
$expected = [
'packageName' => 'acme-website/package',
'state' => 'open',
'branch' => 'dev-master',
'installedPackage' => 'acme/library',
'installedVersion' => '1.0.0',
'advisory' => [
'title' => 'CVE-1999: Remote code execution',
'link' =>'https://acme.website/security-advisories',
'cve' => 'CVE-1999',
'affectedVersions' => '>=1.0',
],
];

/** @var SecurityIssues&MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with($this->equalTo('/security-issues/12/open'))
->willReturn($expected);

$this->assertSame($expected, $api->open(12));
}

public function testClose(): void
{
$expected = [
'packageName' => 'acme-website/package',
'state' => SecurityIssues::STATE_IN_PROGRESS,
'branch' => 'dev-master',
'installedPackage' => 'acme/library',
'installedVersion' => '1.0.0',
'advisory' => [
'title' => 'CVE-1999: Remote code execution',
'link' =>'https://acme.website/security-advisories',
'cve' => 'CVE-1999',
'affectedVersions' => '>=1.0',
],
];

/** @var SecurityIssues&MockObject $api */
$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with($this->equalTo('/security-issues/12/close/' . SecurityIssues::STATE_IN_PROGRESS))
->willReturn($expected);

$this->assertSame($expected, $api->close(12, SecurityIssues::STATE_IN_PROGRESS));
}

protected function getApiClass(): string
{
return SecurityIssues::class;
}
Expand Down

0 comments on commit 32d958b

Please sign in to comment.