diff --git a/app/Http/Controllers/MarketController.php b/app/Http/Controllers/MarketController.php index 9fa9f3db..60935071 100644 --- a/app/Http/Controllers/MarketController.php +++ b/app/Http/Controllers/MarketController.php @@ -103,6 +103,7 @@ class MarketController extends Controller protected function getAllAvailablePlugins() { + $registryVersion = 1; if (app()->environment('testing') || ! $this->registryCache) { try { $pluginsJson = $this->guzzle->request( @@ -115,6 +116,10 @@ class MarketController extends Controller } $this->registryCache = json_decode($pluginsJson, true); + $received = Arr::get($this->registryCache, 'version'); + if (is_int($received) && $received != $registryVersion) { + throw new Exception("Only version $registryVersion of market registry is accepted."); + } } return Arr::get($this->registryCache, 'packages', []); diff --git a/tests/MarketControllerTest.php b/tests/MarketControllerTest.php index a2950c62..6dbef4be 100644 --- a/tests/MarketControllerTest.php +++ b/tests/MarketControllerTest.php @@ -92,6 +92,7 @@ class MarketControllerTest extends TestCase $this->setupGuzzleClientMock([ new RequestException('Connection Error', new Request('POST', 'whatever')), new Response(200, [], $registry), + new Response(200, [], json_encode(array_merge(json_decode($registry, true), ['version' => 0]))), ]); // Expected an exception, but unable to be asserted. @@ -112,6 +113,10 @@ class MarketControllerTest extends TestCase ]); File::deleteDirectory(config('plugins.directory').DIRECTORY_SEPARATOR.$package['name']); + + $this + ->getJson('/admin/plugins/market-data') + ->assertJson(['message' => 'Only version 1 of market registry is accepted.']); } protected function tearDown(): void