-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
82 lines (73 loc) · 2.55 KB
/
test_api.py
File metadata and controls
82 lines (73 loc) · 2.55 KB
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
73
74
75
76
77
78
79
80
81
82
"""Quick API test for the enhanced phishing detection backend"""
import requests
import json
BASE_URL = "http://localhost:8002"
def test_api():
print("🧪 Testing Enhanced Phishing Detection API")
print("="*60)
# Test 1: Health Check
print("\n1. Health Check")
response = requests.get(f"{BASE_URL}/health")
print(f"Status: {response.status_code}")
print(f"Response: {response.json()}")
# Test 2: Phishing URL
print("\n2. Testing Phishing URL")
phishing_url = "http://paypal-secure-login-verify.com/signin/?session=12345"
response = requests.post(
f"{BASE_URL}/predict",
json={"url": phishing_url}
)
print(f"URL: {phishing_url}")
print(f"Status: {response.status_code}")
result = response.json()
print(f"Label: {result['label']}")
print(f"Score: {result['score']:.2%}")
print(f"Reasons: {result['reasons'][:3]}")
# Test 3: Legitimate URL
print("\n3. Testing Legitimate URL")
legit_url = "https://github.com/python/cpython"
response = requests.post(
f"{BASE_URL}/predict",
json={"url": legit_url}
)
print(f"URL: {legit_url}")
print(f"Status: {response.status_code}")
result = response.json()
print(f"Label: {result['label']}")
print(f"Score: {result['score']:.2%}")
print(f"Reasons: {result['reasons'][:3]}")
# Test 4: Typosquatting Attack
print("\n4. Testing Typosquatting Attack")
typo_url = "https://gooogle.com/login/"
response = requests.post(
f"{BASE_URL}/predict",
json={"url": typo_url}
)
print(f"URL: {typo_url}")
print(f"Status: {response.status_code}")
result = response.json()
print(f"Label: {result['label']}")
print(f"Score: {result['score']:.2%}")
print(f"Reasons: {result['reasons'][:3]}")
# Test 5: IP-based Attack
print("\n5. Testing IP-based Attack")
ip_url = "http://192.168.1.100/banking/login.php"
response = requests.post(
f"{BASE_URL}/predict",
json={"url": ip_url}
)
print(f"URL: {ip_url}")
print(f"Status: {response.status_code}")
result = response.json()
print(f"Label: {result['label']}")
print(f"Score: {result['score']:.2%}")
print(f"Reasons: {result['reasons'][:3]}")
print("\n" + "="*60)
print("✅ API Test Complete!")
if __name__ == "__main__":
try:
test_api()
except requests.exceptions.ConnectionError:
print("❌ Could not connect to API. Make sure backend is running on port 8001")
except Exception as e:
print(f"❌ Error: {e}")