feat(share) : résolution de chemin SMB anti path-traversal

This commit is contained in:
Matthieu
2026-06-03 17:02:21 +02:00
parent d0aff0fa51
commit f12ff87b87
3 changed files with 117 additions and 0 deletions
@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
namespace App\Tests\Unit\Service;
use App\Service\Share\Exception\InvalidPathException;
use App\Service\Share\SharePathResolver;
use PHPUnit\Framework\TestCase;
/**
* @internal
*/
final class SharePathResolverTest extends TestCase
{
private SharePathResolver $resolver;
protected function setUp(): void
{
$this->resolver = new SharePathResolver();
}
public function testNormalizeRelativeKeepsSimplePath(): void
{
self::assertSame('a/b', $this->resolver->normalizeRelative('a/b'));
}
public function testNormalizeRelativeStripsDotsAndSlashes(): void
{
self::assertSame('a/b', $this->resolver->normalizeRelative('/a/./b/'));
}
public function testNormalizeRelativeConvertsBackslashes(): void
{
self::assertSame('a/b', $this->resolver->normalizeRelative('a\b'));
}
public function testNormalizeRelativeRejectsParentTraversal(): void
{
$this->expectException(InvalidPathException::class);
$this->resolver->normalizeRelative('a/../b');
}
public function testNormalizeRelativeRejectsLeadingParent(): void
{
$this->expectException(InvalidPathException::class);
$this->resolver->normalizeRelative('../etc/passwd');
}
public function testFullPathJoinsBaseAndRelative(): void
{
self::assertSame('/Projets/a/b', $this->resolver->fullPath('/Projets', 'a/b'));
}
public function testFullPathWithEmptyBaseAndEmptyRelativeIsRoot(): void
{
self::assertSame('/', $this->resolver->fullPath('', ''));
}
public function testFullPathTrimsBaseSlashes(): void
{
self::assertSame('/Projets/a', $this->resolver->fullPath('/Projets/', 'a'));
}
}