Files
myworkspace/LinkSyncServer/tests/test_auth.py
DavidSaylor 09d30427f4 Complete LinkSyncServer and LinkSyncExtension implementation
LinkSyncServer:
- Fix app.py imports, add CORS middleware, lifespan events
- Create api/routes.py router aggregator
- Create config/settings.py for centralized configuration
- Rewrite models/base.py with proper relationships and serialization
- Rewrite all API endpoints with real DB integration (auth, links, collections, sync, queries, tags)
- Add admin endpoints (user management, stats, audit log)
- Complete query parser with recursive descent and proper precedence
- Complete query executor with set operations and field filters
- Set up Alembic migrations with initial schema
- Create web interface (templates, CSS, JS)
- Add 42 passing tests (auth, links, collections, queries)
- Add deploy.ps1 and deploy.sh scripts
- Update README with deployment workflow

LinkSyncExtension:
- Create utils/api.js (REST client with retries, auth, error handling)
- Create utils/sync.js (3 sync modes + conflict detection)
- Create utils/collection.js (collection management)
- Create utils/query-engine.js (client-side query parser)
- Rewrite background.js (sync loop, bookmark events, message routing)
- Rewrite popup.js (tabs, settings modal, notifications, CRUD)
- Update popup.html (tabbed interface, query builder, modal)
- Update popup.css (full redesign)
- Create content/content.js (page metadata extraction)
- Create options.html/js (dedicated settings page)
- Generate icons (48x48, 96x96)
- Update manifest.json (host permissions, content scripts, options)
- Create AGENTS.md
2026-05-19 13:21:26 -05:00

91 lines
2.9 KiB
Python

"""
LinkSyncServer - Authentication Tests
"""
import pytest
from fastapi.testclient import TestClient
class TestAuth:
def test_login_admin(self, client: TestClient):
response = client.post(
"/api/auth/login",
data={"username": "admin", "password": "admin123"},
)
assert response.status_code == 200
data = response.json()
assert "access_token" in data
assert data["token_type"] == "bearer"
assert data["user"]["role"] == "admin"
def test_login_invalid(self, client: TestClient):
response = client.post(
"/api/auth/login",
data={"username": "invalid", "password": "wrong"},
)
assert response.status_code == 401
def test_register_user(self, client: TestClient):
import uuid
unique = str(uuid.uuid4())[:8]
response = client.post(
"/api/auth/register",
json={
"username": f"testuser_{unique}",
"email": f"test_{unique}@example.com",
"password": "testpass123",
},
)
assert response.status_code == 200
data = response.json()
assert data["user"]["username"] == f"testuser_{unique}"
assert data["user"]["role"] == "user"
def test_register_duplicate(self, client: TestClient):
import uuid
unique = str(uuid.uuid4())[:8]
client.post(
"/api/auth/register",
json={
"username": f"dupuser_{unique}",
"email": f"dup_{unique}@example.com",
"password": "testpass123",
},
)
response = client.post(
"/api/auth/register",
json={
"username": f"dupuser_{unique}",
"email": f"dup2_{unique}@example.com",
"password": "testpass123",
},
)
assert response.status_code == 400
def test_logout(self, client: TestClient):
response = client.post("/api/auth/logout")
assert response.status_code == 200
def test_get_me_unauthenticated(self, client: TestClient):
response = client.get("/api/auth/me")
assert response.status_code == 401
def test_get_me_authenticated(self, client: TestClient, admin_token: str):
response = client.get(
"/api/auth/me",
headers={"Authorization": f"Bearer {admin_token}"},
)
assert response.status_code == 200
assert response.json()["username"] == "admin"
def test_create_api_key(self, client: TestClient, admin_token: str):
response = client.post(
"/api/auth/api-key",
params={"name": "test-key"},
headers={"Authorization": f"Bearer {admin_token}"},
)
assert response.status_code == 200
data = response.json()
assert "api_key" in data
assert "key_id" in data