mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2025-02-05 14:20:08 +08:00
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()
|
||||
{
|
||||
$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', []);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user