-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathtest_auth_interactive.py
More file actions
executable file
·87 lines (66 loc) · 1.84 KB
/
test_auth_interactive.py
File metadata and controls
executable file
·87 lines (66 loc) · 1.84 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
83
84
85
86
87
#!/usr/bin/env python3
"""Interactive test script for authentication.
Start the bearer server first:
python tests/test_server_bearer.py
Then run this script:
python test_auth_interactive.py
"""
from mcp2py import load
print("=" * 70)
print("Testing mcp2py Authentication")
print("=" * 70)
print()
print("1. Testing Bearer Token Authentication")
print("-" * 70)
try:
# Test with correct token
print("Connecting with correct token...")
server = load(
"http://localhost:8000/sse",
headers={"Authorization": "Bearer test-token-12345"}
)
print("✓ Connection successful!")
# Test echo
result = server.echo(message="Hello from mcp2py!")
print(f"✓ Echo: {result}")
# Test add
result = server.add(a=10, b=32)
print(f"✓ Add: {result}")
# Test user info
result = server.get_user_info()
print(f"✓ User info: {result}")
server.close()
print("✓ Server closed")
except Exception as e:
print(f"✗ Error: {e}")
print()
print("-" * 70)
# Test with wrong token
print("2. Testing Invalid Token (should fail)")
print("-" * 70)
try:
print("Connecting with invalid token...")
server = load(
"http://localhost:8000/sse",
headers={"Authorization": "Bearer wrong-token"}
)
print("✗ Connection should have failed!")
server.close()
except RuntimeError as e:
print(f"✓ Correctly rejected: {type(e).__name__}")
print()
print("-" * 70)
# Test with no token
print("3. Testing No Token (should fail)")
print("-" * 70)
try:
print("Connecting without token...")
server = load("http://localhost:8000/sse")
print("✗ Connection should have failed!")
server.close()
except RuntimeError as e:
print(f"✓ Correctly rejected: {type(e).__name__}")
print()
print("=" * 70)
print("✅ All authentication tests completed!")
print("=" * 70)