Skip to content

Commit 32d958b

Browse files
authored
Merge pull request #71 from packagist/security-issues
SecurityIssues: add endpoints to view, open, and close issues
2 parents 4b7b2ce + cb723e8 commit 32d958b

File tree

2 files changed

+96
-3
lines changed

2 files changed

+96
-3
lines changed

src/Api/SecurityIssues.php

+15
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,19 @@ public function all(array $filters = [])
5050
{
5151
return $this->get('/security-issues/', $filters);
5252
}
53+
54+
public function show(int $issueId): array
55+
{
56+
return $this->get('/security-issues/' . $issueId);
57+
}
58+
59+
public function open(int $issueId): array
60+
{
61+
return $this->post('/security-issues/' . $issueId . '/open');
62+
}
63+
64+
public function close(int $issueId, string $state): array
65+
{
66+
return $this->post('/security-issues/' . $issueId . '/close/' . $state);
67+
}
5368
}

tests/Api/SecurityIssuesTest.php

+81-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class SecurityIssuesTest extends ApiTestCase
1515
{
16-
public function testAll()
16+
public function testAll(): void
1717
{
1818
$expected = [
1919
[
@@ -41,7 +41,7 @@ public function testAll()
4141
$this->assertSame($expected, $api->all());
4242
}
4343

44-
public function testAllWithFilters()
44+
public function testAllWithFilters(): void
4545
{
4646
$expected = [
4747
[
@@ -73,7 +73,85 @@ public function testAllWithFilters()
7373
$this->assertSame($expected, $api->all($filters));
7474
}
7575

76-
protected function getApiClass()
76+
public function testShow(): void
77+
{
78+
$expected = [
79+
'packageName' => 'acme-website/package',
80+
'state' => 'open',
81+
'branch' => 'dev-master',
82+
'installedPackage' => 'acme/library',
83+
'installedVersion' => '1.0.0',
84+
'advisory' => [
85+
'title' => 'CVE-1999: Remote code execution',
86+
'link' =>'https://acme.website/security-advisories',
87+
'cve' => 'CVE-1999',
88+
'affectedVersions' => '>=1.0',
89+
],
90+
];
91+
92+
/** @var SecurityIssues&MockObject $api */
93+
$api = $this->getApiMock();
94+
$api->expects($this->once())
95+
->method('get')
96+
->with($this->equalTo('/security-issues/12'))
97+
->willReturn($expected);
98+
99+
$this->assertSame($expected, $api->show(12));
100+
}
101+
102+
public function testOpen(): void
103+
{
104+
$expected = [
105+
'packageName' => 'acme-website/package',
106+
'state' => 'open',
107+
'branch' => 'dev-master',
108+
'installedPackage' => 'acme/library',
109+
'installedVersion' => '1.0.0',
110+
'advisory' => [
111+
'title' => 'CVE-1999: Remote code execution',
112+
'link' =>'https://acme.website/security-advisories',
113+
'cve' => 'CVE-1999',
114+
'affectedVersions' => '>=1.0',
115+
],
116+
];
117+
118+
/** @var SecurityIssues&MockObject $api */
119+
$api = $this->getApiMock();
120+
$api->expects($this->once())
121+
->method('post')
122+
->with($this->equalTo('/security-issues/12/open'))
123+
->willReturn($expected);
124+
125+
$this->assertSame($expected, $api->open(12));
126+
}
127+
128+
public function testClose(): void
129+
{
130+
$expected = [
131+
'packageName' => 'acme-website/package',
132+
'state' => SecurityIssues::STATE_IN_PROGRESS,
133+
'branch' => 'dev-master',
134+
'installedPackage' => 'acme/library',
135+
'installedVersion' => '1.0.0',
136+
'advisory' => [
137+
'title' => 'CVE-1999: Remote code execution',
138+
'link' =>'https://acme.website/security-advisories',
139+
'cve' => 'CVE-1999',
140+
'affectedVersions' => '>=1.0',
141+
],
142+
];
143+
144+
/** @var SecurityIssues&MockObject $api */
145+
$api = $this->getApiMock();
146+
$api->expects($this->once())
147+
->method('post')
148+
->with($this->equalTo('/security-issues/12/close/' . SecurityIssues::STATE_IN_PROGRESS))
149+
->willReturn($expected);
150+
151+
$this->assertSame($expected, $api->close(12, SecurityIssues::STATE_IN_PROGRESS));
152+
}
153+
154+
protected function getApiClass(): string
77155
{
78156
return SecurityIssues::class;
79157
}

0 commit comments

Comments
 (0)