DIK-24: понятное сообщение по-русски при неверном или пустом пароле на странице правки

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Peppa 2026-11-18 17:17:26 +05:00
parent eff969602d
commit 5a2afac0cc
3 changed files with 10 additions and 2 deletions

View File

@ -47,6 +47,7 @@ TBD - created by archiving change dik-3-fresh-offers. Update Purpose after archi
- **GIVEN** задан пароль владельца
- **WHEN** кто-то открывает страницу правки без пароля или с чужим
- **THEN** доступ не даётся и данные не показываются
- **AND** сообщение по-русски объясняет: пароль не введён или неверен, и что делать
#### Scenario: Пароль не задан
- **GIVEN** пароль владельца не задан

View File

@ -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" });

View File

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