Add version check for market registry
This commit is contained in:
parent
d7b78324f8
commit
a24e34cf5e
|
|
@ -103,6 +103,7 @@ class MarketController extends Controller
|
||||||
|
|
||||||
protected function getAllAvailablePlugins()
|
protected function getAllAvailablePlugins()
|
||||||
{
|
{
|
||||||
|
$registryVersion = 1;
|
||||||
if (app()->environment('testing') || ! $this->registryCache) {
|
if (app()->environment('testing') || ! $this->registryCache) {
|
||||||
try {
|
try {
|
||||||
$pluginsJson = $this->guzzle->request(
|
$pluginsJson = $this->guzzle->request(
|
||||||
|
|
@ -115,6 +116,10 @@ class MarketController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->registryCache = json_decode($pluginsJson, true);
|
$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', []);
|
return Arr::get($this->registryCache, 'packages', []);
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,7 @@ class MarketControllerTest extends TestCase
|
||||||
$this->setupGuzzleClientMock([
|
$this->setupGuzzleClientMock([
|
||||||
new RequestException('Connection Error', new Request('POST', 'whatever')),
|
new RequestException('Connection Error', new Request('POST', 'whatever')),
|
||||||
new Response(200, [], $registry),
|
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.
|
// 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']);
|
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
|
protected function tearDown(): void
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user