test(hosted-file): add debug and E2E tests for hash-based download
This commit is contained in:
24
tests/debug_auth_dependency.py
Normal file
24
tests/debug_auth_dependency.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import asyncio
|
||||||
|
from typing import Optional
|
||||||
|
from app.routers.dependencies_v3 import get_account_context_optional
|
||||||
|
|
||||||
|
async def debug_auth():
|
||||||
|
print("--- Debugging get_account_context_optional ---")
|
||||||
|
|
||||||
|
API_KEY = "IDF68Em5X4HTZlswRNgepQ"
|
||||||
|
|
||||||
|
# Simulate Query Param
|
||||||
|
ctx = get_account_context_optional(
|
||||||
|
x_aether_api_key_query=API_KEY
|
||||||
|
)
|
||||||
|
|
||||||
|
print(f"Auth Method: {ctx.auth_method}")
|
||||||
|
print(f"Account ID: {ctx.account_id}")
|
||||||
|
|
||||||
|
if ctx.auth_method == 'guest':
|
||||||
|
print("❌ Result: Guest (Failure)")
|
||||||
|
else:
|
||||||
|
print(f"✅ Result: {ctx.auth_method} (Success)")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(debug_auth())
|
||||||
53
tests/e2e/test_e2e_v3_hash_download.py
Normal file
53
tests/e2e/test_e2e_v3_hash_download.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import requests
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
# The hash from your previous message
|
||||||
|
FILE_HASH = "384fef832fa07b347a1d70927d0606b24cf41771202c1bfa00d7026764db2bb2"
|
||||||
|
BASE_URL = f"https://dev-api.oneskyit.com/v3/action/hosted_file/hash/{FILE_HASH}/download"
|
||||||
|
API_KEY = "PMM4n50teUCaOMMTN8qOJA"
|
||||||
|
|
||||||
|
def test_hash_download_query_param():
|
||||||
|
print(f"--- Testing Hash Download via Query Param API Key ---")
|
||||||
|
|
||||||
|
# Passing api_key in query string as requested
|
||||||
|
url = f"{BASE_URL}?api_key={API_KEY}"
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = requests.get(url)
|
||||||
|
print(f"Status: {response.status_code}")
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
print("✅ Success: File downloaded by hash!")
|
||||||
|
print(f" Content-Length: {response.headers.get('Content-Length')}")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print(f"❌ Failed: {response.text}")
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
print(f"💥 Exception: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def test_hash_download_header():
|
||||||
|
print(f"\n--- Testing Hash Download via Header API Key ---")
|
||||||
|
|
||||||
|
headers = {"X-Aether-API-Key": API_KEY}
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = requests.get(BASE_URL, headers=headers)
|
||||||
|
print(f"Status: {response.status_code}")
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
print("✅ Success: File downloaded by hash via header!")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print(f"❌ Failed: {response.status_code}")
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
print(f"💥 Exception: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
s1 = test_hash_download_query_param()
|
||||||
|
s2 = test_hash_download_header()
|
||||||
|
if s1 and s2:
|
||||||
|
print("\n🎉 HASH DOWNLOAD TESTS PASSED!")
|
||||||
Reference in New Issue
Block a user