44 lines
1.5 KiB
PHP
44 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Controller;
|
|
|
|
use App\Entity\ScriptMapping;
|
|
use App\Tests\DatabaseWebTestCase;
|
|
|
|
final class PublicScriptControllerTest extends DatabaseWebTestCase
|
|
{
|
|
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());
|
|
}
|
|
}
|