2024-09-13 18:28:36 +00:00
|
|
|
from http import HTTPStatus
|
|
|
|
|
2024-10-21 13:19:31 +00:00
|
|
|
import httpx
|
2024-09-13 18:04:37 +00:00
|
|
|
import pytest
|
2024-09-13 18:28:36 +00:00
|
|
|
from starlette.testclient import TestClient
|
2024-09-13 18:04:37 +00:00
|
|
|
|
2024-09-13 18:28:36 +00:00
|
|
|
from main import app
|
2025-02-17 23:08:14 +00:00
|
|
|
from src.models import LinkRequest
|
2024-09-13 18:04:37 +00:00
|
|
|
|
2024-09-13 18:28:36 +00:00
|
|
|
client = TestClient(app)
|
|
|
|
|
2024-09-13 18:04:37 +00:00
|
|
|
test_websites = [
|
2024-10-27 18:40:21 +00:00
|
|
|
"https://ext.to/",
|
2024-10-27 18:46:19 +00:00
|
|
|
"https://www.ygg.re/",
|
|
|
|
"https://extratorrent.st/",
|
|
|
|
"https://idope.se/",
|
|
|
|
"https://speed.cd/login",
|
|
|
|
]
|
|
|
|
|
2024-09-13 18:04:37 +00:00
|
|
|
|
|
|
|
@pytest.mark.parametrize("website", test_websites)
|
2024-09-13 18:28:36 +00:00
|
|
|
def test_bypass(website: str):
|
2024-11-28 12:33:04 +00:00
|
|
|
"""
|
|
|
|
Tests if the service can bypass cloudflare/DDOS-GUARD on given websites.
|
|
|
|
|
|
|
|
This test is skipped if the website is not reachable or does not have cloudflare/DDOS-GUARD.
|
|
|
|
"""
|
2024-10-21 13:19:31 +00:00
|
|
|
test_request = httpx.get(
|
|
|
|
website,
|
|
|
|
)
|
2024-10-27 18:32:06 +00:00
|
|
|
if (
|
2025-02-20 20:37:02 +00:00
|
|
|
test_request.status_code != HTTPStatus.OK
|
2024-10-27 18:32:06 +00:00
|
|
|
and "Just a moment..." not in test_request.text
|
|
|
|
):
|
2024-11-21 22:59:27 +00:00
|
|
|
pytest.skip(f"Skipping {website} due to {test_request.status_code}")
|
2024-10-21 13:19:31 +00:00
|
|
|
|
2024-09-13 18:28:36 +00:00
|
|
|
response = client.post(
|
|
|
|
"/v1",
|
2025-02-17 23:08:14 +00:00
|
|
|
json={
|
|
|
|
**LinkRequest.model_construct(
|
|
|
|
url=website, max_timeout=30, cmd="request.get"
|
|
|
|
).model_dump(),
|
2025-02-27 19:01:39 +00:00
|
|
|
# "proxy": "203.174.15.83:8080",
|
2025-02-17 23:08:14 +00:00
|
|
|
},
|
2024-09-13 18:28:36 +00:00
|
|
|
)
|
2024-10-21 13:19:31 +00:00
|
|
|
|
2024-09-13 18:28:36 +00:00
|
|
|
assert response.status_code == HTTPStatus.OK
|
2024-10-21 13:34:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_health_check():
|
2024-11-28 12:33:04 +00:00
|
|
|
"""
|
|
|
|
Tests the health check endpoint.
|
|
|
|
|
|
|
|
This test ensures that the health check
|
|
|
|
endpoint returns HTTPStatus.OK.
|
|
|
|
"""
|
2024-10-21 13:34:07 +00:00
|
|
|
response = client.get("/health")
|
|
|
|
assert response.status_code == HTTPStatus.OK
|