|
3 | 3 | namespace Loki\Components\Test\Unit\Filter; |
4 | 4 |
|
5 | 5 | use Loki\Components\Filter\FilterScope; |
| 6 | +use PHPUnit\Framework\Attributes\DataProvider; |
6 | 7 | use PHPUnit\Framework\TestCase; |
7 | 8 | use Loki\Components\Filter\Security; |
8 | 9 |
|
9 | 10 | class SecurityTest extends TestCase |
10 | 11 | { |
11 | | - public function testFilter() |
| 12 | + #[DataProvider('filterDataProvider')] |
| 13 | + public function testFilter(string $input, string $expected): void |
12 | 14 | { |
13 | 15 | $filterScope = new FilterScope(); |
14 | 16 | $filter = new Security(); |
15 | | - $this->assertEquals('foobar', $filter->filter('<script>foobar</script>', $filterScope)); |
| 17 | + $this->assertSame($expected, $filter->filter($input, $filterScope)); |
| 18 | + } |
| 19 | + |
| 20 | + public static function filterDataProvider(): array |
| 21 | + { |
| 22 | + return [ |
| 23 | + 'script tag with content' => ['<script>foobar</script>', 'foobar'], |
| 24 | + 'bare script tag' => ['<script>', ''], |
| 25 | + 'encoded script tag' => ['<script>', ''], |
| 26 | + 'double encoded script tag' => ['&lt;script&gt;', ''], |
| 27 | + 'broken out img onerror' => ['"><img src=x onerror=1>', '">'], |
| 28 | + 'javascript scheme' => ['javascript:alert(1)', 'alert(1)'], |
| 29 | + 'vbscript scheme' => ['vbscript:msgbox(1)', 'msgbox(1)'], |
| 30 | + 'img onerror' => ['<img src=x onerror=alert(1)>', ''], |
| 31 | + 'encoded bold tags' => ['<b>already</b>', 'already'], |
| 32 | + 'anchor with javascript href' => ['<a href="javascript:alert(1)">x</a>', 'x'], |
| 33 | + 'benign markup with entity' => ['<b>bold</b> & text', 'bold & text'], |
| 34 | + 'plain text' => ['plain text', 'plain text'], |
| 35 | + ]; |
16 | 36 | } |
17 | 37 | } |
0 commit comments