From 4b5ccc6a4cb6b230e52aa581a62b385d4d08f636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Fri, 12 Jun 2026 23:04:40 +0400 Subject: [PATCH] =?UTF-8?q?v2:=20fix=20chaos=20test=20=E2=80=94=20CIDR=20?= =?UTF-8?q?=D0=BE=D1=82=2011=20(10.x=20=D0=B7=D0=B0=D0=B1=D0=BB=D0=BE?= =?UTF-8?q?=D0=BA=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD),=20=D0=BF=D0=BE=201?= =?UTF-8?q?0=20=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8E,=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B2=D1=81=D0=B5=D1=85=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- v2/src/config/index.js | 2 +- v2/src/test/index.js | 49 ++++++++++++++++++++++++++++++------------ 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 25a35f1..df8b4f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipwhitelist", - "version": "0.5.88", + "version": "0.5.89", "description": "IP WhiteList microservice for cloud provider", "main": "server.js", "scripts": { diff --git a/v2/src/config/index.js b/v2/src/config/index.js index b018eb6..5c34159 100644 --- a/v2/src/config/index.js +++ b/v2/src/config/index.js @@ -6,7 +6,7 @@ // ═══════════════════════════════════════════════════════════════════════════════ module.exports = { - version: '0.5.88', + version: '0.5.89', iamUrl: process.env.V2_IAM_API_URL || 'https://auth-api.ngcloud.ru', appUrl: process.env.V2_APP_URL || 'https://whitelist.nodejsk8s.services.ngcloud.ru', }; diff --git a/v2/src/test/index.js b/v2/src/test/index.js index d38347c..28ad3cf 100644 --- a/v2/src/test/index.js +++ b/v2/src/test/index.js @@ -93,44 +93,65 @@ function createTestRouter() { // ── GET /chaos — параллельный хаос-тест внутри приложения ──────────── router.get('/chaos', async (req, res) => { - const cids = ['WZ10001','WZ20001','WZ20002','WZ01112','WZ03709']; + const cids = ['WZ10001','WZ20002','WZ30001','WZ01112']; + // Очистка for (const c of cids) { await pool.query('DELETE FROM v2_entries WHERE company_id IN (SELECT id FROM v2_companies WHERE client_id=$1)',[c]).catch(()=>{}); await pool.query('DELETE FROM v2_audit WHERE company_id IN (SELECT id FROM v2_companies WHERE client_id=$1)',[c]).catch(()=>{}); await pool.query('DELETE FROM v2_companies WHERE client_id=$1',[c]).catch(()=>{}); } const emails = ['u1@t.ru', 'u2@t.ru', 'u3@t.ru', 'admin@t.ru']; - const cidMap = { 0:'WZ10001', 1:'WZ20002', 2:'WZ30001', 3:'WZ01112' }; + // CIDR префиксы от 11 (10.x — заблокирован 10.0.0.0/8!) + const cidPrefix = { 0: 11, 1: 12, 2: 13, 3: 14 }; let ok = 0, errors = 0; + const perCompany = 10; // по 10 на компанию (лимит 15) const tasks = []; - for (let i = 0; i < 10; i++) { - const idx = i % 4; + for (let idx = 0; idx < 4; idx++) { const email = emails[idx]; - const clientId = cidMap[idx]; + const clientId = cids[idx]; const impBy = idx === 3 ? 'real@nubes.ru' : null; + const prefix = cidPrefix[idx]; tasks.push((async () => { const co = await q.getOrCreateCompany(clientId, clientId); - for (let j = 0; j < 15; j++) { + for (let j = 0; j < perCompany; j++) { try { - await q.createEntry(co.id, (10+idx)+'.'+i+'.'+j+'.0/24', 'chaos', email, impBy); + await q.createEntry(co.id, prefix + '.0.' + j + '.0/24', 'chaos', email, impBy); ok++; } catch (e) { errors++; } } })()); } await Promise.all(tasks); - const co1 = await q.getOrCreateCompany('WZ10001','WZ10001'); - const entries = await q.listEntries(co1.id); - const cidrs = entries.map(e => e.value_cidr); - const dupes = cidrs.length !== new Set(cidrs).size; - const limit = await q.getLimit(co1); - const audit = await q.getAudit(co1.id); + + // Проверка ВСЕХ компаний + const checks = []; + let totalEntries = 0, totalAudit = 0, anyDupes = false, anyOverLimit = false; + for (const clientId of cids) { + const co = await q.getOrCreateCompany(clientId, clientId); + const entries = await q.listEntries(co.id); + const cidrs = entries.map(e => e.value_cidr); + const dupes = cidrs.length !== new Set(cidrs).size; + const limit = await q.getLimit(co); + const audit = await q.getAudit(co.id); + totalEntries += entries.length; + totalAudit += audit.length; + if (dupes) anyDupes = true; + if (entries.length > limit) anyOverLimit = true; + checks.push({ clientId, entries: entries.length, audit: audit.length, dupes, overLimit: entries.length > limit, limit }); + } + + // Очистка for (const c of cids) { await pool.query('DELETE FROM v2_entries WHERE company_id IN (SELECT id FROM v2_companies WHERE client_id=$1)',[c]).catch(()=>{}); await pool.query('DELETE FROM v2_audit WHERE company_id IN (SELECT id FROM v2_companies WHERE client_id=$1)',[c]).catch(()=>{}); await pool.query('DELETE FROM v2_companies WHERE client_id=$1',[c]).catch(()=>{}); } - res.json({ ok: !dupes && entries.length <= limit, stats: { ok, errors }, checks: { noDupes: !dupes, withinLimit: entries.length <= limit, auditCount: audit.length, wZ10001Entries: entries.length, limit } }); + + res.json({ + ok: !anyDupes && !anyOverLimit && ok === 40, + stats: { ok, errors, totalEntries, totalAudit }, + checks + }); }); return router;