diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index ed323aa..3fe9535 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -62,7 +62,7 @@ jobs: - name: Scan etherpad instance uses: GuillaumeFalourd/assert-command-line-output@v2.4 with: - command_line: bin/console.php ether:scan -vvv http://localhost:8080 | grep -E "Package version|HTTP/1.1 400" | sed 's/ *$//' + command_line: bin/console.php ether:scan -vvv http://localhost:8080 | grep -E "Package version|HTTP/1.1 400|Websocket" | sed 's/ *$//' assert_file_path: tests/e2e/fixture/reverse_proxy_no_websocket.txt expected_result: PASSED diff --git a/src/Console/ScanCommandOutputHelper.php b/src/Console/ScanCommandOutputHelper.php index e0dd7d4..3521362 100644 --- a/src/Console/ScanCommandOutputHelper.php +++ b/src/Console/ScanCommandOutputHelper.php @@ -137,9 +137,14 @@ public function onScanPadException(Throwable $e): void $this->symfonyStyle->error($e->getMessage()); } - public function onScanPadSuccess(): void + public function onScanPadSuccess(bool $usedWebsocket): void { $this->symfonyStyle->success('Pads are publicly accessible'); + if ($usedWebsocket) { + $this->symfonyStyle->success('Websocket is supported'); + } else { + $this->symfonyStyle->error('Websocket is not supported'); + } } public function onVersionResult(?string $minVersion, ?string $maxVersion): void diff --git a/src/Service/ScannerService.php b/src/Service/ScannerService.php index 96a3e02..0da85e9 100644 --- a/src/Service/ScannerService.php +++ b/src/Service/ScannerService.php @@ -4,6 +4,7 @@ namespace Gared\EtherScan\Service; use ElephantIO\Client as ElephantClient; +use ElephantIO\Engine\SocketIO; use Exception; use Gared\EtherScan\Api\GithubApi; use Gared\EtherScan\Exception\EtherpadServiceNotFoundException; @@ -337,6 +338,10 @@ private function doSocketWebsocket( 'password' => null, 'protocolVersion' => 2, ]); + $engine = $socketIoClient->getEngine(); + if ($engine instanceof SocketIO === false) { + throw new Exception('Engine of unsupported class'); + } while ($result = $socketIoClient->wait('message', 2)) { if (is_array($result->data)) { @@ -357,7 +362,7 @@ private function doSocketWebsocket( $this->versionRangeService->setPackageVersion($version); $callback->onClientVars($version, $result->data); $callback->onScanPluginsList($onlyPlugins); - $callback->onScanPadSuccess(); + $callback->onScanPadSuccess($engine->getTransport() === SocketIO::TRANSPORT_WEBSOCKET); break; } } diff --git a/src/Service/ScannerServiceCallbackInterface.php b/src/Service/ScannerServiceCallbackInterface.php index 05f097b..ec8d44b 100644 --- a/src/Service/ScannerServiceCallbackInterface.php +++ b/src/Service/ScannerServiceCallbackInterface.php @@ -54,7 +54,7 @@ public function onScanPadStart(): void; public function onScanPadException(Throwable $e): void; - public function onScanPadSuccess(): void; + public function onScanPadSuccess(bool $usedWebsocket): void; public function onVersionResult(?string $minVersion, ?string $maxVersion): void; @@ -64,4 +64,4 @@ public function onVersionResult(?string $minVersion, ?string $maxVersion): void; public function onClientVars(string $version, array $data): void; public function getConsoleLogger(): ?LoggerInterface; -} \ No newline at end of file +} diff --git a/tests/e2e/fixture/latest.txt b/tests/e2e/fixture/latest.txt index 2ad8f7a..5d865c5 100644 --- a/tests/e2e/fixture/latest.txt +++ b/tests/e2e/fixture/latest.txt @@ -15,6 +15,8 @@ Starting scan of a pad... [OK] Pads are publicly accessible + [OK] Websocket is supported + [OK] Server is healthy [INFO] Version is $EP_VERSION diff --git a/tests/e2e/fixture/master_with_plugins.txt b/tests/e2e/fixture/master_with_plugins.txt index 4c9861f..8c89d8e 100644 --- a/tests/e2e/fixture/master_with_plugins.txt +++ b/tests/e2e/fixture/master_with_plugins.txt @@ -20,6 +20,8 @@ Plugins: [OK] Pads are publicly accessible + [OK] Websocket is supported + [OK] Server is healthy diff --git a/tests/e2e/fixture/reverse_proxy_no_websocket.txt b/tests/e2e/fixture/reverse_proxy_no_websocket.txt index 0c5adf9..b40ba92 100644 --- a/tests/e2e/fixture/reverse_proxy_no_websocket.txt +++ b/tests/e2e/fixture/reverse_proxy_no_websocket.txt @@ -1,2 +1,3 @@ [debug] Stream receive: HTTP/1.1 400 Bad Request [INFO] Package version: 1.8.17 + [ERROR] Websocket is not supported