Skip to content

Commit 4489fb9

Browse files
authored
Merge pull request #43 from packagist/t/add-security-notice-api
Add security issues endpoints
2 parents 48c2d54 + 0e1ccd0 commit 4489fb9

File tree

6 files changed

+198
-2
lines changed

6 files changed

+198
-2
lines changed

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
* [Delete a package](#delete-a-package)
7171
* [List all dependents of a package](#list-all-dependents-of-a-package)
7272
* [List all customers with access to a package](#list-all-customers-with-access-to-a-package)
73+
* [List all security issues of a package](#list-all-security-issues-of-a-package)
7374
* [Create an artifact package file](#create-an-artifact-package-file)
7475
* [Create an artifact package](#create-an-artifact-package)
7576
* [Add an artifact file to an existing package](#add-an-artifact-file-to-an-existing-package)
@@ -92,14 +93,16 @@
9293
* [Job](#job)
9394
* [Show a job](#show-a-job)
9495
* [Wait for a job to finish](#wait-for-a-job-to-finish)
96+
* [Security Issue](#security-issue)
97+
* [List an organization's security issues](#list-an-organizations-security-issues)
9598
* [Magento legacy keys](#magento-legacy-keys)
9699
* [List all legacy keys for a customer](#list-all-legacy-keys-for-a-customer)
97100
* [Create a new legacy keys for a customer](#create-a-new-legacy-keys-for-a-customer)
98101
* [Delete a legacy keys from a customer](#delete-a-legacy-keys-from-a-customer)
99102
* [Validate incoming webhook payloads](#validate-incoming-webhook-payloads)
100103
* [License](#license)
101104

102-
<!-- Added by: wissem, at: Fri Oct 16 14:23:54 CEST 2020 -->
105+
<!-- Added by: wissem, at: Wed May 26 12:28:19 CEST 2021 -->
103106

104107
<!--te-->
105108

@@ -505,7 +508,8 @@ $client->subrepositories()->mirroredRepositories()->removePackages($subrepositor
505508
#### List an organization's packages
506509
```php
507510
$filters = [
508-
'origin' => \PrivatePackagist\ApiClient\Api\Packages::ORIGIN_PRIVATE, // optional filter to only receive packages that can be added to customers
511+
'origin' => \PrivatePackagist\ApiClient\Api\Packages::ORIGIN_PRIVATE, // optional filter to only receive packages that can be added to customers,
512+
'security-issue-state' => \PrivatePackagist\ApiClient\Api\SecurityIssues::STATE_OPEN, // optional filter to filter packages with open security issues,
509513
];
510514
$packages = $client->packages()->all($filters);
511515
```
@@ -581,6 +585,15 @@ $client->packages()->listCustomers('acme-website/package');
581585
```
582586
Returns a list of customers with access to the package.
583587

588+
#### List all security issues of a package
589+
```php
590+
$filters = [
591+
'security-issue-state' => \PrivatePackagist\ApiClient\Api\SecurityIssues::STATE_OPEN,
592+
];
593+
$client->packages()->listSecurityIssues('acme-website/package', $filters);
594+
```
595+
Returns a list of security issues.
596+
584597
#### Create an artifact package file
585598

586599
```php
@@ -746,6 +759,18 @@ try {
746759
```
747760
Returns the job.
748761

762+
### Security Issue
763+
764+
#### List an organization's security issues
765+
766+
```php
767+
$filters = [
768+
'security-issue-state' => \PrivatePackagist\ApiClient\Api\SecurityIssues::STATE_OPEN, // optional filter to filter packages with open security issues,
769+
];
770+
$packages = $client->securityIssues()->all($filters);
771+
```
772+
Returns an array of security issues.
773+
749774
### Magento legacy keys
750775

751776
#### List all legacy keys for a customer

src/Api/Packages.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ public function listDependents($packageName)
120120
return $this->get(sprintf('/packages/%s/dependents/', $packageName));
121121
}
122122

123+
public function listSecurityIssues($packageName, array $filters = [])
124+
{
125+
return $this->get(sprintf('/packages/%s/security-issues/', $packageName), $filters);
126+
}
127+
123128
public function artifacts()
124129
{
125130
return new Artifacts($this->client, $this->client->getResponseMediator());

src/Api/SecurityIssues.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* (c) Packagist Conductors UG (haftungsbeschränkt) <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
namespace PrivatePackagist\ApiClient\Api;
11+
12+
class SecurityIssues extends AbstractApi
13+
{
14+
/**
15+
* Security issue that is still open
16+
*/
17+
const STATE_OPEN = 'open';
18+
19+
/**
20+
* Security issue where a fix is in progress
21+
*/
22+
const STATE_IN_PROGRESS = 'in-progress';
23+
24+
/**
25+
* Security issue that doesn't affect the project
26+
*/
27+
const STATE_NOT_AFFECTED = 'not-affected';
28+
29+
/**
30+
* Security issue that is incorrect
31+
*/
32+
const STATE_INCORRECT = 'incorrect';
33+
34+
/**
35+
* Security issue where there is no capacity to fix the issue
36+
*/
37+
const STATE_NO_CAPACITY = 'no-capacity';
38+
39+
/**
40+
* Security issue that can be ignored
41+
*/
42+
const STATE_IGNORE = 'ignore';
43+
44+
/**
45+
* Security issue that has been resolved
46+
*/
47+
const STATE_RESOLVED = 'resolved';
48+
49+
public function all(array $filters = [])
50+
{
51+
return $this->get('/security-issues/', $filters);
52+
}
53+
}

src/Client.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ public function packages()
8888
return new Api\Packages($this, $this->responseMediator);
8989
}
9090

91+
public function securityIssues()
92+
{
93+
return new Api\SecurityIssues($this, $this->responseMediator);
94+
}
95+
96+
9197
public function jobs()
9298
{
9399
return new Api\Jobs($this, $this->responseMediator);

tests/Api/PackagesTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,35 @@ public function testListDependents()
261261
$this->assertSame($expected, $api->listDependents($packageName));
262262
}
263263

264+
public function testListSecurityIssues()
265+
{
266+
$packageName = 'acme-website/core-package';
267+
$expected = [
268+
[
269+
'packageName' => 'acme-website/package',
270+
'state' => 'open',
271+
'branch' => 'dev-master',
272+
'installedPackage' => 'acme/library',
273+
'installedVersion' => '1.0.0',
274+
'advisory' => [
275+
'title' => 'CVE-1999: Remote code execution',
276+
'link' =>'https://acme.website/security-advisories',
277+
'cve' => 'CVE-1999',
278+
'affectedVersions' => '>=1.0',
279+
],
280+
],
281+
];
282+
283+
/** @var Packages&\PHPUnit_Framework_MockObject_MockObject $api */
284+
$api = $this->getApiMock();
285+
$api->expects($this->once())
286+
->method('get')
287+
->with($this->equalTo('/packages/acme-website/core-package/security-issues/'))
288+
->willReturn($expected);
289+
290+
$this->assertSame($expected, $api->listSecurityIssues($packageName));
291+
}
292+
264293
protected function getApiClass()
265294
{
266295
return Packages::class;

tests/Api/SecurityIssuesTest.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
/*
4+
* (c) Packagist Conductors UG (haftungsbeschränkt) <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
namespace PrivatePackagist\ApiClient\Api;
11+
12+
class SecurityIssuesTest extends ApiTestCase
13+
{
14+
public function testAll()
15+
{
16+
$expected = [
17+
[
18+
'packageName' => 'acme-website/package',
19+
'state' => 'open',
20+
'branch' => 'dev-master',
21+
'installedPackage' => 'acme/library',
22+
'installedVersion' => '1.0.0',
23+
'advisory' => [
24+
'title' => 'CVE-1999: Remote code execution',
25+
'link' =>'https://acme.website/security-advisories',
26+
'cve' => 'CVE-1999',
27+
'affectedVersions' => '>=1.0',
28+
],
29+
],
30+
];
31+
32+
/** @var Packages&\PHPUnit_Framework_MockObject_MockObject $api */
33+
$api = $this->getApiMock();
34+
$api->expects($this->once())
35+
->method('get')
36+
->with($this->equalTo('/security-issues/'))
37+
->willReturn($expected);
38+
39+
$this->assertSame($expected, $api->all());
40+
}
41+
42+
public function testAllWithFilters()
43+
{
44+
$expected = [
45+
[
46+
'packageName' => 'acme-website/package',
47+
'state' => 'open',
48+
'branch' => 'dev-master',
49+
'installedPackage' => 'acme/library',
50+
'installedVersion' => '1.0.0',
51+
'advisory' => [
52+
'title' => 'CVE-1999: Remote code execution',
53+
'link' =>'https://acme.website/security-advisories',
54+
'cve' => 'CVE-1999',
55+
'affectedVersions' => '>=1.0',
56+
],
57+
],
58+
];
59+
60+
$filters = [
61+
'security-issue-state' => SecurityIssues::STATE_OPEN,
62+
];
63+
64+
/** @var Packages&\PHPUnit_Framework_MockObject_MockObject $api */
65+
$api = $this->getApiMock();
66+
$api->expects($this->once())
67+
->method('get')
68+
->with($this->equalTo('/security-issues/'), $this->equalTo($filters))
69+
->willReturn($expected);
70+
71+
$this->assertSame($expected, $api->all($filters));
72+
}
73+
74+
protected function getApiClass()
75+
{
76+
return SecurityIssues::class;
77+
}
78+
}

0 commit comments

Comments
 (0)