Skip to content

Commit f1df535

Browse files
committed
Add functional tests for yarn and npm
1 parent 43c6ec9 commit f1df535

File tree

6 files changed

+96
-0
lines changed

6 files changed

+96
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace App\Tests\Functional;
4+
5+
use GuzzleHttp\Client;
6+
use GuzzleHttp\Psr7\Request;
7+
use GuzzleHttp\Psr7\Uri;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class NpmProxyAuditRequestTest extends TestCase
11+
{
12+
13+
/**
14+
* @var Client
15+
*/
16+
private $client;
17+
18+
public function setUp()
19+
{
20+
$this->client = new Client();
21+
}
22+
23+
public function testWithGzippedBody(): void
24+
{
25+
$request = new Request(
26+
'POST',
27+
new Uri('127.0.0.1/-/npm/v1/security/audits'),
28+
json_decode(file_get_contents(__DIR__ . '/../fixtures/headers-npm.json'), true),
29+
fopen(__DIR__ . '/../fixtures/request-body-npm.gz', 'r')
30+
);
31+
$response = $this->client->send($request);
32+
33+
$this->assertEquals(200, $response->getStatusCode(), 'Expected response to return a 200');
34+
$this->assertJson($response->getBody()->getContents(), 'Expected response to be valid Json');
35+
}
36+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace App\Tests\Functional;
4+
5+
use GuzzleHttp\Client;
6+
use GuzzleHttp\Psr7\Request;
7+
use GuzzleHttp\Psr7\Uri;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class YarnProxyAuditRequestTest extends TestCase
11+
{
12+
/**
13+
* @var Client
14+
*/
15+
private $client;
16+
17+
public function setUp()
18+
{
19+
$this->client = new Client();
20+
}
21+
22+
public function testWithGzippedBody(): void
23+
{
24+
$request = new Request(
25+
'POST',
26+
new Uri('127.0.0.1/-/npm/v1/security/audits'),
27+
json_decode(file_get_contents(__DIR__ . '/../fixtures/headers-yarn.json'), true),
28+
fopen(__DIR__ . '/../fixtures/request-body-yarn.gz', 'r')
29+
);
30+
$response = $this->client->send($request);
31+
32+
$this->assertEquals(200, $response->getStatusCode(), 'Expected response to return a 200');
33+
$this->assertJson($response->getBody()->getContents(), 'Expected response to be valid Json');
34+
}
35+
}

tests/fixtures/headers-npm.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"Accept": "*/*",
3+
"Accept-Encoding": "gzip,deflate",
4+
"Connection": "keep-alive",
5+
"Content-Encoding": "gzip",
6+
"Content-Length": 73012,
7+
"Content-Type": "application/json, application/octet-stream",
8+
"Host": "peterton.nl",
9+
"Npm-In-Ci": "false",
10+
"Npm-Scope": "",
11+
"Npm-Session": "4a4d074851a25e33",
12+
"Referer": "undefined",
13+
"User-Agent": "npm/6.4.1 node/v10.15.3 win32 x64",
14+
"X-Php-Ob-Level": 1
15+
}

tests/fixtures/headers-yarn.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Accept": "application/json",
3+
"Connection": "keep-alive",
4+
"Content-Encoding": "gzip",
5+
"Content-Length": 107070,
6+
"Content-Type": "application/json",
7+
"Host": "registry.yarnpkg.com",
8+
"User-Agent": "yarn/1.16.0 npm/? node/v10.15.3 win32 x64",
9+
"X-Php-Ob-Level": 1
10+
}

tests/fixtures/request-body-npm.gz

71.3 KB
Binary file not shown.

tests/fixtures/request-body-yarn.gz

105 KB
Binary file not shown.

0 commit comments

Comments
 (0)