File size: 2,077 Bytes
81e3673
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import sys

# Test via the Frontend Proxy (Next.js)
BASE_URL = "http://localhost:3000" 

def test_proxy_access():
    print(f"Testing Proxy Access at {BASE_URL}...")
    
    # 1. Login via Proxy
    login_url = f"{BASE_URL}/api/auth/login"
    payload = {"username": "admin@example.com", "password": "securePass123"}
    print(f"1. Logging in via {login_url}...")
    
    try:
        res = requests.post(login_url, json=payload)
        if res.status_code != 200:
            print(f"❌ Login Failed at Proxy: {res.status_code} {res.text}")
            return
        
        data = res.json()
        token = data.get("access_token")
        if not token:
             print("❌ Login succeeded but no token returned!")
             print(f"Response keys: {data.keys()}")
             return
             
        print("✓ Login successful via Proxy. Token received.")
        
    except Exception as e:
         print(f"❌ Login Request Error: {e}")
         print("Is the Next.js server (npm run dev) running on port 3000?")
         return

    # 2. Access /api/agents/ via Proxy
    agents_url = f"{BASE_URL}/api/agents/"
    headers = {
        "Authorization": f"Bearer {token}",
        "Content-Type": "application/json"
    }
    print(f"2. Requesting {agents_url} via Proxy...")
    
    try:
        res = requests.get(agents_url, headers=headers)
        print(f"Status: {res.status_code}")
        
        if res.status_code == 200:
            print("✅ Proxy Access GRANTED.")
        elif res.status_code == 401:
            print("❌ Proxy Access DENIED (401 Unauthorized). Header likely stripped or token rejected.")
            print(f"Response: {res.text[:200]}")
        elif res.status_code == 403:
            print("❌ Proxy Access FORBIDDEN (403 Permission Denied).")
        else:
            print(f"❌ Unexpected Status: {res.status_code}")
            print(f"Response: {res.text[:200]}")

    except Exception as e:
        print(f"❌ Agent Request Error: {e}")

if __name__ == "__main__":
    test_proxy_access()