Revision 5c583de8
Added by koszko almost 2 years ago
test/unit/test_patterns.py | ||
---|---|---|
89 | 89 |
match = execute_in_page('returnval(ftp_regex.exec(arguments[0]));', |
90 | 90 |
'@bad.url/') |
91 | 91 |
assert match is None |
92 |
|
|
93 |
def test_deconstruct_url(execute_in_page, patterns_code): |
|
94 |
""" |
|
95 |
patterns.js contains deconstruct_url() function that handles URL parsing. |
|
96 |
Verify it works properly. |
|
97 |
""" |
|
98 |
execute_in_page(patterns_code, page='https://gotmyowndoma.in') |
|
99 |
|
|
100 |
deco = execute_in_page('returnval(deconstruct_url(arguments[0]));', |
|
101 |
'https://eXaMpLe.com/a/b?ver=1.2.3#heading2') |
|
102 |
assert deco |
|
103 |
assert deco['trailing_dash'] == False |
|
104 |
assert deco['proto'] == 'https' |
|
105 |
assert deco['domain'] == ['example', 'com'] |
|
106 |
assert deco['path'] == ['a', 'b'] |
|
107 |
|
|
108 |
deco = execute_in_page('returnval(deconstruct_url(arguments[0]));', |
|
109 |
'http://**.example.com/') |
|
110 |
assert deco |
|
111 |
assert deco['trailing_dash'] == True |
|
112 |
assert deco['proto'] == 'http' |
|
113 |
assert deco['domain'] == ['**', 'example', 'com'] |
|
114 |
assert deco['path'] == [] |
|
115 |
|
|
116 |
deco = execute_in_page('returnval(deconstruct_url(arguments[0]));', |
|
117 |
'ftp://user@ftp.example.com/all///passwords.txt/') |
|
118 |
assert deco |
|
119 |
assert deco['trailing_dash'] == True |
|
120 |
assert deco['proto'] == 'ftp' |
|
121 |
assert deco['domain'] == ['ftp', 'example', 'com'] |
|
122 |
assert deco['path'] == ['all', 'passwords.txt'] |
|
123 |
|
|
124 |
deco = execute_in_page('returnval(deconstruct_url(arguments[0]));', |
|
125 |
'ftp://mirror.edu.pl.eu.org') |
|
126 |
assert deco |
|
127 |
assert deco['trailing_dash'] == False |
|
128 |
assert deco['proto'] == 'ftp' |
|
129 |
assert deco['domain'] == ['mirror', 'edu', 'pl', 'eu', 'org'] |
|
130 |
assert deco['path'] == [] |
|
131 |
|
|
132 |
deco = execute_in_page('returnval(deconstruct_url(arguments[0]));', |
|
133 |
'file:///mnt/parabola_chroot///etc/passwd') |
|
134 |
assert deco |
|
135 |
assert deco['trailing_dash'] == False |
|
136 |
assert deco['proto'] == 'file' |
|
137 |
assert deco['path'] == ['mnt', 'parabola_chroot', 'etc', 'passwd'] |
|
138 |
|
|
139 |
for bad_url in [ |
|
140 |
'://bad-url.missing/protocol', |
|
141 |
'http:/example.com/a/b', |
|
142 |
'unknown://example.com/a/b', |
|
143 |
'idontfancypineapple', |
|
144 |
'ftp://@example.org/', |
|
145 |
'https:///some/path/', |
|
146 |
'file://non-absolute/path' |
|
147 |
]: |
|
148 |
with pytest.raises(Exception, match=r'Error in injected script'): |
|
149 |
deco = execute_in_page('returnval(deconstruct_url(arguments[0]));', |
|
150 |
bad_url) |
|
151 |
|
|
152 |
# at some point we might also consider testing url deconstruction with |
|
153 |
# length limits... |
Also available in: Unified diff
start implementing more efficient querying of URL patterns