Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint-backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
env:
BACKEND_DIR: ./backend
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: ./.github/actions/uv-python-install
name: Install Python, uv and Python dependencies
with:
Expand Down
4 changes: 3 additions & 1 deletion backend/chainlit/auth/cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
_cookie_path = os.environ.get(_cookie_root_path, "/")
else:
_cookie_path = os.environ.get("CHAINLIT_AUTH_COOKIE_PATH", "/")
_state_cookie_lifetime = 3 * 60 # 3m
_state_cookie_lifetime = int(
os.environ.get("CHAINLIT_STATE_COOKIE_LIFETIME", str(3 * 60))
)
_auth_cookie_name = os.environ.get("CHAINLIT_AUTH_COOKIE_NAME", "access_token")
_state_cookie_name = "oauth_state"

Expand Down
17 changes: 17 additions & 0 deletions backend/tests/auth/test_cookie.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import importlib

import pytest
from fastapi import FastAPI, Form
from fastapi.testclient import TestClient
from starlette.requests import Request
from starlette.responses import Response

import chainlit.auth.cookie as cookie_module
from chainlit.auth import (
clear_auth_cookie,
get_token_from_cookies,
Expand Down Expand Up @@ -130,6 +133,20 @@ def test_overwrite_shorter_token_unchunked(client):
assert len(chunk_cookies) == 0, f"Found {len(chunk_cookies)} residual cookies"


def test_state_cookie_lifetime_default(monkeypatch):
"""Test that _state_cookie_lifetime defaults to 180 seconds (3 minutes)."""
monkeypatch.delenv("CHAINLIT_STATE_COOKIE_LIFETIME", raising=False)
importlib.reload(cookie_module)
assert cookie_module._state_cookie_lifetime == 180


def test_state_cookie_lifetime_custom(monkeypatch):
"""Test that _state_cookie_lifetime can be set via environment variable."""
monkeypatch.setenv("CHAINLIT_STATE_COOKIE_LIFETIME", "600")
importlib.reload(cookie_module)
assert cookie_module._state_cookie_lifetime == 600


def test_clear_auth_cookie(client):
"""Test cookie clearing removes all chunks."""
# Set initial token
Expand Down
Loading