update tests/unit/test_patterns.py
Browse files- tests/unit/test_patterns.py +71 -0
tests/unit/test_patterns.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
from app.grabber.patterns import ProxyPatterns
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class TestHTTPPatterns:
|
| 6 |
+
def test_http_ip_port_pattern(self):
|
| 7 |
+
text = "192.168.1.1:8080\n10.0.0.1:3128"
|
| 8 |
+
matches = ProxyPatterns.extract_http_proxies(text)
|
| 9 |
+
|
| 10 |
+
assert len(matches) == 2
|
| 11 |
+
assert matches[0] == ("192.168.1.1", "8080")
|
| 12 |
+
assert matches[1] == ("10.0.0.1", "3128")
|
| 13 |
+
|
| 14 |
+
def test_http_url_pattern(self):
|
| 15 |
+
text = "192.168.1.1:8080\n10.0.0.1:3128"
|
| 16 |
+
matches = ProxyPatterns.extract_http_proxies(text)
|
| 17 |
+
|
| 18 |
+
assert len(matches) >= 1
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class TestVMessPatterns:
|
| 22 |
+
def test_vmess_url_detection(self):
|
| 23 |
+
url = "vmess://eyJhZGQiOiIxMjcuMC4wLjEiLCJwb3J0Ijo0NDMsImlkIjoidXVpZCJ9"
|
| 24 |
+
assert ProxyPatterns.is_vmess(url) is True
|
| 25 |
+
|
| 26 |
+
def test_vmess_extraction(self):
|
| 27 |
+
text = """
|
| 28 |
+
Some text
|
| 29 |
+
vmess://eyJhZGQiOiIxMjcuMC4wLjEiLCJwb3J0Ijo0NDN9
|
| 30 |
+
More text
|
| 31 |
+
"""
|
| 32 |
+
matches = ProxyPatterns.extract_vmess_urls(text)
|
| 33 |
+
|
| 34 |
+
assert len(matches) == 1
|
| 35 |
+
assert matches[0].startswith("vmess://")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class TestVLESSPatterns:
|
| 39 |
+
def test_vless_url_detection(self):
|
| 40 |
+
url = "vless://uuid@server:443?type=tcp"
|
| 41 |
+
assert ProxyPatterns.is_vless(url) is True
|
| 42 |
+
|
| 43 |
+
def test_vless_extraction(self):
|
| 44 |
+
text = "vless://some-uuid@192.168.1.1:443?encryption=none&type=tcp"
|
| 45 |
+
matches = ProxyPatterns.extract_vless_urls(text)
|
| 46 |
+
|
| 47 |
+
assert len(matches) == 1
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class TestTrojanPatterns:
|
| 51 |
+
def test_trojan_url_detection(self):
|
| 52 |
+
url = "trojan://password@server:443"
|
| 53 |
+
assert ProxyPatterns.is_trojan(url) is True
|
| 54 |
+
|
| 55 |
+
def test_trojan_extraction(self):
|
| 56 |
+
text = "trojan://pass123@example.com:443?sni=example.com"
|
| 57 |
+
matches = ProxyPatterns.extract_trojan_urls(text)
|
| 58 |
+
|
| 59 |
+
assert len(matches) == 1
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class TestShadowsocksPatterns:
|
| 63 |
+
def test_ss_url_detection(self):
|
| 64 |
+
url = "ss://base64encoded@server:8388"
|
| 65 |
+
assert ProxyPatterns.is_shadowsocks(url) is True
|
| 66 |
+
|
| 67 |
+
def test_ss_extraction(self):
|
| 68 |
+
text = "ss://YWVzLTI1Ni1nY206cGFzc3dvcmQ@192.168.1.1:8388"
|
| 69 |
+
matches = ProxyPatterns.extract_ss_urls(text)
|
| 70 |
+
|
| 71 |
+
assert len(matches) == 1
|