43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
|
|
# retoor <retoor@molodetz.nl>
|
||
|
|
|
||
|
|
import httpx
|
||
|
|
import pytest
|
||
|
|
from devplacepy.main import app
|
||
|
|
from devplacepy.config import DATABASE_URL
|
||
|
|
from tests.conftest import run_async
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture
|
||
|
|
def client():
|
||
|
|
from devplacepy.database import init_db
|
||
|
|
|
||
|
|
init_db()
|
||
|
|
with httpx.Client(app=app) as c:
|
||
|
|
yield c
|
||
|
|
|
||
|
|
|
||
|
|
def test_localhost_ipv4_allowed_through(client):
|
||
|
|
gateway_url = "http://127.0.0.1/openai/v1/chat/completions"
|
||
|
|
response = client.get(gateway_url, headers={"accept": "application/json"})
|
||
|
|
assert response.status_code != 403
|
||
|
|
|
||
|
|
|
||
|
|
def test_localhost_ipv6_allowed_through(client):
|
||
|
|
gateway_url = "http://[::1]/openai/v1/models"
|
||
|
|
response = client.get(gateway_url, headers={"accept": "application/json"})
|
||
|
|
assert response.status_code != 403
|
||
|
|
|
||
|
|
|
||
|
|
def test_non_openai_path_not_affected(client):
|
||
|
|
response = client.get("http://127.0.0.1/feed", headers={"accept": "application/json"})
|
||
|
|
assert response.status_code != 403
|
||
|
|
|
||
|
|
|
||
|
|
def test_external_ip_rejected(client):
|
||
|
|
response = client.get(
|
||
|
|
"http://10.0.0.1/openai/v1/chat/completions",
|
||
|
|
headers={"accept": "application/json"},
|
||
|
|
)
|
||
|
|
assert response.status_code == 403
|
||
|
|
assert response.json() == {"detail": "Forbidden"}
|