Skip to content

Commit

Permalink
fix: remove exp from jwt (#4729)
Browse files Browse the repository at this point in the history
* fix: remove exp from jwt

* clean up
  • Loading branch information
RogerHYang authored Sep 25, 2024
1 parent bed47c5 commit 0e6e1e8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
10 changes: 7 additions & 3 deletions integration_tests/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,14 +527,18 @@ def handle_request(self, request: httpx.Request) -> httpx.Response:
_HTTPX_OP_IDX.set(op_idx + 1)
info.write(f"({op_idx})".encode())
info.write(f"{test_name}\n".encode())
response = self._transport.handle_request(request)
info.write(f"{response.status_code} {request.method} {request.url}\n".encode())
info.write(f"{request.method} {request.url}\n".encode())
if token_ids := _decode_token_ids(request.headers):
info.write(f"{' '.join(token_ids)}\n".encode())
info.write(f"{request.headers}\n".encode())
info.write(request.read())
info.write(b"\n")
info.write(f"{response.headers}\n".encode())
try:
response = self._transport.handle_request(request)
except BaseException:
print(info.getvalue().decode())
raise
info.write(f"{response.status_code} {response.headers}\n".encode())
if returned_token_ids := _decode_token_ids(response.headers, "set-cookie"):
info.write(f"{' '.join(returned_token_ids)}\n".encode())
return _LogResponse(
Expand Down
8 changes: 5 additions & 3 deletions integration_tests/auth/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@
get_env_smtp_port,
get_env_smtp_username,
)
from portpicker import pick_unused_port # type: ignore[import-untyped]
from smtpdfix import AuthController, Config, SMTPDFix
from smtpdfix.certs import _generate_certs

from .._helpers import _Secret, _server


@pytest.fixture(scope="module")
def _secret() -> _Secret:
def _secret(
_env_phoenix_sql_database_url: Any,
) -> _Secret:
return secrets.token_hex(DEFAULT_SECRET_LENGTH)


@pytest.fixture(autouse=True, scope="module")
def _app(
_ports: Iterator[int],
_secret: _Secret,
_env_phoenix_sql_database_url: Any,
_fake: Faker,
Expand All @@ -45,7 +47,7 @@ def _app(
(ENV_PHOENIX_DISABLE_RATE_LIMIT, "true"),
(ENV_PHOENIX_SECRET, _secret),
(ENV_PHOENIX_SMTP_HOSTNAME, "127.0.0.1"),
(ENV_PHOENIX_SMTP_PORT, str(pick_unused_port())),
(ENV_PHOENIX_SMTP_PORT, str(next(_ports))),
(ENV_PHOENIX_SMTP_USERNAME, "test"),
(ENV_PHOENIX_SMTP_PASSWORD, "test"),
(ENV_PHOENIX_SMTP_MAIL_FROM, _fake.email()),
Expand Down
25 changes: 21 additions & 4 deletions integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from contextlib import ExitStack
from dataclasses import asdict
from itertools import count, starmap
from typing import Generator, Iterator, Optional, Tuple, cast
from typing import Generator, Iterator, List, Optional, Tuple, cast
from unittest import mock

import pytest
Expand Down Expand Up @@ -46,6 +46,19 @@
)


@pytest.fixture(scope="session")
def _ports() -> Iterator[int]:
def _(used: List[int]) -> Iterator[int]:
while True:
port = pick_unused_port()
if port not in used:
print("PORT", port)
used.append(port)
yield port

return _([])


@pytest.fixture(
scope="session",
params=[
Expand Down Expand Up @@ -75,11 +88,15 @@ def _fake() -> Faker:


@pytest.fixture(autouse=True, scope="module")
def _env(tmp_path_factory: TempPathFactory) -> Iterator[None]:
def _env(
_sql_database_url: URL,
_ports: Iterator[int],
tmp_path_factory: TempPathFactory,
) -> Iterator[None]:
tmp = tmp_path_factory.getbasetemp()
values = (
(ENV_PHOENIX_PORT, str(pick_unused_port())),
(ENV_PHOENIX_GRPC_PORT, str(pick_unused_port())),
(ENV_PHOENIX_PORT, str(next(_ports))),
(ENV_PHOENIX_GRPC_PORT, str(next(_ports))),
(ENV_PHOENIX_WORKING_DIR, str(tmp)),
)
with mock.patch.dict(os.environ, values):
Expand Down
2 changes: 0 additions & 2 deletions src/phoenix/server/jwt_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ def __init__(

def _encode(self, claim: ClaimSet) -> str:
payload: Dict[str, Any] = dict(jti=claim.token_id)
if claim.expiration_time:
payload["exp"] = int(claim.expiration_time.timestamp())
header = {"alg": self._algorithm}
jwt_bytes: bytes = jwt.encode(header=header, payload=payload, key=self._secret)
return jwt_bytes.decode()
Expand Down

0 comments on commit 0e6e1e8

Please sign in to comment.