GuildLogoSafeNameTest.php

main 51 lines · 1.3 KB Raw
Alex Alex Commit Initial commit 01/10/2026 09:20
1<?php
2
3declare(strict_types=1);
4
5namespace ZnoteX\Tests\Security;
6
7use PHPUnit\Framework\TestCase;
8
9final class GuildLogoSafeNameTest extends TestCase
10{
11 public function testAcceptsAnOrdinaryGuildName(): void
12 {
13 $this->assertSame('Knights of ZnoteX', \guild_logo_safe_name('Knights of ZnoteX'));
14 }
15
16 public function testTrimsWhitespace(): void
17 {
18 $this->assertSame('Guardians', \guild_logo_safe_name(' Guardians '));
19 }
20
21 public function testRejectsEmptyName(): void
22 {
23 $this->assertNull(\guild_logo_safe_name(''));
24 $this->assertNull(\guild_logo_safe_name(' '));
25 }
26
27 public function testRejectsNameLongerThanSixtyCharacters(): void
28 {
29 $this->assertNull(\guild_logo_safe_name(str_repeat('a', 61)));
30 $this->assertNotNull(\guild_logo_safe_name(str_repeat('a', 60)));
31 }
32
33 /** @dataProvider pathTraversalProvider */
34 public function testRejectsPathTraversalAttempts(string $malicious): void
35 {
36 $this->assertNull(\guild_logo_safe_name($malicious));
37 }
38
39 public static function pathTraversalProvider(): array
40 {
41 return [
42 'parent directory' => ['../../../etc/passwd'],
43 'dot dot in the middle' => ['guild..name'],
44 'forward slash' => ['guild/name'],
45 'backslash' => ['guild\\name'],
46 'null byte' => ["guild\0name"],
47 'windows traversal' => ['..\\..\\config.local.php'],
48 ];
49 }
50}
51
Top