From d6a58529d7a4308e58cbca46b5f3e4cd39377903 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 13 Aug 2026 00:11:45 +0530 Subject: [PATCH] Simplify the start command assertion SitesBase carries thirty-nine helpers with no docblocks and a single inline comment, so a getter that also asserts, a memoised trait property and a recursion threading a path string for its failure messages all sat well outside the file. Encode the payload once and assert against the string. The key check gets stronger as a result - it catches startCommand at any depth without walking - and JSON_UNESCAPED_SLASHES keeps the helper paths intact, which the default encoding would have hidden behind escaped slashes. --- tests/e2e/Services/Sites/SitesBase.php | 53 ++++---------------------- 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/tests/e2e/Services/Sites/SitesBase.php b/tests/e2e/Services/Sites/SitesBase.php index c48814332d..f56536f76c 100644 --- a/tests/e2e/Services/Sites/SitesBase.php +++ b/tests/e2e/Services/Sites/SitesBase.php @@ -19,9 +19,6 @@ trait SitesBase protected string $stdout = ''; protected string $stderr = ''; - /** @var list|null */ - protected ?array $internalStartCommands = null; - protected function setupSite(mixed $params): string { $site = $this->client->call(Client::METHOD_POST, '/sites', array_merge([ @@ -501,57 +498,21 @@ trait SitesBase return $specification['slug']; } - /** - * The commands that boot a framework are an internal contract between Appwrite and the - * runtime image, and they change without notice. Leaking one lets a client copy it into - * their own site, so it must not reach a response body at all - not as a value a console - * could render, and not as a default a console could offer as a placeholder. - * - * @return list - */ - protected function getInternalStartCommands(): array + protected function assertStartCommandNotExposed(array $payload): void { - if ($this->internalStartCommands !== null) { - return $this->internalStartCommands; - } + $body = \json_encode($payload, JSON_UNESCAPED_SLASHES); - $commands = []; + $this->assertStringNotContainsString('startCommand', $body); + + // Every framework start command shells out to a helper script shipped in the runtime image. + $this->assertStringNotContainsString('helpers/', $body); foreach (Config::getParam('frameworks', []) as $framework) { foreach ($framework['adapters'] ?? [] as $adapter) { if (!empty($adapter['startCommand'])) { - $commands[] = $adapter['startCommand']; + $this->assertStringNotContainsString($adapter['startCommand'], $body); } } } - - $this->assertNotEmpty($commands, 'Expected at least one framework to define a start command.'); - - $this->internalStartCommands = \array_values(\array_unique($commands)); - - return $this->internalStartCommands; - } - - protected function assertStartCommandNotExposed(mixed $payload, string $path = 'body'): void - { - if (\is_string($payload)) { - foreach ($this->getInternalStartCommands() as $command) { - $this->assertNotSame($command, $payload, 'Internal start command exposed at ' . $path); - } - - // Every internal command shells out to a helper script shipped in the runtime image. - $this->assertStringNotContainsString('helpers/', $payload, 'Internal helper script exposed at ' . $path); - - return; - } - - if (!\is_array($payload)) { - return; - } - - foreach ($payload as $key => $value) { - $this->assertNotSame('startCommand', $key, 'Start command exposed at ' . $path . '.' . $key); - $this->assertStartCommandNotExposed($value, $path . '.' . $key); - } } }