Refactor: reorganización completa del proyecto y documentación consolidada
Esta actualización reorganiza el proyecto de reverse engineering de la API de ADIF con los siguientes cambios: Estructura del proyecto: - Movida documentación principal a carpeta docs/ - Consolidados archivos markdown redundantes en CLAUDE.md (contexto completo del proyecto) - Organización de tests en carpeta tests/ con README explicativo - APK renombrado de base.apk a adif.apk para mayor claridad Archivos de código: - Movidos adif_auth.py y adif_client.py a la raíz (antes en api_testing_scripts/) - Eliminados scripts de testing obsoletos y scripts de Frida no utilizados - Nuevos tests detallados: test_endpoints_detailed.py y test_onepaths_with_real_trains.py Descubrimientos: - Documentados nuevos hallazgos en docs/NEW_DISCOVERIES.md - Actualización de onePaths funcionando con commercialNumber real (devuelve 200) - Extraídos 1587 códigos de estación en station_codes.txt Configuración: - Actualizado .gitignore con mejores patrones para Python e IDEs - Eliminados archivos temporales de depuración y logs
This commit is contained in:
180
tests/test_api_authenticated.py
Normal file
180
tests/test_api_authenticated.py
Normal file
@@ -0,0 +1,180 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test de endpoints de Adif con autenticación HMAC-SHA256
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
# Agregar raíz del proyecto al path para importar adif_auth
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
import requests
|
||||
import json
|
||||
from adif_auth import AdifAuthenticator
|
||||
|
||||
# Claves extraídas con Frida
|
||||
ACCESS_KEY = "and20210615"
|
||||
SECRET_KEY = "Jthjtr946RTt"
|
||||
USER_ID = "0c8c32dce47f8512"
|
||||
|
||||
# Crear autenticador
|
||||
auth = AdifAuthenticator(ACCESS_KEY, SECRET_KEY, USER_ID)
|
||||
|
||||
def test_departures():
|
||||
"""Probar endpoint de salidas"""
|
||||
print("\n" + "="*70)
|
||||
print("TEST: Salidas de Madrid Atocha (Cercanías)")
|
||||
print("="*70)
|
||||
|
||||
host = "circulacion.api.adif.es"
|
||||
path = "/portroyalmanager/secure/circulationpaths/departures/traffictype/"
|
||||
url = f"https://{host}{path}"
|
||||
|
||||
payload = {
|
||||
"stationCode": "10200",
|
||||
"commercialService": "BOTH",
|
||||
"commercialStopType": "BOTH",
|
||||
"page": {"pageNumber": 0},
|
||||
"trafficType": "CERCANIAS"
|
||||
}
|
||||
|
||||
payload_str = json.dumps(payload)
|
||||
|
||||
# Firmar petición
|
||||
headers = auth.sign_request(
|
||||
method="POST",
|
||||
host=host,
|
||||
path=path,
|
||||
payload=payload_str
|
||||
)
|
||||
|
||||
print(f"\nURL: {url}")
|
||||
print(f"Payload: {payload_str}")
|
||||
print(f"\nHeaders:")
|
||||
for k, v in headers.items():
|
||||
if k == "Authorization":
|
||||
print(f" {k}: {v[:50]}...")
|
||||
else:
|
||||
print(f" {k}: {v}")
|
||||
|
||||
# Hacer petición
|
||||
try:
|
||||
response = requests.post(url, headers=headers, data=payload_str, timeout=10)
|
||||
print(f"\nStatus Code: {response.status_code}")
|
||||
|
||||
if response.status_code == 200:
|
||||
print("✅ SUCCESS!")
|
||||
data = response.json()
|
||||
print(f"\nRespuesta (preview):")
|
||||
print(json.dumps(data, indent=2, ensure_ascii=False)[:1000])
|
||||
else:
|
||||
print(f"❌ ERROR")
|
||||
print(f"Response: {response.text[:500]}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ EXCEPTION: {e}")
|
||||
|
||||
|
||||
def test_station_details():
|
||||
"""Probar endpoint de detalles de estación"""
|
||||
print("\n" + "="*70)
|
||||
print("TEST: Detalles de estación Madrid Atocha")
|
||||
print("="*70)
|
||||
|
||||
host = "estaciones.api.adif.es"
|
||||
path = "/portroyalmanager/secure/stations/onestation/"
|
||||
url = f"https://{host}{path}"
|
||||
|
||||
payload = {"stationCode": "10200"}
|
||||
payload_str = json.dumps(payload)
|
||||
|
||||
headers = auth.sign_request(
|
||||
method="POST",
|
||||
host=host,
|
||||
path=path,
|
||||
payload=payload_str
|
||||
)
|
||||
|
||||
print(f"\nURL: {url}")
|
||||
print(f"Payload: {payload_str}")
|
||||
|
||||
try:
|
||||
response = requests.post(url, headers=headers, data=payload_str, timeout=10)
|
||||
print(f"\nStatus Code: {response.status_code}")
|
||||
|
||||
if response.status_code == 200:
|
||||
print("✅ SUCCESS!")
|
||||
data = response.json()
|
||||
print(f"\nRespuesta (preview):")
|
||||
print(json.dumps(data, indent=2, ensure_ascii=False)[:1000])
|
||||
else:
|
||||
print(f"❌ ERROR")
|
||||
print(f"Response: {response.text[:500]}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ EXCEPTION: {e}")
|
||||
|
||||
|
||||
def test_arrivals():
|
||||
"""Probar endpoint de llegadas"""
|
||||
print("\n" + "="*70)
|
||||
print("TEST: Llegadas a Madrid Atocha (Todos los tipos)")
|
||||
print("="*70)
|
||||
|
||||
host = "circulacion.api.adif.es"
|
||||
path = "/portroyalmanager/secure/circulationpaths/arrivals/traffictype/"
|
||||
url = f"https://{host}{path}"
|
||||
|
||||
payload = {
|
||||
"stationCode": "10200",
|
||||
"commercialService": "BOTH",
|
||||
"commercialStopType": "BOTH",
|
||||
"page": {"pageNumber": 0},
|
||||
"trafficType": "ALL"
|
||||
}
|
||||
|
||||
payload_str = json.dumps(payload)
|
||||
|
||||
headers = auth.sign_request(
|
||||
method="POST",
|
||||
host=host,
|
||||
path=path,
|
||||
payload=payload_str
|
||||
)
|
||||
|
||||
print(f"\nURL: {url}")
|
||||
|
||||
try:
|
||||
response = requests.post(url, headers=headers, data=payload_str, timeout=10)
|
||||
print(f"\nStatus Code: {response.status_code}")
|
||||
|
||||
if response.status_code == 200:
|
||||
print("✅ SUCCESS!")
|
||||
data = response.json()
|
||||
print(f"\nRespuesta (preview):")
|
||||
print(json.dumps(data, indent=2, ensure_ascii=False)[:800])
|
||||
else:
|
||||
print(f"❌ ERROR")
|
||||
print(f"Response: {response.text[:500]}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ EXCEPTION: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("\n" + "="*70)
|
||||
print("PRUEBAS DE API ADIF CON AUTENTICACIÓN HMAC-SHA256")
|
||||
print("="*70)
|
||||
print(f"\nUsando claves:")
|
||||
print(f" ACCESS_KEY: {ACCESS_KEY}")
|
||||
print(f" SECRET_KEY: {SECRET_KEY}")
|
||||
print(f" USER_ID: {USER_ID}")
|
||||
|
||||
# Ejecutar tests
|
||||
test_departures()
|
||||
test_station_details()
|
||||
test_arrivals()
|
||||
|
||||
print("\n" + "="*70)
|
||||
print("TESTS COMPLETADOS")
|
||||
print("="*70)
|
||||
Reference in New Issue
Block a user