1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @filesource HTML5ModuleTestCritical.php |
5
|
|
|
* @created 10.02.2016 |
6
|
|
|
* @package chillerlan\BBCodeTest |
7
|
|
|
* @author Smiley <[email protected]> |
8
|
|
|
* @copyright 2015 Smiley |
9
|
|
|
* @license MIT |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace chillerlan\BBCodeTest\critical\Modules; |
13
|
|
|
|
14
|
|
|
use chillerlan\bbcode\Modules\Html5\Code; |
15
|
|
|
use chillerlan\bbcode\Modules\Html5\Containers; |
16
|
|
|
use chillerlan\bbcode\Modules\Html5\Html5BaseModule; |
17
|
|
|
use chillerlan\bbcode\Modules\Html5\Singletags; |
18
|
|
|
use chillerlan\bbcode\Parser; |
19
|
|
|
use chillerlan\bbcode\ParserOptions; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class HTML5ModuleTestCritical |
23
|
|
|
* |
24
|
|
|
* may cause the one or other PREG_ERROR or run into a php bug depending on OS and PHP version... |
25
|
|
|
* |
26
|
|
|
* @link https://github.com/travis-ci/travis-ci/issues/4593 |
27
|
|
|
* @link https://github.com/travis-ci/travis-ci/issues/5039 |
28
|
|
|
* @link https://github.com/travis-ci/travis-ci/issues/5323 |
29
|
|
|
* @link https://github.com/travis-ci/travis-ci/issues/5332 |
30
|
|
|
*/ |
31
|
|
|
class HTML5ModuleTestCritical extends \PHPUnit_Framework_TestCase{ |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var \chillerlan\bbcode\Parser |
35
|
|
|
*/ |
36
|
|
|
protected $parser; |
37
|
|
|
|
38
|
|
|
protected function setUp(){ |
39
|
|
|
$options = new ParserOptions; |
40
|
|
|
$options->allow_all = true; |
41
|
|
|
$this->parser = new Parser($options); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function bbcodeDataProvider(){ |
45
|
|
|
return [ |
46
|
|
|
// basics |
47
|
|
|
['', ''], // empty string test (coverage) |
48
|
|
|
['no bbcode at all', 'no bbcode at all'], |
49
|
|
|
['[somebbcode]invalid bbcodes will be eaten :P[/somebbcode]', 'invalid bbcodes will be eaten :P'], |
50
|
|
|
// XSS |
51
|
|
|
['<script>alert(\'Hello, i am an XSS attempt!\')</script>', '<script>alert(\'Hello, i am an XSS attempt!\')</script>'], |
52
|
|
|
['<img src="javascript:alert(\'XSS\');" />', '<img src="javascript:alert(\'XSS\');" />'], |
53
|
|
|
['[img]JaVaScRiPt:alert(\'XSS\');[/img]', ''], |
54
|
|
|
['[img]""><SCRIPT>alert("XSS")</SCRIPT>"[/img]', ''], |
55
|
|
|
['[img]javascript:alert('XSS')[/img]', ''], |
56
|
|
|
['[img]¼script¾alert(¢XSS¢)¼/script¾[/img]', ''], |
57
|
|
|
['[img]vbscript:msgbox("XSS")[/img]', ''], |
58
|
|
|
['[img]javascript:alert('XSS')[/img]', ''], |
59
|
|
|
['[img alt=Privateinvestocat]https://octodex.github.com/images/privateinvestocat.jpg[/img]', '<img src="https://octodex.github.com/images/privateinvestocat.jpg" alt="Privateinvestocat" class="bb-image" />'], |
60
|
|
|
// noparse |
61
|
|
|
['[noparse][u][b]some unparsed bbcode[/b][/u][/noparse]', '<pre class="bbcode noparse">[u][b]some unparsed bbcode[/b][/u]</pre>'], |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @dataProvider bbcodeDataProvider |
67
|
|
|
*/ |
68
|
|
|
public function testParser($bbcode, $expected){ |
69
|
|
|
$this->assertEquals($expected, $this->parser->parse($bbcode)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function nestingDataProvider(){ |
73
|
|
|
return [ |
74
|
|
|
[0, 'bbcode_nesting.txt'], |
75
|
|
|
[1, 'results/html5_nesting_1.txt'], |
76
|
|
|
[10, 'results/html5_nesting_10.txt'], |
77
|
|
|
[100, 'results/html5_nesting_100.txt'], |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @dataProvider nestingDataProvider |
83
|
|
|
*/ |
84
|
|
|
public function testNesting($limit, $resultfile){ |
85
|
|
|
$options = new ParserOptions; |
86
|
|
|
$options->allow_all = true; |
87
|
|
|
$options->nesting_limit = $limit; |
88
|
|
|
$this->parser->setOptions($options); |
89
|
|
|
|
90
|
|
|
$bbcode = file_get_contents(dirname(__FILE__).'/../../bbcode_samples/bbcode_nesting.txt'); |
91
|
|
|
$expected = file_get_contents(dirname(__FILE__).'/../../bbcode_samples/'.$resultfile); |
92
|
|
|
|
93
|
|
|
$parsed = $this->parser->parse($bbcode); |
94
|
|
|
// replace the random IDs with something more testable |
95
|
|
|
$parsed = preg_replace('/\"([a-f\d]{8})\"/i', '"abcdef12"', $parsed); |
96
|
|
|
|
97
|
|
|
$this->assertEquals($expected, $parsed); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testCodeModule(){ |
101
|
|
|
foreach(array_keys($this->parser->getTagmap(), Code::class) as $lang){ |
102
|
|
|
$bbcode = file_get_contents(dirname(__FILE__).'/../../bbcode_samples/bbcode_code_'.$lang.'.txt'); |
103
|
|
|
$expected = file_get_contents(dirname(__FILE__).'/../../bbcode_samples/results/html5_code_'.$lang.'.txt'); |
104
|
|
|
$parsed = $this->parser->parse($bbcode); |
105
|
|
|
$parsed = preg_replace('/\"([a-f\d]{8})\"/i', '"abcdef12"', $parsed); |
106
|
|
|
|
107
|
|
|
$this->assertEquals($expected, $parsed); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
} |
112
|
|
|
|