/
StringTest.php
108 lines (97 loc) · 3.91 KB
/
StringTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
# MantisBT - A PHP based bugtracking system
# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
/**
* Test cases for string handling within mantis
*
* @package Tests
* @subpackage String
* @copyright Copyright 2002 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
*/
# Includes
require_once dirname( dirname( __FILE__ ) ) . '/TestConfig.php';
# MantisBT Core API
require_mantis_core();
/**
* Mantis string handling test cases
* @package Tests
* @subpackage String
* @copyright Copyright 2002 MantisBT Team - mantisbt-dev@lists.sourceforge.net
* @link http://www.mantisbt.org
*/
class MantisStringTest extends PHPUnit_Framework_TestCase {
/**
* Tests string_sanitize_url()
*
* @dataProvider provider
* @param string $p_in Input.
* @param string $p_out Expected output.
* @return void
*/
public function testStringSanitize( $p_in, $p_out ) {
$t_a = string_sanitize_url( $p_in, false );
$this->assertEquals( $p_out, $t_a );
# Since unit tests are run from command-line, with a default MantisBT
# config $g_short_path will be that of the phpunit binary. We also
# need to cover the case of Mantis being installed at the server's
# root (i.e. $g_short_path = '/')
config_set_global('short_path', '/');
$t_a = string_sanitize_url($p_in, false);
$this->assertEquals( $p_out, $t_a );
}
/**
* Data provider for string sanitize test
* @return array
*/
public function provider() {
$t_test_strings = array(
array( '', 'index.php' ),
array( 'abc.php', 'abc.php' ),
array( 'abc.php?', 'abc.php'),
array( 'abc.php#a', 'abc.php#a'),
array( 'abc.php?abc=def', 'abc.php?abc=def'),
array( 'abc.php?abc=def#a', 'abc.php?abc=def#a'),
array( 'abc.php?abc=def&z=xyz', 'abc.php?abc=def&z=xyz'),
array( 'abc.php?abc=def&z=xyz', 'abc.php?abc=def&z=xyz'),
array( 'abc.php?abc=def&z=xyz#a', 'abc.php?abc=def&z=xyz#a'),
array( 'abc.php?abc=def&z=xyz#a', 'abc.php?abc=def&z=xyz#a'),
# @FIXME array( 'abc.php?abc=def&z=<script>alert("foo")</script>z#a', 'abc.php?abc=def&z=alert%28%22foo%29%22%3cz#a'),
# @FIXME array( 'abc.php?abc=def&z=z#<script>alert("foo")</script>a', 'abc.php?abc=def&z=z#alert%28%22foo%22%3ca'),
array( 'plugin.php?page=Source/index', 'plugin.php?page=Source%2Findex'),
array( 'plugin.php?page=Source/list&id=1', 'plugin.php?page=Source%2Flist&id=1'),
array( 'plugin.php?page=Source/list&id=1#abc', 'plugin.php?page=Source%2Flist&id=1#abc'),
array( 'login_page.php?return=http://google.com/', 'index.php'),
array( 'javascript:alert(1);', 'index.php'),
array( '\/csrf-22702', '%5C/csrf-22702' ),
);
# @FIXME
# array( $my_path.'abc.php',
# array( $my_path.'abc.php?',
# array( $my_path.'abc.php#a',
# array( $my_path.'abc.php?abc=def',
# array( $my_path.'abc.php?abc=def#a',
# array( $my_path.'abc.php?abc=def&z=xyz',
# array( $my_path.'abc.php?abc=def&z=xyz',
# array( $my_path.'abc.php?abc=def&z=xyz#a',
# array( $my_path.'abc.php?abc=def&z=xyz#a',
# array( $my_path.'abc.php?abc=def&z=<script>alert("foo")</script>z#a',
# array( $my_path.'abc.php?abc=def&z=z#<script>alert("foo")</script>a',
# array( $my_path.'plugin.php?page=Source/index',
# array( $my_path.'plugin.php?page=Source/list&id=1',
# array( $my_path.'plugin.php?page=Source/list&id=1#abc',
# array( 'http://www.test.my.url/'),
return $t_test_strings;
}
}