* fix: configurable JWT TTL with working refresh endpoint (#800) Replace the hardcoded 24h JWT expiration with configurable TTL (default 30d) resolvable via JWT_EXPIRES_IN env var (ceiling) or admin Settings → Security UI. Rewrite /auth/refresh to accept valid-or-recently-expired tokens within a configurable grace window (default 7d), re-verifying the HS256 signature via Web Crypto (since hono/jwt checks exp before signature) and re-validating the user against the database before issuing a fresh token. Updates every token-minting call site (auth routes, OTP plugin, magic-link plugin, OAuth providers) to read the TTL from the DB-aware helper. Adds a live Session / JWT card to Admin → Settings → Security with save/load and matching persistence via SettingsService. Updates repo docs and the doc site authentication page to describe the new configuration surface and refresh semantics. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix: keep /auth/refresh 401 message and flex cookie Max-Age assertion - Restore "Authentication required" as the error message when /auth/refresh is called without a token, matching the prior behavior the E2E contract expects. - Update the cookie E2E to assert Max-Age is present (any positive value) instead of the old hardcoded 86400, since JWT TTL is now configurable. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
E2E Test Suite
This directory contains end-to-end tests for SonicJS AI using Playwright.
Test Files
Core Tests
01-health.spec.ts- Basic health and connectivity tests02-authentication.spec.ts- Login/logout functionality02b-authentication-api.spec.ts- Authentication API component tests03-admin-dashboard.spec.ts- Admin dashboard functionality04-collections.spec.ts- Collections management UI tests05-content.spec.ts- Content management tests06-media.spec.ts- Media upload and management tests07-api.spec.ts- Basic API endpoint tests
API Component Tests
08-collections-api.spec.ts- Collections API component tests08b-admin-collections-api.spec.ts- Admin Collections API component tests
Integration Tests
09-integration.spec.ts- Full workflow integration tests
Authentication API Tests
The Authentication API tests provide comprehensive coverage of:
Authentication Endpoints (02b-authentication-api.spec.ts)
- POST /auth/register - User registration with validation
- POST /auth/login - User authentication
- POST /auth/logout - Session termination
- GET /auth/logout - Logout with redirect
- GET /auth/me - Get current authenticated user
- POST /auth/refresh - Refresh authentication token
- Security testing - XSS, SQL injection, sensitive data exposure
- Session management - Cookie handling, concurrent requests
- Error handling - Malformed requests, validation errors
- Rate limiting - Brute force protection
Collections API Tests
The Collections API tests provide comprehensive coverage of:
Public API Endpoints (08-collections-api.spec.ts)
- GET /api/collections - List all active collections
- GET /api/collections/:collection/content - Get content for specific collection
- GET /api/content - Get all content with pagination
- Error handling - Invalid requests, malformed data, SQL injection protection
- Performance - Response time validation
- Security - Data sanitization, no sensitive information exposure
- Data integrity - Consistent timestamps, valid JSON, referential integrity
Admin API Endpoints (08b-admin-collections-api.spec.ts)
- POST /admin/api/collections - Create new collections (when implemented)
- PUT /admin/api/collections/:id - Update existing collections (when implemented)
- DELETE /admin/api/collections/:id - Delete collections (when implemented)
- GET /admin/api/collections/:id - Get single collection details (when implemented)
- Authentication & Authorization - Proper auth requirement
- Rate limiting & Security - Concurrent request handling, payload validation
- Input sanitization - XSS and SQL injection prevention
Test Utilities
Authentication
loginAsAdmin()- Authenticate as admin userensureAdminUserExists()- Create admin user if needed
Collection Management
createTestCollection()- Create test collection via UIdeleteTestCollection()- Clean up test collection
Test Data
TEST_DATA.collection- Standard test collection dataADMIN_CREDENTIALS- Default admin login credentials
Running Tests
# Run all tests
npm run test:e2e
# Run specific test file
npx playwright test 08-collections-api
# Run with UI
npx playwright test --ui
# Run in debug mode
npx playwright test --debug
Test Strategy
Component Testing Approach
The Collections API tests follow a component testing approach:
- Isolation - Each API endpoint is tested independently
- Coverage - Tests cover happy paths, edge cases, and error conditions
- Security - Validates input sanitization and prevents common attacks
- Performance - Ensures reasonable response times
- Data Integrity - Verifies data consistency and format
Test Categories
- Functional - Core API functionality works as expected
- Security - No vulnerabilities or data exposure
- Performance - Acceptable response times
- Error Handling - Proper error responses and codes
- Authentication - Proper access control
Notes
- Tests are designed to be idempotent and can run multiple times
- Cleanup is automatic using
beforeEach/afterEachhooks - Admin API tests gracefully handle unimplemented endpoints (404/405)
- Tests use real authentication cookies for admin operations
- SQL injection and XSS tests verify proper input sanitization