60 lines
2.0 KiB
PHP
60 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MageSail\Magesail\Test\Unit\Model;
|
|
|
|
use MageSail\Magesail\Model\TunnelProcessPaths;
|
|
use Magento\Framework\App\Filesystem\DirectoryList;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class TunnelProcessPathsTest extends TestCase
|
|
{
|
|
public function testPidPathUsesVarTunnelDirAndSanitizedId(): void
|
|
{
|
|
$dir = new DirectoryList();
|
|
$dir->setTestPath(DirectoryList::VAR_DIR, '/var/magento/var');
|
|
$dir->setTestPath(DirectoryList::LOG, '/var/magento/var/log');
|
|
$paths = new TunnelProcessPaths($dir);
|
|
self::assertSame(
|
|
'/var/magento/var/magesail_tunnels/tunnel1.pid',
|
|
$paths->getPidFilePath('tunnel1')
|
|
);
|
|
}
|
|
|
|
public function testSanitizeIdStripsUnsafeCharacters(): void
|
|
{
|
|
$dir = new DirectoryList();
|
|
$dir->setTestPath(DirectoryList::VAR_DIR, '/v');
|
|
$dir->setTestPath(DirectoryList::LOG, '/v/log');
|
|
$paths = new TunnelProcessPaths($dir);
|
|
self::assertStringContainsString(
|
|
'/magesail_tunnels/ab.pid',
|
|
$paths->getPidFilePath('a!@#b')
|
|
);
|
|
}
|
|
|
|
public function testSanitizeIdFallsBackToInvalidWhenEmpty(): void
|
|
{
|
|
$dir = new DirectoryList();
|
|
$dir->setTestPath(DirectoryList::VAR_DIR, '/v');
|
|
$dir->setTestPath(DirectoryList::LOG, '/v/log');
|
|
$paths = new TunnelProcessPaths($dir);
|
|
self::assertStringEndsWith(
|
|
'/magesail_tunnels/invalid.pid',
|
|
$paths->getPidFilePath('!!!')
|
|
);
|
|
}
|
|
|
|
public function testLegacyPaths(): void
|
|
{
|
|
$dir = new DirectoryList();
|
|
$dir->setTestPath(DirectoryList::VAR_DIR, '/v');
|
|
$dir->setTestPath(DirectoryList::LOG, '/v/log');
|
|
$paths = new TunnelProcessPaths($dir);
|
|
self::assertSame('/v/magesail.pid', $paths->getLegacyPidFilePath());
|
|
self::assertSame('/v/magesail.key', $paths->getLegacyKeyFilePath());
|
|
self::assertSame('/v/log/magesail_tunnel.log', $paths->getLegacyLogFilePath());
|
|
}
|
|
}
|