forked from GerbenJavado/LinkFinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_parser.py
62 lines (52 loc) · 3.17 KB
/
test_parser.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pytest
from linkfinder import regex_str, parser_file
# Imitate cli_output function
def get_parse_cli(str):
endpoints = parser_file(str, regex_str, mode=0)
ret = []
for endpoint in endpoints:
ret.append(endpoint["link"])
return ret
def test_parser_cli():
assert get_parse_cli("\"http://example.com\"") == ["http://example.com"]
assert get_parse_cli("\"smb://example.com\"") == ["smb://example.com"]
assert get_parse_cli("\"https://www.example.co.us\"") == ["https://www.example.co.us"]
assert get_parse_cli("\"/path/to/file\"") == ["/path/to/file"]
assert get_parse_cli("\"../path/to/file\"") == ["../path/to/file"]
assert get_parse_cli("\"./path/to/file\"") == ["./path/to/file"]
assert get_parse_cli("\"/user/create.action?user=Test\"") == ["/user/create.action?user=Test"]
assert get_parse_cli("\"/api/create.php?user=test&pass=test#home\"") == ["/api/create.php?user=test&pass=test#home"]
assert get_parse_cli("\"/wrong/file/test<>b\"") == []
assert get_parse_cli("\"api/create.php\"") == ["api/create.php"]
assert get_parse_cli("\"api/create.php?user=test\"") == ["api/create.php?user=test"]
assert get_parse_cli("\"api/create.php?user=test&pass=test\"") == ["api/create.php?user=test&pass=test"]
assert get_parse_cli("\"api/create.php?user=test#home\"") == ["api/create.php?user=test#home"]
assert get_parse_cli("\"user/create.action?user=Test\"") == ["user/create.action?user=Test"]
assert get_parse_cli("\"user/create.notaext?user=Test\"") == []
assert get_parse_cli("\"/path/to/file\"") == ["/path/to/file"]
assert get_parse_cli("\"../path/to/file\"") == ["../path/to/file"]
assert get_parse_cli("\"./path/to/file\"") == ["./path/to/file"]
assert get_parse_cli("\"/wrong/file/test<>b\"") == []
# REST API (no extension)
assert get_parse_cli("\"api/user\"") == ["api/user"]
assert get_parse_cli("\"v1/create\"") == ["v1/create"]
assert get_parse_cli("\"api/v1/user/2\"") == ["api/v1/user/2"]
assert get_parse_cli("\"api/v1/search?text=Test Hello\"") == ["api/v1/search?text=Test Hello"]
assert get_parse_cli("\"test_1.json\"") == ["test_1.json"]
assert get_parse_cli("\"test2.aspx?arg1=tmp1+tmp2&arg2=tmp3\"") == ["test2.aspx?arg1=tmp1+tmp2&arg2=tmp3"]
assert get_parse_cli("\"addUser.action\"") == ["addUser.action"]
assert get_parse_cli("\"main.js\"") == ["main.js"]
assert get_parse_cli("\"index.html\"") == ["index.html"]
assert get_parse_cli("\"robots.txt\"") == ["robots.txt"]
assert get_parse_cli("\"users.xml\"") == ["users.xml"]
assert get_parse_cli("\"UserModel.name\"") == []
def test_parser_cli_multi():
assert set(get_parse_cli("href=\"http://example.com\";href=\"/api/create.php\"")) == set(["http://example.com", "/api/create.php"])
def test_parser_unique():
'''
Should return only unique link
'''
assert get_parse_cli("href=\"http://example.com\";document.window.location=\"http://example.com\"") == ["http://example.com"]
assert set(get_parse_cli("href=\"http://example.com\";<img src=\"http://example.com\">;href=\"/api/create.php\"")) == set(["http://example.com", "/api/create.php"])