-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Repo JSON Performance Improvements (#310)
* Fix Composer v2 package provider 404 > Any requested package which does not exist MUST return a 404 status code, which will indicate to Composer that this package does not exist in your repository. Make sure the 404 response is fast to avoid blocking Composer. Avoid redirects to alternative 404 pages. * Cache repo endpoints It needs to return the last modified date from the providers to use in the HTTP Response. Also fix minor performance improvement with array_merge * Add available-packages for Composer v2 This contains the full list of packages available on the repo. This stops Composer attempting to access the metadata-url for 'public' packages. * Fix Scanner Tests The mock wasn't updated to reflect the change in function. However, the tests weren't actually checking the scan was working. Co-authored-by: Arkadiusz Kondas <[email protected]>
- Loading branch information
Showing
6 changed files
with
138 additions
and
25 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
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
namespace Buddy\Repman\Tests\Functional\Controller; | ||
|
||
use Buddy\Repman\Tests\Functional\FunctionalTestCase; | ||
use Ramsey\Uuid\Uuid; | ||
use Symfony\Component\HttpFoundation\BinaryFileResponse; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
|
@@ -63,7 +64,11 @@ public function testOrganizationPackagesAction(): void | |
{ | ||
// create and login admin to check token last used date is changed | ||
$adminId = $this->createAndLoginAdmin('[email protected]', 'secret'); | ||
$this->fixtures->createToken($this->fixtures->createOrganization('buddy', $adminId), 'secret-org-token'); | ||
$organizationId = $this->fixtures->createOrganization('buddy', $adminId); | ||
$this->fixtures->createToken($organizationId, 'secret-org-token'); | ||
$packageId = Uuid::uuid4()->toString(); | ||
$this->fixtures->createPackage($packageId, 'buddy', $organizationId); | ||
$this->fixtures->syncPackageWithData($packageId, 'buddy-works/repman', 'Test', '1.1.1', new \DateTimeImmutable()); | ||
|
||
// check token was never used | ||
$this->client->request('GET', $this->urlTo('organization_tokens', ['organization' => 'buddy'])); | ||
|
@@ -75,9 +80,24 @@ public function testOrganizationPackagesAction(): void | |
'PHP_AUTH_PW' => 'secret-org-token', | ||
]); | ||
|
||
self::assertMatchesPattern(' | ||
self::assertJsonStringEqualsJsonString(' | ||
{ | ||
"packages": [], | ||
"packages": { | ||
"buddy-works\/repman": { | ||
"1.2.3": { | ||
"version": "1.2.3", | ||
"version_normalized": "1.2.3.0", | ||
"dist": { | ||
"type": "zip", | ||
"url": "\/path\/to\/reference.zip", | ||
"reference": "ac7dcaf888af2324cd14200769362129c8dd8550" | ||
} | ||
} | ||
} | ||
}, | ||
"available-packages": [ | ||
"buddy-works/repman" | ||
], | ||
"metadata-url": "/p2/%package%.json", | ||
"notify-batch": "http://buddy.repo.repman.wip/downloads", | ||
"search": "https://packagist.org/search.json?q=%query%&type=%type%", | ||
|
@@ -191,4 +211,37 @@ public function testProviderV2Action(): void | |
} | ||
', $this->client->getResponse()->getContent()); | ||
} | ||
|
||
public function testProviderV2ActionWithCache(): void | ||
{ | ||
$adminId = $this->createAndLoginAdmin('[email protected]', 'secret'); | ||
$this->fixtures->createToken($this->fixtures->createOrganization('buddy', $adminId), 'secret-org-token'); | ||
|
||
$fileModifiedTime = (new \DateTimeImmutable()) | ||
->setTimestamp((int) filemtime(__DIR__.'/../../Resources/p2/buddy-works/repman.json')); | ||
|
||
$this->client->request('GET', '/p2/buddy-works/repman.json', [], [], [ | ||
'HTTP_HOST' => 'buddy.repo.repman.wip', | ||
'PHP_AUTH_USER' => 'token', | ||
'PHP_AUTH_PW' => 'secret-org-token', | ||
'HTTP_IF_MODIFIED_SINCE' => $fileModifiedTime->format('D, d M Y H:i:s \G\M\T'), | ||
]); | ||
|
||
self::assertEquals(304, $this->client->getResponse()->getStatusCode()); | ||
self::assertEmpty($this->client->getResponse()->getContent()); | ||
} | ||
|
||
public function testProviderV2ForMissingPackage(): void | ||
{ | ||
$adminId = $this->createAndLoginAdmin('[email protected]', 'secret'); | ||
$this->fixtures->createToken($this->fixtures->createOrganization('buddy', $adminId), 'secret-org-token'); | ||
|
||
$this->client->request('GET', '/p2/buddy-works/fake.json', [], [], [ | ||
'HTTP_HOST' => 'buddy.repo.repman.wip', | ||
'PHP_AUTH_USER' => 'token', | ||
'PHP_AUTH_PW' => 'secret-org-token', | ||
]); | ||
|
||
self::assertTrue($this->client->getResponse()->isNotFound()); | ||
} | ||
} |
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