From 5a2afac0cc57c931e8d7cbd196ee229b4c7019dc Mon Sep 17 00:00:00 2001 From: Peppa Date: Wed, 18 Nov 2026 17:17:26 +0500 Subject: [PATCH] =?UTF-8?q?DIK-24:=20=D0=BF=D0=BE=D0=BD=D1=8F=D1=82=D0=BD?= =?UTF-8?q?=D0=BE=D0=B5=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=BE-=D1=80=D1=83=D1=81=D1=81=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=20=D0=BD=D0=B5=D0=B2=D0=B5=D1=80=D0=BD=D0=BE?= =?UTF-8?q?=D0=BC=20=D0=B8=D0=BB=D0=B8=20=D0=BF=D1=83=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D0=BC=20=D0=BF=D0=B0=D1=80=D0=BE=D0=BB=D0=B5=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D0=B5=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5.5 --- openspec/specs/offers-freshness/spec.md | 1 + src/index.js | 4 +++- test/fresh.test.js | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/openspec/specs/offers-freshness/spec.md b/openspec/specs/offers-freshness/spec.md index 75fa2a2..ad6e3bc 100644 --- a/openspec/specs/offers-freshness/spec.md +++ b/openspec/specs/offers-freshness/spec.md @@ -47,6 +47,7 @@ TBD - created by archiving change dik-3-fresh-offers. Update Purpose after archi - **GIVEN** задан пароль владельца - **WHEN** кто-то открывает страницу правки без пароля или с чужим - **THEN** доступ не даётся и данные не показываются +- **AND** сообщение по-русски объясняет: пароль не введён или неверен, и что делать #### Scenario: Пароль не задан - **GIVEN** пароль владельца не задан diff --git a/src/index.js b/src/index.js index e816892..abfaac3 100644 --- a/src/index.js +++ b/src/index.js @@ -27,7 +27,9 @@ function admin(req, res, url, store, password, json) { } if (!checkPassword(req.headers.authorization, password)) { res.writeHead(401, { "www-authenticate": 'Basic realm="admin", charset="UTF-8"', "content-type": "text/plain; charset=utf-8" }); - return res.end("Нужен пароль"); + return res.end(req.headers.authorization + ? "Пароль неверный. Проверьте пароль и попробуйте ещё раз — обновите страницу и введите его снова." + : "Чтобы править данные, нужен пароль владельца. Обновите страницу и введите его."); } if (url.pathname === "/admin" && req.method === "GET") { res.writeHead(200, { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" }); diff --git a/test/fresh.test.js b/test/fresh.test.js index 4ca2dec..3732387 100644 --- a/test/fresh.test.js +++ b/test/fresh.test.js @@ -95,7 +95,12 @@ test("Сценарий: пароль не задан / неверный / вер const r = await fetch(b + "/admin"); assert.equal(r.status, 503); }); await withServer({ dataDir: tmpBase(), password: "s3cret" }, async (b) => { - assert.equal((await fetch(b + "/admin")).status, 401); + const noPass = await fetch(b + "/admin"); + assert.equal(noPass.status, 401); + assert.match(await noPass.text(), /нужен пароль владельца/); + const bad = await fetch(b + "/admin", { headers: { authorization: "Basic " + Buffer.from("o:wrong").toString("base64") } }); + assert.equal(bad.status, 401); + assert.match(await bad.text(), /Пароль неверный/); assert.equal((await fetch(b + "/admin/api/venues")).status, 401); const auth = { authorization: "Basic " + Buffer.from("o:s3cret").toString("base64") }; assert.equal((await fetch(b + "/admin", { headers: auth })).status, 200);