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);