File size: 2,224 Bytes
76bade6 | 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 | import pytest
from app.grabber.patterns import ProxyPatterns
class TestHTTPPatterns:
def test_http_ip_port_pattern(self):
text = "192.168.1.1:8080\n10.0.0.1:3128"
matches = ProxyPatterns.extract_http_proxies(text)
assert len(matches) == 2
assert matches[0] == ("192.168.1.1", "8080")
assert matches[1] == ("10.0.0.1", "3128")
def test_http_url_pattern(self):
text = "192.168.1.1:8080\n10.0.0.1:3128"
matches = ProxyPatterns.extract_http_proxies(text)
assert len(matches) >= 1
class TestVMessPatterns:
def test_vmess_url_detection(self):
url = "vmess://eyJhZGQiOiIxMjcuMC4wLjEiLCJwb3J0Ijo0NDMsImlkIjoidXVpZCJ9"
assert ProxyPatterns.is_vmess(url) is True
def test_vmess_extraction(self):
text = """
Some text
vmess://eyJhZGQiOiIxMjcuMC4wLjEiLCJwb3J0Ijo0NDN9
More text
"""
matches = ProxyPatterns.extract_vmess_urls(text)
assert len(matches) == 1
assert matches[0].startswith("vmess://")
class TestVLESSPatterns:
def test_vless_url_detection(self):
url = "vless://uuid@server:443?type=tcp"
assert ProxyPatterns.is_vless(url) is True
def test_vless_extraction(self):
text = "vless://some-uuid@192.168.1.1:443?encryption=none&type=tcp"
matches = ProxyPatterns.extract_vless_urls(text)
assert len(matches) == 1
class TestTrojanPatterns:
def test_trojan_url_detection(self):
url = "trojan://password@server:443"
assert ProxyPatterns.is_trojan(url) is True
def test_trojan_extraction(self):
text = "trojan://pass123@example.com:443?sni=example.com"
matches = ProxyPatterns.extract_trojan_urls(text)
assert len(matches) == 1
class TestShadowsocksPatterns:
def test_ss_url_detection(self):
url = "ss://base64encoded@server:8388"
assert ProxyPatterns.is_shadowsocks(url) is True
def test_ss_extraction(self):
text = "ss://YWVzLTI1Ni1nY206cGFzc3dvcmQ@192.168.1.1:8388"
matches = ProxyPatterns.extract_ss_urls(text)
assert len(matches) == 1
|