mirror of
https://github.com/pterodactyl/panel.git
synced 2026-11-30 11:25:52 -05:00
Co-authored-by: Anthony <anthony@infraly.co> Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Pterodactyl\Tests\Support\Fakes;
|
|
|
|
use GuzzleHttp\Promise\PromiseInterface;
|
|
use Illuminate\Http\Client\Request;
|
|
use PHPUnit\Framework\Assert;
|
|
|
|
class FakeDaemonRevocation extends FakeDaemonHttpClient
|
|
{
|
|
/**
|
|
* @param ?string[] $servers
|
|
*/
|
|
public function assertDeauthorized(string $user, ?array $servers = null): void
|
|
{
|
|
$calls = $this->callsFor('deauthorize');
|
|
|
|
Assert::assertNotEmpty($calls, 'Expected daemon deauthorize to have been called.');
|
|
|
|
foreach ($calls as $call) {
|
|
if (($call['user'] ?? null) !== $user) {
|
|
continue;
|
|
}
|
|
|
|
if ($servers === null || ($call['servers'] ?? null) === $servers) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
Assert::fail(sprintf('Expected daemon deauthorize for user [%s] to have been called.', $user));
|
|
}
|
|
|
|
protected function responseFor(Request $request): ?PromiseInterface
|
|
{
|
|
if (parse_url($request->url(), PHP_URL_PATH) !== '/api/deauthorize-user' || $request->method() !== 'POST') {
|
|
return null;
|
|
}
|
|
|
|
$this->record('deauthorize', ['user' => $request['user'], 'servers' => $request['servers']]);
|
|
|
|
return $this->reply();
|
|
}
|
|
}
|