From 04bf62f1c5718bf39ccf47ee02127b570e5e6ee1 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Tue, 18 Nov 2025 10:06:09 -0100 Subject: [PATCH] allow test during :check Signed-off-by: Maxence Lange --- lib/Command/CirclesCheck.php | 6 ++++++ lib/Controller/EventWrapperController.php | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/Command/CirclesCheck.php b/lib/Command/CirclesCheck.php index b5dcdb8a6..7188888e7 100644 --- a/lib/Command/CirclesCheck.php +++ b/lib/Command/CirclesCheck.php @@ -63,6 +63,7 @@ use OCA\Circles\Tools\Traits\TArrayTools; use OCA\Circles\Tools\Traits\TNCRequest; use OCA\Circles\Tools\Traits\TStringTools; +use OCP\IConfig; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -107,6 +108,8 @@ class CirclesCheck extends Base { /** @var ConfigService */ private $configService; + /** @var IConfig */ + private $config; /** @var array */ private $sessions = []; @@ -125,6 +128,7 @@ class CirclesCheck extends Base { */ public function __construct( Capabilities $capabilities, + IConfig $config, InterfaceService $interfaceService, FederatedEventService $federatedEventService, RemoteService $remoteService, @@ -135,6 +139,7 @@ public function __construct( parent::__construct(); $this->capabilities = $capabilities; + $this->config = $config; $this->interfaceService = $interfaceService; $this->federatedEventService = $federatedEventService; $this->remoteService = $remoteService; @@ -333,6 +338,7 @@ private function testLoopback(InputInterface $input, OutputInterface $output): b return false; } + $this->config->setAppValue(Application::APP_ID, 'test_dummy_token', (string)(time() + 10)); if (!$this->testRequest( $output, 'POST', 'circles.EventWrapper.asyncBroadcast', ['token' => 'test-dummy-token'] diff --git a/lib/Controller/EventWrapperController.php b/lib/Controller/EventWrapperController.php index 0e09afe45..d04436648 100644 --- a/lib/Controller/EventWrapperController.php +++ b/lib/Controller/EventWrapperController.php @@ -42,6 +42,7 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; +use OCP\IConfig; use OCP\IRequest; /** @@ -68,7 +69,8 @@ class EventWrapperController extends Controller { /** @var ConfigService */ private $configService; - + /** @var IConfig */ + private $config; /** * EventWrapperController constructor. @@ -84,6 +86,7 @@ class EventWrapperController extends Controller { public function __construct( string $appName, IRequest $request, + IConfig $config, EventWrapperService $eventWrapperService, FederatedEventService $federatedEventService, RemoteUpstreamService $remoteUpstreamService, @@ -91,6 +94,7 @@ public function __construct( ConfigService $configService ) { parent::__construct($appName, $request); + $this->config = $config; $this->eventWrapperService = $eventWrapperService; $this->federatedEventService = $federatedEventService; $this->remoteUpstreamService = $remoteUpstreamService; @@ -121,6 +125,10 @@ public function asyncBroadcast(string $token): DataResponse { return new DataResponse(null, Http::STATUS_OK); } + if ($token === 'test-dummy-token' && ((int)$this->config->getAppValue(Application::APP_ID, 'test_dummy_token', '0')) < time()) { + return new DataResponse([], Http::STATUS_UNAUTHORIZED); + } + // closing socket, keep current process running. $this->async();