From 3a610becd10db0646c800b239f534fbc28aaab8f Mon Sep 17 00:00:00 2001 From: DanliaQwerty20 Date: Mon, 7 Sep 2026 20:59:20 +0300 Subject: [PATCH] test: protect calendar acceptance api --- AGENTS.md | 1 + README.md | 3 ++- scripts/check.ps1 | 2 +- scripts/run-calendar.ps1 | 2 ++ tests/calendar-event.js | 2 ++ 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 3fe8e36..cdadc77 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -11,6 +11,7 @@ - цель теста приходит через переменную, настоящий production запрещён; - chaos выключен по умолчанию и требует отдельную метку namespace; - тест обязан иметь понятный порог успеха; +- секреты test API передаются только переменными окружения и не хранятся в Git; - документация на русском, имена в коде — простой английский. ## Команды diff --git a/README.md b/README.md index ba78da9..de37899 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,9 @@ pwsh ./scripts/run-load.ps1 ```powershell $env:ACTION_TOKEN = "" +$env:CALENDAR_TEST_API_KEY = "<тот же локальный секрет, что у Calendar MCP>" pwsh ./scripts/run-calendar.ps1 ``` Скрипт принимает только локальные HTTP-адреса. Проверочный API `fake-calendar` доступен только в -тестовом режиме. +тестовом режиме и требует отдельный `X-Test-Key`; секрет не хранится в Git. diff --git a/scripts/check.ps1 b/scripts/check.ps1 index 2a9b8d0..c65fbd4 100644 --- a/scripts/check.ps1 +++ b/scripts/check.ps1 @@ -10,7 +10,7 @@ foreach ($required in @("TARGET_URL", "thresholds", "http_req_failed", "http_req if ($script -notmatch $required) { throw "В k6-тесте нет $required." } } $calendarScript = Get-Content tests/calendar-event.js -Raw -foreach ($required in @("AWAITING_APPROVAL", "SUCCEEDED", "payloadHash", "requestKey", "result?.eventId", "http_req_failed")) { +foreach ($required in @("AWAITING_APPROVAL", "SUCCEEDED", "payloadHash", "requestKey", "result?.eventId", "http_req_failed", "CALENDAR_TEST_API_KEY", "X-Test-Key")) { if ($calendarScript -notmatch [regex]::Escape($required)) { throw "В calendar acceptance-тесте нет $required." } } Write-Host "Быстрые проверки test-lab прошли." diff --git a/scripts/run-calendar.ps1 b/scripts/run-calendar.ps1 index 86474b5..9c8f32a 100644 --- a/scripts/run-calendar.ps1 +++ b/scripts/run-calendar.ps1 @@ -13,6 +13,7 @@ foreach ($url in @($AgentUrl, $ActionUrl, $CalendarTestUrl)) { } } if (-not $env:ACTION_TOKEN) { throw "Укажи ACTION_TOKEN с JWT тестового пользователя." } +if (-not $env:CALENDAR_TEST_API_KEY) { throw "Укажи CALENDAR_TEST_API_KEY локального Calendar MCP." } $parts = $env:ACTION_TOKEN.Split('.') if ($parts.Count -ne 3) { throw "ACTION_TOKEN не похож на JWT." } $payload = $parts[1].Replace('-', '+').Replace('_', '/') @@ -32,6 +33,7 @@ if (-not $claims.sub -or -not $claims.tenant_id) { --env "AGENT_URL=$AgentUrl" ` --env "ACTION_URL=$ActionUrl" ` --env "CALENDAR_TEST_URL=$CalendarTestUrl" ` + --env "CALENDAR_TEST_API_KEY=$env:CALENDAR_TEST_API_KEY" ` --env "ACTION_TOKEN=$env:ACTION_TOKEN" ` --env "TEST_TENANT_ID=$($claims.tenant_id)" ` --env "TEST_ACTOR_ID=$($claims.sub)" ` diff --git a/tests/calendar-event.js b/tests/calendar-event.js index 9903f68..38f0ed2 100644 --- a/tests/calendar-event.js +++ b/tests/calendar-event.js @@ -4,6 +4,7 @@ import { check, fail, sleep } from 'k6'; const agentUrl = requiredUrl('AGENT_URL'); const actionUrl = requiredUrl('ACTION_URL'); const calendarTestUrl = requiredUrl('CALENDAR_TEST_URL'); +const calendarTestKey = required('CALENDAR_TEST_API_KEY'); const actionToken = required('ACTION_TOKEN'); const tenantId = required('TEST_TENANT_ID'); const actorId = required('TEST_ACTOR_ID'); @@ -135,6 +136,7 @@ function waitForDone(actionId) { function findEvents(requestKey) { const response = http.get( `${calendarTestUrl}/test/events?requestKey=${encodeURIComponent(requestKey)}`, + { headers: { 'X-Test-Key': calendarTestKey } }, ); expectStatus(response, 200, 'fake-calendar test API is not available'); return response.json().events;