| 1 | <?php |
||
| 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 |