Completed
Push — master ( d90020...eca10a )
by Rob
04:28
created

XssTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 52
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace devtoolboxuk\cerberus;
4
5
use devtoolboxuk\cerberus\Handlers\XssHandler;
6
use PHPUnit\Framework\TestCase;
7
8
class XssTest extends TestCase
9
{
10
11
    private $options = [];
12
13
    function __construct($name = null, array $data = [], $dataName = '')
14
    {
15
        parent::__construct($name, $data, $dataName);
16
        $this->options = $this->getTestData();
17
    }
18
19
    private function getTestData()
20
    {
21
        /** @noinspection PhpIncludeInspection */
22
        return include __DIR__ . '/options.php';
23
    }
24
25
    function testNoXss()
26
    {
27
28
        $cerberus = new CerberusService();
29
        $cerberus->setOptions($this->getOptions());
30
31
        $data = '<span>http://dev-toolbox.co.uk';
32
        $detection = $cerberus
33
            ->pushHandler(new XssHandler($data));
34
35
        $this->assertEquals(0, $detection->getScore());
36
        $this->assertEquals('[]', $detection->getResult());
37
38
    }
39
40
    private function getOptions()
41
    {
42
        return $this->options;
43
    }
44
45
    function testXss()
46
    {
47
48
        $cerberus = new CerberusService();
49
        $cerberus->setOptions($this->getOptions());
50
51
        $data = 'http://localhost/text.php/"><script>alert(“Gehackt!”);</script></form><form action="/...';
52
        $detection = $cerberus
53
            ->pushHandler(new XssHandler($data));
54
55
        $this->assertEquals(10, $detection->getScore());
56
        $this->assertEquals('{"Xss":10}', $detection->getResult());
57
    }
58
59
}
60