1
0
Fork 0
get-installer-bootstrap/tests/Controller/PublicScriptControllerTest.php

45 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2026-05-05 07:53:54 +00:00
<?php
namespace App\Tests\Controller;
use App\Entity\ScriptMapping;
2026-05-05 08:06:55 +00:00
use App\Tests\DatabaseWebTestCase;
2026-05-05 07:53:54 +00:00
2026-05-05 08:06:55 +00:00
final class PublicScriptControllerTest extends DatabaseWebTestCase
2026-05-05 07:53:54 +00:00
{
public function testUnknownPathReturnsNotFound(): void
{
$this->client->request('GET', '/missing/install.sh');
self::assertResponseStatusCodeSame(404);
}
public function testCachedScriptIsServed(): void
{
$container = static::getContainer();
$cacheDir = $container->getParameter('app.cache_dir');
if (!str_starts_with($cacheDir, '/')) {
$cacheDir = $container->getParameter('kernel.project_dir').'/'.$cacheDir;
}
@mkdir($cacheDir.'/scripts', 0775, true);
file_put_contents($cacheDir.'/scripts/test.sh', "#!/bin/sh\necho ok\n");
$mapping = (new ScriptMapping())
->setPublicPath('mcp/graylog/install.sh')
->setRepositoryUrl('https://forge.lclr.dev/AI/graylog-mcp.git')
->setGitRef('main')
->setRepositoryFilePath('install.sh')
->setCacheKey('scripts/test.sh');
$mapping->markSyncSucceeded('scripts/test.sh');
$this->entityManager->persist($mapping);
$this->entityManager->flush();
$this->client->request('GET', '/mcp/graylog/install.sh');
self::assertResponseIsSuccessful();
self::assertResponseHeaderSame('content-type', 'text/x-shellscript; charset=UTF-8');
self::assertStringContainsString('echo ok', (string) $this->client->getResponse()->getContent());
}
}