diff --git a/tests/test_companion_readonly.py b/tests/test_companion_readonly.py index 39f18599d..9ea0d63f0 100644 --- a/tests/test_companion_readonly.py +++ b/tests/test_companion_readonly.py @@ -279,6 +279,47 @@ def test_models_route_unresolved_owner_returns_only_shared_rows(monkeypatch): assert _endpoint_names(endpoints) == ["shared-endpoint"] +def test_models_route_auth_disabled_does_not_widen_ownerless_api_token(monkeypatch): + monkeypatch.setenv("AUTH_ENABLED", "false") + rows = [ + _ep(1, "alice-endpoint", "alice"), + _ep(2, "shared-endpoint", None), + _ep(3, "bob-endpoint", "bob"), + ] + monkeypatch.setattr(companion_routes, "get_current_user", lambda request: None) + + endpoints = _call_models_route( + monkeypatch, + rows, + _request( + api_token=True, + api_token_owner=None, + api_token_scopes=["chat"], + current_user="api", + ), + ) + + assert _endpoint_names(endpoints) == ["shared-endpoint"] + + +def test_models_route_auth_disabled_keeps_cookie_owner_scoped(monkeypatch): + monkeypatch.setenv("AUTH_ENABLED", "false") + rows = [ + _ep(1, "alice-endpoint", "alice"), + _ep(2, "shared-endpoint", None), + _ep(3, "bob-endpoint", "bob"), + ] + monkeypatch.setattr(companion_routes, "get_current_user", lambda request: "alice") + + endpoints = _call_models_route( + monkeypatch, + rows, + _request(api_token=False, current_user="alice"), + ) + + assert _endpoint_names(endpoints) == ["alice-endpoint", "shared-endpoint"] + + def test_models_route_auth_enabled_anonymous_returns_only_shared_rows(monkeypatch): monkeypatch.setenv("AUTH_ENABLED", "true") rows = [