47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
from app.services.upstream_client import UpstreamClient
|
|
|
|
|
|
def test_new_api_token_headers_include_authorization_and_new_api_user():
|
|
client = UpstreamClient(
|
|
base_url="http://newapi.local",
|
|
api_prefix="",
|
|
auth_type="new_api_token",
|
|
auth_config={"token": "access-token", "user_id": "7"},
|
|
)
|
|
|
|
headers = client._headers()
|
|
|
|
assert headers["Authorization"] == "Bearer access-token"
|
|
assert headers["New-Api-User"] == "7"
|
|
assert "Nox-Api-User" not in headers
|
|
|
|
|
|
def test_nox_token_headers_include_authorization_and_nox_api_user():
|
|
client = UpstreamClient(
|
|
base_url="http://nox.local",
|
|
api_prefix="",
|
|
auth_type="nox_token",
|
|
auth_config={"token": "nox-access-token", "user_id": "9"},
|
|
)
|
|
|
|
headers = client._headers()
|
|
|
|
assert headers["Authorization"] == "Bearer nox-access-token"
|
|
assert headers["Nox-Api-User"] == "9"
|
|
assert "New-Api-User" not in headers
|
|
|
|
|
|
def test_bearer_headers_do_not_include_new_or_nox_user_headers():
|
|
client = UpstreamClient(
|
|
base_url="http://sub2api.local",
|
|
api_prefix="/api/v1",
|
|
auth_type="bearer",
|
|
auth_config={"token": "sk-sub2api", "user_id": "11", "new_api_user": "11"},
|
|
)
|
|
|
|
headers = client._headers()
|
|
|
|
assert headers["Authorization"] == "Bearer sk-sub2api"
|
|
assert "New-Api-User" not in headers
|
|
assert "Nox-Api-User" not in headers
|