v0.5.13: зачистка UI — мёртвый login.ejs, /exp→/export, комментарии
This commit is contained in:
@@ -3,11 +3,12 @@
|
|||||||
*
|
*
|
||||||
* Отвечает только за:
|
* Отвечает только за:
|
||||||
* 1. Инициализацию Express и глобальных middleware (helmet, static, body-parser)
|
* 1. Инициализацию Express и глобальных middleware (helmet, static, body-parser)
|
||||||
* 2. Инициализацию auth (initAuth) и CSRF (initCsrf)
|
* 2. Инициализацию auth (initAuth)
|
||||||
* 3. Подключение роутеров из src/routes/ с передачей зависимостей
|
* 3. Подключение роутеров: src/api/routes/ (API), ui/routes/ (UI)
|
||||||
* 4. Старт HTTP-сервера
|
* 4. Старт HTTP-сервера
|
||||||
*
|
*
|
||||||
* Бизнес-логика — в src/routes/*.js
|
* API-логика — в src/api/routes/
|
||||||
|
* UI-логика — в ui/routes/
|
||||||
* DB-запросы — в src/queries.js
|
* DB-запросы — в src/queries.js
|
||||||
* Auth/JWT — в src/auth.js
|
* Auth/JWT — в src/auth.js
|
||||||
* Валидация — в src/validators.js
|
* Валидация — в src/validators.js
|
||||||
|
|||||||
+11
-11
@@ -68,7 +68,7 @@ async function cleanupAll() {
|
|||||||
const auth = await authMod.initAuth();
|
const auth = await authMod.initAuth();
|
||||||
const { MOCK_USERS } = require('../src/config');
|
const { MOCK_USERS } = require('../src/config');
|
||||||
const admin = MOCK_USERS.find(u => u.id === 'admin');
|
const admin = MOCK_USERS.find(u => u.id === 'admin');
|
||||||
const user = MOCK_USERS.find(u => u.id === 'test');
|
const user = MOCK_USERS.find(u => u.id === 'alfa');
|
||||||
|
|
||||||
const tokenAdmin = auth.issueMockToken({ clientId: admin.clientId, companyId: admin.companyId, companyName: admin.companyName, email: admin.email });
|
const tokenAdmin = auth.issueMockToken({ clientId: admin.clientId, companyId: admin.companyId, companyName: admin.companyName, email: admin.email });
|
||||||
const tokenUser = auth.issueMockToken({ clientId: user.clientId, companyId: user.companyId, companyName: user.companyName, email: user.email });
|
const tokenUser = auth.issueMockToken({ clientId: user.clientId, companyId: user.companyId, companyName: user.companyName, email: user.email });
|
||||||
@@ -771,15 +771,15 @@ async function cleanupAll() {
|
|||||||
|
|
||||||
// ── Rate limit tests ──
|
// ── Rate limit tests ──
|
||||||
|
|
||||||
// S14.1: 10 быстрых запросов к /exp (ограничен exportLimiter=20/мин)
|
// S14.1: 10 быстрых запросов к /export (публичный)
|
||||||
{
|
{
|
||||||
const supertest = require('supertest');
|
const supertest = require('supertest');
|
||||||
const req = supertest(app);
|
const req = supertest(app);
|
||||||
const results = await Promise.all(
|
const results = await Promise.all(
|
||||||
Array(10).fill(0).map(() => req.get('/exp'))
|
Array(10).fill(0).map(() => req.get('/export'))
|
||||||
);
|
);
|
||||||
const all200 = results.every(r => r.status === 200);
|
const all200 = results.every(r => r.status === 200);
|
||||||
log(all200, 'S14.1: 10× GET /exp без авторизации → все 200', results.map(r => r.status).join(','));
|
log(all200, 'S14.1: 10× GET /export без авторизации → все 200', results.map(r => r.status).join(','));
|
||||||
}
|
}
|
||||||
|
|
||||||
// S14.2: 10 быстрых POST /login (ограничен authLimiter)
|
// S14.2: 10 быстрых POST /login (ограничен authLimiter)
|
||||||
@@ -798,22 +798,22 @@ async function cleanupAll() {
|
|||||||
// ══════════════════════════════════════════════════════════════════════════════
|
// ══════════════════════════════════════════════════════════════════════════════
|
||||||
console.log('\n── S15. Export edge cases ──');
|
console.log('\n── S15. Export edge cases ──');
|
||||||
|
|
||||||
// S15.1: /exp с пустой БД
|
// S15.1: /export с пустой БД
|
||||||
{
|
{
|
||||||
const supertest = require('supertest');
|
const supertest = require('supertest');
|
||||||
const req = supertest(app);
|
const req = supertest(app);
|
||||||
const r = await req.get('/exp');
|
const r = await req.get('/export');
|
||||||
log(r.status === 200, 'S15.1: /exp → 200');
|
log(r.status === 200, 'S15.1: /export → 200');
|
||||||
log(r.headers['content-type']?.includes('text/plain'), 'S15.2: /exp Content-Type text/plain');
|
log(r.headers['content-type']?.includes('text/plain'), 'S15.2: /export Content-Type text/plain');
|
||||||
}
|
}
|
||||||
|
|
||||||
// S15.3: /exp после добавления записи
|
// S15.3: /export после добавления записи
|
||||||
{
|
{
|
||||||
await q.createEntry(userCompanyId, C.A, 'export-test', 'stress@test');
|
await q.createEntry(userCompanyId, C.A, 'export-test', 'stress@test');
|
||||||
const supertest = require('supertest');
|
const supertest = require('supertest');
|
||||||
const req = supertest(app);
|
const req = supertest(app);
|
||||||
const r = await req.get('/exp');
|
const r = await req.get('/export');
|
||||||
log(r.status === 200 && r.text.includes(cidr(C.A)), 'S15.3: /exp содержит добавленный CIDR');
|
log(r.status === 200 && r.text.includes(cidr(C.A)), 'S15.3: /export содержит добавленный CIDR');
|
||||||
await pool.query(`UPDATE whitelist_entries SET deleted_at=NOW(), deleted_by='stress' WHERE value_cidr=$1 AND deleted_at IS NULL`,
|
await pool.query(`UPDATE whitelist_entries SET deleted_at=NOW(), deleted_by='stress' WHERE value_cidr=$1 AND deleted_at IS NULL`,
|
||||||
[cidr(C.A)]);
|
[cidr(C.A)]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="ru">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Вход — IP WhiteList</title>
|
|
||||||
<link rel="icon" href="/favicon.png" type="image/png">
|
|
||||||
<style>
|
|
||||||
:root {
|
|
||||||
--bg: #f5f5f5; --card: #ffffff; --text: #1a1a1a; --muted: #6b7280;
|
|
||||||
--border: #d1d5db; --grey-light: #f3f4f6; --blue: #2563eb; --blue-h: #1d4ed8;
|
|
||||||
}
|
|
||||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
||||||
body {
|
|
||||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
||||||
background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
|
|
||||||
display: flex; align-items: center; justify-content: center; min-height: 100vh;
|
|
||||||
}
|
|
||||||
.login-card {
|
|
||||||
background: var(--card); border: 1px solid var(--border); border-radius: 12px;
|
|
||||||
box-shadow: 0 1px 3px rgba(0,0,0,.06); width: 380px; padding: 2rem;
|
|
||||||
}
|
|
||||||
h1 { font-size: 1.2rem; margin-bottom: .25rem; }
|
|
||||||
.sub { color: var(--muted); font-size: .85rem; margin-bottom: 1.5rem; }
|
|
||||||
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: 1rem; }
|
|
||||||
.field label { font-size: .8rem; font-weight: 500; color: var(--muted); text-transform: uppercase; }
|
|
||||||
.field select, .field input {
|
|
||||||
padding: .5rem .75rem; border: 1px solid var(--border); border-radius: 6px;
|
|
||||||
font-size: .9rem; outline: none; background: #fff;
|
|
||||||
}
|
|
||||||
.field select:focus, .field input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
|
|
||||||
.btn {
|
|
||||||
width: 100%; padding: .6rem; border: none; border-radius: 6px; font-size: .9rem;
|
|
||||||
font-weight: 500; cursor: pointer; background: var(--blue); color: #fff;
|
|
||||||
transition: background .15s;
|
|
||||||
}
|
|
||||||
.btn:hover { background: var(--blue-h); }
|
|
||||||
.badge {
|
|
||||||
display: inline-block; padding: .15rem .5rem; border-radius: 4px;
|
|
||||||
font-size: .7rem; font-weight: 600; text-transform: uppercase;
|
|
||||||
}
|
|
||||||
.badge-admin { background: #fef3c7; color: #92400e; }
|
|
||||||
.badge-user { background: #dcfce7; color: #166534; }
|
|
||||||
.note {
|
|
||||||
margin-top: 1.5rem; padding: .75rem; background: #fef3c7; border-radius: 8px;
|
|
||||||
font-size: .8rem; color: #92400e;
|
|
||||||
}
|
|
||||||
.error { color: #dc2626; font-size: .85rem; margin-bottom: 1rem; }
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<div class="login-card">
|
|
||||||
<h1>Вход в IP WhiteList</h1>
|
|
||||||
<p class="sub">Мок-аутентификация — имитация Keycloak</p>
|
|
||||||
|
|
||||||
<% if (error) { %><div class="error"><%= error %></div><% } %>
|
|
||||||
|
|
||||||
<form method="POST" action="/login">
|
|
||||||
<%# CSRF-токен: защита от CSRF-атаки на форму входа %>
|
|
||||||
<input type="hidden" name="_csrf" value="<%= csrfToken %>">
|
|
||||||
<div class="field">
|
|
||||||
<label>Пользователь</label>
|
|
||||||
<select name="user">
|
|
||||||
<% users.forEach(u => { %>
|
|
||||||
<option value="<%= u.id %>">
|
|
||||||
<%= u.label %> <%= u.role === 'admin' ? '(admin)' : '' %>
|
|
||||||
</option>
|
|
||||||
<% }) %>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<button class="btn" type="submit">Войти</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<div class="note">
|
|
||||||
В реальном продакшене здесь будет редирект на Keycloak.<br>
|
|
||||||
После входа пользователь сохраняется в session middleware.
|
|
||||||
<% if (devLoginUrl) { %>
|
|
||||||
<br><a href="<%= devLoginUrl %>" style="color:inherit">Тестовый вход (dev-backdoor) →</a>
|
|
||||||
<% } %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<footer style="text-align:right;padding:.5rem 1.5rem;font-size:.72rem;color:var(--muted);">v<%= appVersion %></footer>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Reference in New Issue
Block a user