From 0925ae4fd8013155462e39867d95234be6085896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Fri, 12 Jun 2026 22:56:57 +0400 Subject: [PATCH] =?UTF-8?q?v2:=20/v2/test/chaos=20=E2=80=94=20=D0=BF=D0=B0?= =?UTF-8?q?=D1=80=D0=B0=D0=BB=D0=BB=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20?= =?UTF-8?q?=D1=85=D0=B0=D0=BE=D1=81-=D1=82=D0=B5=D1=81=D1=82=20=D0=B2?= =?UTF-8?q?=D0=BD=D1=83=D1=82=D1=80=D0=B8=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20(Promise.all)?= 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 | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9c2d45d..632baca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipwhitelist", - "version": "0.5.86", + "version": "0.5.87", "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 81033e2..fcedce1 100644 --- a/v2/src/config/index.js +++ b/v2/src/config/index.js @@ -6,7 +6,7 @@ // ═══════════════════════════════════════════════════════════════════════════════ module.exports = { - version: '0.5.86', + version: '0.5.87', 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 e2b3d9c..d38347c 100644 --- a/v2/src/test/index.js +++ b/v2/src/test/index.js @@ -91,6 +91,48 @@ function createTestRouter() { } }); + // ── GET /chaos — параллельный хаос-тест внутри приложения ──────────── + router.get('/chaos', async (req, res) => { + const cids = ['WZ10001','WZ20001','WZ20002','WZ01112','WZ03709']; + 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' }; + let ok = 0, errors = 0; + const tasks = []; + for (let i = 0; i < 10; i++) { + const idx = i % 4; + const email = emails[idx]; + const clientId = cidMap[idx]; + const impBy = idx === 3 ? 'real@nubes.ru' : null; + tasks.push((async () => { + const co = await q.getOrCreateCompany(clientId, clientId); + for (let j = 0; j < 15; j++) { + try { + await q.createEntry(co.id, (10+idx)+'.'+i+'.'+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); + 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 } }); + }); + return router; }