test: export content, empty comment, deleted not in export (53/53 pass)

This commit is contained in:
2026-05-30 17:20:41 +03:00
parent 1e330a4395
commit 7d2b6a309f
+68
View File
@@ -678,6 +678,74 @@ async function cleanup() {
);
}
// ─────────────────────────────────────────────────────────────────────────────
// 26. Пустой comment — должен сохранять запись без ошибки
// ─────────────────────────────────────────────────────────────────────────────
console.log('\n── 26. Пустой comment ──');
{
const csrf = await getCsrfFromIndex(userAgent);
const res = await userAgent.post('/add').type('form')
.send({ value: '7.7.7.7', comment: '', _csrf: csrf });
const err = getRedirectParam(res, 'error');
log(!err && res.status === 302, 'user: добавил запись без comment', `err=${err}`);
// Чистим
await pool.query(
`UPDATE whitelist_entries SET deleted_at = NOW(), deleted_by = 'test-cleanup'
WHERE value_cidr = '7.7.7.7/32' AND deleted_at IS NULL`
);
}
// ─────────────────────────────────────────────────────────────────────────────
// 27. Export содержит CIDR текущей компании
// ─────────────────────────────────────────────────────────────────────────────
console.log('\n── 27. Export содержит CIDR ──');
{
// Добавим уникальную запись и проверим что она появляется в export
const csrf = await getCsrfFromIndex(userAgent);
await userAgent.post('/add').type('form')
.send({ value: '6.6.6.6', comment: 'export test', _csrf: csrf });
const res = await userAgent.get('/export');
log(res.status === 200, 'user: /export → 200');
const hasCidr = res.text.includes('6.6.6.6');
log(hasCidr, 'user: добавленный CIDR виден в /export',
hasCidr ? 'found' : `text=${res.text.slice(0, 100)}`);
// Чистим
await pool.query(
`UPDATE whitelist_entries SET deleted_at = NOW(), deleted_by = 'test-cleanup'
WHERE value_cidr = '6.6.6.6/32' AND deleted_at IS NULL`
);
}
// ─────────────────────────────────────────────────────────────────────────────
// 28. Удалённая запись не видна в export
// ─────────────────────────────────────────────────────────────────────────────
console.log('\n── 28. Удалённая запись не в export ──');
{
// Добавляем, потом удаляем, проверяем что нет в export
const csrf = await getCsrfFromIndex(userAgent);
const addRes = await userAgent.post('/add').type('form')
.send({ value: '4.4.4.4', comment: 'будет удалена', _csrf: csrf });
// Ищем id в БД
const r = await pool.query(
`SELECT id FROM whitelist_entries WHERE value_cidr = '4.4.4.4/32' AND deleted_at IS NULL`
);
const delId = r.rows[0]?.id;
if (delId) {
const csrf2 = await getCsrfFromIndex(userAgent);
await userAgent.post(`/delete/${delId}`).type('form').send({ _csrf: csrf2 });
}
const exportRes = await userAgent.get('/export');
log(!exportRes.text.includes('4.4.4.4'),
'user: удалённый CIDR не виден в /export');
}
// ─────────────────────────────────────────────────────────────────────────────
// 24. Race condition — одновременные запросы на /add при лимите
// (используем свежий агент, не отравленный rate-limit)