This repository was archived by the owner on Dec 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_scheme_handling.py
More file actions
58 lines (45 loc) · 1.84 KB
/
test_scheme_handling.py
File metadata and controls
58 lines (45 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
"""
Test script to verify that the application correctly handles URL schemes when behind a proxy.
This script simulates a request with the X-Forwarded-Proto header set to "https"
and checks if the manifest URL in the response uses HTTPS.
"""
import requests
import json
import sys
# Base URL of the application
BASE_URL = "http://localhost:8000"
def test_scheme_handling():
"""Test that the application correctly handles URL schemes when behind a proxy."""
print("Testing URL scheme handling...")
# Test the save-config endpoint with X-Forwarded-Proto header
headers = {"X-Forwarded-Proto": "https", "Content-Type": "application/x-www-form-urlencoded"}
# Minimal form data required for the save-config endpoint
data = {
"openai_api_key": "test_key",
"tmdb_read_access_token": "test_token",
"model_name": "test_model",
"max_results": 10,
}
try:
response = requests.post(f"{BASE_URL}/save-config", headers=headers, data=data)
response.raise_for_status()
# Parse the response JSON
result = response.json()
# Check if the manifest URL uses HTTPS
if "manifest_url" in result and result["manifest_url"].startswith("https://"):
print("✅ Success: Manifest URL uses HTTPS scheme")
print(f"Manifest URL: {result['manifest_url']}")
return True
else:
print("❌ Error: Manifest URL does not use HTTPS scheme")
print(f"Response: {json.dumps(result, indent=2)}")
return False
except requests.exceptions.RequestException as e:
print(f"❌ Error making request: {e}")
return False
except Exception as e:
print(f"❌ Unexpected error: {e}")
return False
if __name__ == "__main__":
success = test_scheme_handling()
sys.exit(0 if success else 1)