mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-09 10:21:03 +00:00
ce50db0fde
SECURITY (critical fixes):
- Add authMiddleware to /api/system/console-token (was publicly accessible)
- Validate api_url on node create/update to prevent SSRF (rejects localhost/loopback)
- Add rate limiting (5 req/15 min/IP) to /api/auth/login and /api/auth/setup
- Fix path traversal in env_file resolution — absolute/escaping paths rejected
- Add stack name validation to GET routes (was only on PUT/POST)
- Add helmet security headers middleware
- Restrict CORS to FRONTEND_URL in production
PRODUCTION READINESS:
- Add GET /api/health public endpoint + HEALTHCHECK in Dockerfile
- Add SIGTERM/SIGINT graceful shutdown handler (drains connections, closes DB)
- Run container as non-root sencho user in Dockerfile
QUALITY:
- Fix 4 silent empty catch{} blocks in EditorLayout (now show toast.error)
- Connect ErrorBoundary to root App in main.tsx
- Replace WebSocket.Server with named WebSocketServer import (ESM compat)
TESTING (new automated test suite):
- Install Vitest; 38 backend tests across 4 suites covering validation utilities,
health endpoint, auth middleware, login flows, SSRF protection, and path traversal
- Extract isValidStackName/isValidRemoteUrl/isPathWithinBase to utils/validation.ts
- Playwright E2E scaffolding: auth, stacks, nodes specs + shared login helper
- CI: run Vitest + ESLint on every PR
50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
/**
|
|
* Authentication E2E tests.
|
|
* Tests login, logout, and unauthenticated redirect.
|
|
*/
|
|
import { test, expect } from '@playwright/test';
|
|
import { loginAs, TEST_USERNAME, TEST_PASSWORD } from './helpers';
|
|
|
|
test.describe('Authentication', () => {
|
|
test('login with valid credentials shows the dashboard', async ({ page }) => {
|
|
await loginAs(page);
|
|
// Should see the main editor/dashboard — not a login page
|
|
await expect(page).not.toHaveURL(/login/i);
|
|
await expect(page.getByRole('main')).toBeVisible();
|
|
});
|
|
|
|
test('login with wrong password shows an error', async ({ page }) => {
|
|
await page.goto('/');
|
|
// Skip setup if needed
|
|
const isSetup = await page.getByRole('heading', { name: /setup/i }).isVisible().catch(() => false);
|
|
if (isSetup) {
|
|
// Must complete setup before we can test wrong password
|
|
await loginAs(page);
|
|
await page.goto('/login');
|
|
}
|
|
|
|
await page.getByLabel(/username/i).fill(TEST_USERNAME);
|
|
await page.getByLabel(/password/i).fill('definitly-wrong-password');
|
|
await page.getByRole('button', { name: /login|sign in/i }).click();
|
|
|
|
await expect(page.getByText(/invalid|incorrect|wrong/i)).toBeVisible();
|
|
});
|
|
|
|
test('visiting a protected page without auth redirects to login', async ({ page }) => {
|
|
// Clear cookies to simulate logged-out state
|
|
await page.context().clearCookies();
|
|
await page.goto('/');
|
|
await expect(page).toHaveURL(/login|setup/i);
|
|
});
|
|
|
|
test('logout redirects to login', async ({ page }) => {
|
|
await loginAs(page);
|
|
// Find and click the logout button (varies by UI — adjust selector as needed)
|
|
const logoutBtn = page.getByRole('button', { name: /logout|sign out/i });
|
|
if (await logoutBtn.isVisible()) {
|
|
await logoutBtn.click();
|
|
await expect(page).toHaveURL(/login/i);
|
|
}
|
|
});
|
|
});
|