114 lines
3.6 KiB
Python
114 lines
3.6 KiB
Python
import requests
|
|
import json
|
|
import base64
|
|
|
|
def test_webui_auth():
|
|
print("=== Testing Web UI Authentication ===")
|
|
|
|
# Test 1: Check if server is running
|
|
try:
|
|
response = requests.get("http://localhost:3015/api/health", timeout=10)
|
|
print(f"✅ Server is running: {response.status_code}")
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
print(f" Auth mode: {data.get('auth_mode', 'Unknown')}")
|
|
print(f" Auth configured: {data.get('auth_configured', 'Unknown')}")
|
|
except Exception as e:
|
|
print(f"❌ Server not accessible: {e}")
|
|
return False
|
|
|
|
# Test 2: Test Web UI login with credentials
|
|
print("\n=== Testing Web UI Login ===")
|
|
credentials = "jleu3482:jleu1212"
|
|
encoded_credentials = base64.b64encode(credentials.encode()).decode()
|
|
|
|
headers = {
|
|
'Authorization': f'Basic {encoded_credentials}',
|
|
'Content-Type': 'application/json'
|
|
}
|
|
|
|
try:
|
|
# Try to access webui with basic auth
|
|
response = requests.get("http://localhost:3015/webui/", headers=headers, timeout=10)
|
|
print(f"Web UI access: {response.status_code}")
|
|
|
|
if response.status_code == 200:
|
|
print("✅ Web UI authentication successful!")
|
|
return True
|
|
else:
|
|
print(f"❌ Web UI authentication failed: {response.status_code}")
|
|
print(f" Response: {response.text[:200]}...")
|
|
except Exception as e:
|
|
print(f"❌ Web UI access error: {e}")
|
|
|
|
# Test 3: Test API with API key
|
|
print("\n=== Testing API Authentication ===")
|
|
api_headers = {
|
|
'Authorization': 'Bearer jleu1212',
|
|
'Content-Type': 'application/json'
|
|
}
|
|
|
|
try:
|
|
response = requests.get("http://localhost:3015/api/documents", headers=api_headers, timeout=10)
|
|
print(f"API documents endpoint: {response.status_code}")
|
|
|
|
if response.status_code == 200:
|
|
print("✅ API authentication successful!")
|
|
return True
|
|
else:
|
|
print(f"❌ API authentication failed: {response.status_code}")
|
|
except Exception as e:
|
|
print(f"❌ API access error: {e}")
|
|
|
|
return False
|
|
|
|
def test_ocr_upload():
|
|
print("\n=== Testing OCR PDF Upload ===")
|
|
|
|
# Upload the OCR PDF
|
|
files = {
|
|
'file': ('ocr.pdf', open('ocr.pdf', 'rb'), 'application/pdf')
|
|
}
|
|
|
|
headers = {
|
|
'Authorization': 'Bearer jleu1212'
|
|
}
|
|
|
|
try:
|
|
response = requests.post(
|
|
"http://localhost:3015/api/upload",
|
|
files=files,
|
|
headers=headers,
|
|
timeout=30
|
|
)
|
|
|
|
print(f"Upload response: {response.status_code}")
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
print(f"✅ Upload successful: {data}")
|
|
return True
|
|
else:
|
|
print(f"❌ Upload failed: {response.text}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ Upload error: {e}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
print("LightRAG Web UI Authentication Test")
|
|
print("=" * 50)
|
|
|
|
# Test authentication
|
|
auth_success = test_webui_auth()
|
|
|
|
if auth_success:
|
|
print("\n🎉 Authentication is working! You can now:")
|
|
print("1. Visit: http://localhost:3015/webui/")
|
|
print("2. Use credentials: jleu3482 / jleu1212")
|
|
print("3. Upload documents and search")
|
|
|
|
# Test OCR upload if authentication works
|
|
test_ocr_upload()
|
|
else:
|
|
print("\n❌ Authentication is not working properly.")
|
|
print("Please check the server configuration and restart the server.") |