paijo77 commited on
Commit
803e6de
·
verified ·
1 Parent(s): cbd8d01

update tests/unit/test_edge_cases.py

Browse files
Files changed (1) hide show
  1. tests/unit/test_edge_cases.py +87 -0
tests/unit/test_edge_cases.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pytest
2
+ from app.grabber.github_grabber import GitHubGrabber
3
+ from app.grabber.patterns import ProxyPatterns
4
+ from app.models.source import SourceType
5
+
6
+
7
+ class TestEdgeCases:
8
+ @pytest.mark.asyncio
9
+ async def test_empty_content(self):
10
+ grabber = GitHubGrabber()
11
+ proxies = await grabber.parse_content("", SourceType.GENERIC_TEXT)
12
+
13
+ assert proxies == []
14
+
15
+ @pytest.mark.asyncio
16
+ async def test_whitespace_only(self):
17
+ grabber = GitHubGrabber()
18
+ content = " \n\n\t\t\n "
19
+ proxies = await grabber.parse_content(content, SourceType.GENERIC_TEXT)
20
+
21
+ assert proxies == []
22
+
23
+ @pytest.mark.asyncio
24
+ async def test_invalid_ip_format(self):
25
+ grabber = GitHubGrabber()
26
+ content = "999.999.999.999:8080\n256.1.1.1:3128"
27
+ proxies = await grabber.parse_content(content, SourceType.GENERIC_TEXT)
28
+
29
+ assert len(proxies) == 0
30
+
31
+ @pytest.mark.asyncio
32
+ async def test_valid_port_range(self):
33
+ grabber = GitHubGrabber()
34
+ content = "192.168.1.1:80\n192.168.1.2:443\n192.168.1.3:65535"
35
+ proxies = await grabber.parse_content(content, SourceType.GENERIC_TEXT)
36
+
37
+ assert all(1 <= p.port <= 65535 for p in proxies)
38
+
39
+ @pytest.mark.asyncio
40
+ async def test_duplicate_proxies(self):
41
+ grabber = GitHubGrabber()
42
+ content = """
43
+ 192.168.1.1:8080
44
+ 192.168.1.1:8080
45
+ 192.168.1.1:8080
46
+ """
47
+ proxies = await grabber.parse_content(content, SourceType.GENERIC_TEXT)
48
+
49
+ assert len(proxies) >= 1
50
+
51
+ @pytest.mark.asyncio
52
+ async def test_mixed_line_endings(self):
53
+ grabber = GitHubGrabber()
54
+ content = "192.168.1.1:8080\r\n10.0.0.1:3128\n172.16.0.1:9999\r"
55
+ proxies = await grabber.parse_content(content, SourceType.GENERIC_TEXT)
56
+
57
+ assert len(proxies) >= 2
58
+
59
+ @pytest.mark.asyncio
60
+ async def test_comments_and_noise(self):
61
+ grabber = GitHubGrabber()
62
+ content = """
63
+ # This is a comment
64
+ 192.168.1.1:8080
65
+ // Another comment
66
+ 10.0.0.1:3128
67
+ """
68
+ proxies = await grabber.parse_content(content, SourceType.GENERIC_TEXT)
69
+
70
+ assert len(proxies) == 2
71
+
72
+ def test_ip_validation(self):
73
+ assert ProxyPatterns.is_valid_ip("192.168.1.1") is True
74
+ assert ProxyPatterns.is_valid_ip("255.255.255.255") is True
75
+ assert ProxyPatterns.is_valid_ip("0.0.0.0") is True
76
+ assert ProxyPatterns.is_valid_ip("256.1.1.1") is False
77
+ assert ProxyPatterns.is_valid_ip("192.168.1") is False
78
+ assert ProxyPatterns.is_valid_ip("not.an.ip.address") is False
79
+
80
+ def test_port_validation(self):
81
+ assert ProxyPatterns.is_valid_port(1) is True
82
+ assert ProxyPatterns.is_valid_port(80) is True
83
+ assert ProxyPatterns.is_valid_port(443) is True
84
+ assert ProxyPatterns.is_valid_port(65535) is True
85
+ assert ProxyPatterns.is_valid_port(0) is False
86
+ assert ProxyPatterns.is_valid_port(65536) is False
87
+ assert ProxyPatterns.is_valid_port(-1) is False