Settings fixes: - MAX_SITES_PER_USER, USER_RATE_LIMIT_PER_MIN/HR now read from DB settings table (DB > ENV > default), so dashboard/settings changes apply without restart. Sync cache refreshed on every save or delete. - /api/me reports the live DB value for max_sites_per_user. Admin improvements: - Admin users bypass per-user rate limiting entirely (role=admin or ADMIN_EMAILS). - Admin Overview now shows platform stats: registered users, new users (7d), total user sites, available tools. Plugin cleanup: - Appwrite and Directus plugins removed from the active registry (8 plugins now: WordPress, WooCommerce, WordPress Specialist, Gitea, n8n, Supabase, OpenPanel, Coolify). Plugin code is retained for future re-enabling. - Settings page plugin visibility list updated to match. Mobile onboarding: - Stepper steps on narrow viewports stack vertically with correct full border and rounded corners on each step. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
82 lines
2.7 KiB
Python
82 lines
2.7 KiB
Python
"""Tests for the unified legacy /dashboard-legacy/keys page (F.7b session 2)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from starlette.testclient import TestClient
|
|
|
|
import core.dashboard.routes as routes_module
|
|
import core.database as db_module
|
|
from core.database import Database
|
|
|
|
|
|
@pytest.fixture
|
|
async def patched_db(tmp_path, monkeypatch):
|
|
database = Database(str(tmp_path / "keys.db"))
|
|
await database.initialize()
|
|
monkeypatch.setattr(db_module, "_database", database)
|
|
yield database
|
|
await database.close()
|
|
monkeypatch.setattr(db_module, "_database", None)
|
|
|
|
|
|
@pytest.fixture
|
|
async def user_row(patched_db):
|
|
return await patched_db.create_user(
|
|
email="keys@example.com",
|
|
name="keysuser",
|
|
provider="github",
|
|
provider_id="gh-keys-user",
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def user_client(monkeypatch, user_row, patched_db):
|
|
from server import create_multi_endpoint_app
|
|
|
|
def fake_user_session(_request):
|
|
return {"user_id": user_row["id"], "type": "user"}, None
|
|
|
|
monkeypatch.setattr(routes_module, "_require_user_session", fake_user_session)
|
|
|
|
# Also patch auth so dashboard_keys_unified finds the user session
|
|
class FakeAuth:
|
|
def get_session_from_request(self, _r):
|
|
return None # not admin
|
|
|
|
def get_user_session_from_request(self, _r):
|
|
return {"user_id": user_row["id"], "type": "user"}
|
|
|
|
monkeypatch.setattr(routes_module, "get_dashboard_auth", lambda: FakeAuth())
|
|
|
|
app = create_multi_endpoint_app()
|
|
return TestClient(app, follow_redirects=False)
|
|
|
|
|
|
class TestUnifiedKeysUserView:
|
|
def test_get_keys_page_returns_200(self, user_client):
|
|
r = user_client.get("/dashboard-legacy/keys")
|
|
assert r.status_code == 200
|
|
assert "API Key" in r.text or "کلید" in r.text
|
|
|
|
def test_old_connect_redirects_301(self, user_client):
|
|
r = user_client.get("/dashboard-legacy/connect")
|
|
assert r.status_code == 301
|
|
assert "/dashboard-legacy/keys" in r.headers["location"]
|
|
|
|
def test_old_api_keys_redirects_301(self, user_client):
|
|
r = user_client.get("/dashboard-legacy/api-keys")
|
|
assert r.status_code == 301
|
|
assert "/dashboard-legacy/keys" in r.headers["location"]
|
|
|
|
def test_user_view_has_full_access_badge(self, user_client):
|
|
r = user_client.get("/dashboard-legacy/keys")
|
|
assert r.status_code == 200
|
|
# F.7c: No scope selector — shows "Full Access" badge instead
|
|
assert "Full Access" in r.text or "دسترسی کامل" in r.text
|
|
|
|
def test_user_view_shows_create_button(self, user_client):
|
|
r = user_client.get("/dashboard-legacy/keys")
|
|
assert r.status_code == 200
|
|
assert "Create" in r.text or "ایجاد" in r.text
|