masking: a masked value in a request opens Copy and Never mask
yew_fence on Discord: in Insights › Masking's diff of a request, a false positive can't be copied or put on the allow-list from there. Now a masked value in the request's text, as written here or as the vendor got it, opens the app's row menu (right-click on a value card under it): - Copy copies what the value was, through /api/copy (it is the user's own value, shown on this computer only). - Never mask posts the placeholder to the new POST /api/masking/allow. The server asks the masker for the value it stood for (so only a value masking masked can be added), reads settings with LoadChecked (an unreadable file is not written over), appends it to RedactAllow, the list Settings › Privacy's Never mask saves, and Save trims it and keeps one copy. allows() runs after the span memos, so the next request sends it as written. Off, with why, for a value already on the list and for one of the user's own Masked words. A value from before a restart is not in memory and opens nothing. Strings in plugins/redact/i18n.js for zh, zh-TW, ja and de. settings parity maps the route as S2. Run on mote at this tree rebased on578053d6a(pushed on cde3bc9fa;dca338f3aandcde3bc9fachange internal/gateway and one mover min only): - go test ./internal/gui ./internal/cli ./internal/settings ./internal/redact: ok, but for internal/gui's TestPanelHiddenByWailsMarksPageOutOfSight (#5322, "marked=false" as filed) while another session's suite ran on mote; alone it passes 3 of 3 here and 2 of 2 at578053d6a(TestMaskingAllowFromRecord new: 404 for an unknown placeholder, GET refused, added once, the next TextHits sends it unmasked) - go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet on internal/gui and internal/cli: ok (all of ./... before the rebase); gofmt -l clean - node --test mask-value-menu (new; Chromium and WebKit, en/zh/zh-TW/ja/de, 1100 and 640px, plus the before-a-restart case), mask-actions, masking-records, masking-demo, masking-demo-unblurred, mask-alert, redact-words-import, i18n-en-no-cjk, i18n-keys: 235 of 236, the one red below - i18n-keys: its "a plugin's words are its own" is red for three keys that aren't this change's, filed as #5332/#5327, #5482 and #5426; no key of this change is listed. Broken by hand: the route without its append, TestMaskingAllowFromRecord red ("allow [build-01], saved [build-01]"); maskInk without maskActsOn, mask-value-menu red. Not tried: the real app with a live masked request; the whole GUI suite (1266 files; the new call is made only on a click in this page, and every file that opens the masking page was run). Reported-by: yew_fence
This commit is contained in:
@@ -276,6 +276,7 @@ var notYet = map[string]string{
|
||||
"GET /api/masking/sent": U, // masking.go
|
||||
"GET /api/masking/summary": U, // masking.go
|
||||
"GET /api/masking/value": U, // masking.go
|
||||
"POST /api/masking/allow": S2, // masking.go
|
||||
"POST /api/masking/clear": U, // masking.go
|
||||
"POST /api/masking/preview": U, // masking.go
|
||||
"POST /api/masking/values": U, // masking.go
|
||||
|
||||
@@ -107,6 +107,10 @@ magpie.strings({
|
||||
"Add many words at once, pasted one a line or separated by commas": "一次添加多个词:粘贴进来,每行一个,或用逗号隔开",
|
||||
"Copy the list, one word a line": "复制整个列表,每行一个词",
|
||||
"Words copied: {n}": "已复制 {n} 个词",
|
||||
"Value copied": "已复制这个值",
|
||||
"One of your Masked words": "这是你的脱敏词",
|
||||
"In Never mask already": "已在「从不脱敏」里",
|
||||
"Sent as written from the next request on": "从下一条请求起按原样发送",
|
||||
},
|
||||
"zh-TW": {
|
||||
"Turn on masking": "開啟脫敏",
|
||||
@@ -214,6 +218,10 @@ magpie.strings({
|
||||
"Add many words at once, pasted one a line or separated by commas": "一次新增多個詞:貼上進來,每行一個,或用逗號隔開",
|
||||
"Copy the list, one word a line": "複製整個清單,每行一個詞",
|
||||
"Words copied: {n}": "已複製 {n} 個詞",
|
||||
"Value copied": "已複製這個值",
|
||||
"One of your Masked words": "這是你的脫敏詞",
|
||||
"In Never mask already": "已在「從不脫敏」裡",
|
||||
"Sent as written from the next request on": "從下一則請求起照原樣送出",
|
||||
},
|
||||
ja: {
|
||||
"Turn on masking": "マスクをオンにする",
|
||||
@@ -321,6 +329,10 @@ magpie.strings({
|
||||
"Add many words at once, pasted one a line or separated by commas": "複数の語をまとめて追加:1 行に 1 つ、またはカンマ区切りで貼り付け",
|
||||
"Copy the list, one word a line": "リストをコピー(1 行に 1 語)",
|
||||
"Words copied: {n}": "{n} 語をコピーしました",
|
||||
"Value copied": "値をコピーしました",
|
||||
"One of your Masked words": "マスクする語に登録済みです",
|
||||
"In Never mask already": "「マスクしない」に登録済みです",
|
||||
"Sent as written from the next request on": "次のリクエストからそのまま送信します",
|
||||
},
|
||||
de: {
|
||||
"Turn on masking": "Maskierung einschalten",
|
||||
@@ -428,5 +440,9 @@ magpie.strings({
|
||||
"Add many words at once, pasted one a line or separated by commas": "Viele Wörter auf einmal hinzufügen, eingefügt eines pro Zeile oder durch Kommas getrennt",
|
||||
"Copy the list, one word a line": "Die Liste kopieren, ein Wort pro Zeile",
|
||||
"Words copied: {n}": "Wörter kopiert: {n}",
|
||||
"Value copied": "Wert kopiert",
|
||||
"One of your Masked words": "Eines deiner maskierten Wörter",
|
||||
"In Never mask already": "Steht schon unter Nie maskieren",
|
||||
"Sent as written from the next request on": "Ab der nächsten Anfrage unverändert gesendet",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -817,11 +817,53 @@ function maskInk(into, text, here, o, info) {
|
||||
maskTipOn(mark, { p: m[0], kind: x.k, by: x.b });
|
||||
} else mark = maskPlace("msk-ph", m[0], x);
|
||||
mark.dataset.p = m[0];
|
||||
maskActsOn(mark, x, o);
|
||||
into.append(mark);
|
||||
at = m.index + m[0].length;
|
||||
}
|
||||
into.append(document.createTextNode(text.slice(at)));
|
||||
}
|
||||
// maskActsOn: a value marked in the text, while this magpie still knows
|
||||
// it, opens a menu on a click (or Enter): Copy it, or let it go as
|
||||
// written from now on (yew_fence on Discord: a value masked by mistake
|
||||
// could be neither copied nor let go from here)
|
||||
function maskActsOn(mark, x, o) {
|
||||
if (typeof o.vals.get(x.p) !== "string") return;
|
||||
mark.classList.add("acts");
|
||||
mark.setAttribute("role", "button");
|
||||
mark.setAttribute("aria-haspopup", "menu");
|
||||
mark.onclick = (e) => { e.stopPropagation(); maskValueMenu(mark, x, o); };
|
||||
mark.onkeydown = (e) => {
|
||||
if (e.key !== "Enter" && e.key !== " ") return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
maskValueMenu(mark, x, o);
|
||||
};
|
||||
}
|
||||
// maskValueMenu: Copy puts the value itself on the clipboard; Never mask
|
||||
// adds it to Settings › Privacy's list of that name (/api/masking/allow,
|
||||
// the same list), so the next request sends it as written. A value of
|
||||
// the user's own Masked words, or one in the list already, can't be added.
|
||||
function maskValueMenu(anchor, x, o) {
|
||||
const again = agentMenu?.anchor === anchor;
|
||||
closeAgentMenu();
|
||||
maskTipOff();
|
||||
if (again) return;
|
||||
const v = o.vals.get(x.p);
|
||||
if (typeof v !== "string") return;
|
||||
const s = prefs || state?.settings || {};
|
||||
const had = (s.redactAllow || []).some((a) => a.trim().toLowerCase() === v.trim().toLowerCase());
|
||||
const why = x.b === "word" ? t("One of your Masked words") : had ? t("In Never mask already") : "";
|
||||
openRowMenu(anchor, [
|
||||
{ name: "Copy", icon: COPY_ICON, run: () => copy(v, "", null, t("Value copied")) },
|
||||
{ name: "Never mask", icon: EYE, off: !!why, why, run: () => {
|
||||
writingPrefs(api("masking/allow", { p: x.p }))
|
||||
.then((ns) => { prefs = ns; if (state) state.settings = ns; status(t("Sent as written from the next request on"), "ok"); })
|
||||
.catch((e) => status(t(e.message), "err"));
|
||||
} },
|
||||
]);
|
||||
}
|
||||
|
||||
// the parts of a long text around its placeholders, 120 characters each
|
||||
// side, the rest left out
|
||||
function maskWindows(text, info) {
|
||||
@@ -973,6 +1015,7 @@ function maskHow(r, o, info) {
|
||||
add(t("In the answer"), n ? t(n === 1 ? "Put back 1" : "Put back {n}", { n: fmtN(n) }) : r.blocked ? "—" : memory || r.back ? t("Not named") : t("Not known after a restart"));
|
||||
b.append(top, mid, meta);
|
||||
b.onclick = () => { o.pick = o.pick === x.p ? "" : x.p; drawMaskOne(); };
|
||||
b.oncontextmenu = (e) => { if (typeof o.vals.get(x.p) !== "string") return; e.preventDefault(); maskValueMenu(b, x, o); };
|
||||
aside.append(b);
|
||||
}
|
||||
aside.append(el("p", "msk-note", t("A value itself is in this computer's memory only: shown while it is pointed at or picked, and gone once magpie restarts. The record on disk keeps its kind, length and first characters.")));
|
||||
|
||||
@@ -198,6 +198,7 @@ body.window .msk-onebar::before { inset: -6px calc(var(--bar, 0px) - 16px) -6px
|
||||
.msk-gap { color: var(--faint); }
|
||||
.msk-ph, .msk-orig { --k: var(--accent); padding: 1px 4px; border-radius: 4px; font: inherit; color: var(--fg); background: color-mix(in srgb, var(--k) 16%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--k) 30%, transparent); outline: none; cursor: default; transition: opacity .15s, box-shadow .15s; }
|
||||
.msk-ph:hover, .msk-ph:focus-visible, .msk-orig:hover, .msk-orig:focus-visible { background: color-mix(in srgb, var(--k) 26%, transparent); }
|
||||
.msk-ph.acts, .msk-orig.acts { cursor: pointer; }
|
||||
.msk-orig { background: transparent; box-shadow: inset 0 -1.5px 0 var(--k); border-radius: 2px; }
|
||||
.msk-orig.gone { color: var(--faint); }
|
||||
.msk-one.picking mark[data-p]:not(.lit) { opacity: .4; }
|
||||
|
||||
+40
-1
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/gwmw"
|
||||
"github.com/yetone/magpie/internal/masking"
|
||||
"github.com/yetone/magpie/internal/maskrec"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
// previewMax is how much text the preview masks.
|
||||
@@ -75,8 +76,46 @@ func shownRecord(r maskrec.Record, t gwmw.Teller) maskedRecord {
|
||||
// at once rather than after 30 days (maxyou2090 on Discord);
|
||||
// - POST /api/masking/preview {text} the text as a vendor would get it
|
||||
// under the settings now, and what was found, each told by its kind
|
||||
// and hint, never its value; nothing of it is remembered (#1977).
|
||||
// and hint, never its value; nothing of it is remembered (#1977);
|
||||
// - POST /api/masking/allow {p} adds what a placeholder stood for to
|
||||
// Never mask (settings' RedactAllow, which redact-allow sets whole),
|
||||
// so a value masked by mistake goes as written from the next request
|
||||
// on (yew_fence on Discord). The masker is asked for the value, so
|
||||
// only one it masked is added; 404 once it no longer knows it.
|
||||
func maskingRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("POST /api/masking/allow", func(rw http.ResponseWriter, r *http.Request) {
|
||||
var in struct {
|
||||
P string `json:"p"`
|
||||
}
|
||||
if err := json.NewDecoder(io.LimitReader(r.Body, 1<<16)).Decode(&in); err != nil {
|
||||
fail(rw, err)
|
||||
return
|
||||
}
|
||||
t, ok := teller()
|
||||
if !ok {
|
||||
http.NotFound(rw, r)
|
||||
return
|
||||
}
|
||||
v, ok := t.Value(in.P)
|
||||
if !ok {
|
||||
http.NotFound(rw, r)
|
||||
return
|
||||
}
|
||||
// a settings file that can't be read is unknown, not empty: the
|
||||
// list it holds is never written over with this one value
|
||||
s, err := settings.LoadChecked()
|
||||
if err != nil {
|
||||
fail(rw, err)
|
||||
return
|
||||
}
|
||||
// Save trims the list and keeps each value once, whatever its case
|
||||
s.RedactAllow = append(s.RedactAllow, v)
|
||||
if err := settings.Save(s); err != nil {
|
||||
fail(rw, err)
|
||||
return
|
||||
}
|
||||
writeJSON(rw, settingsState())
|
||||
})
|
||||
mux.HandleFunc("POST /api/masking/preview", func(rw http.ResponseWriter, r *http.Request) {
|
||||
var in struct {
|
||||
Text string `json:"text"`
|
||||
|
||||
@@ -179,3 +179,63 @@ func TestMaskingPreviewKeepsKeyForm(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A value masked by mistake is let go from its request's record
|
||||
// (yew_fence on Discord): what the placeholder stood for joins Never
|
||||
// mask, beside the values already there, once whatever its case, and the
|
||||
// next request sends it as written. A placeholder the masker doesn't know
|
||||
// adds nothing, and a GET changes nothing.
|
||||
func TestMaskingAllowFromRecord(t *testing.T) {
|
||||
const key = "sk-proj-abcdEFGH1234ijklMNOP5678qrst"
|
||||
h := t.TempDir()
|
||||
t.Setenv("HOME", h)
|
||||
t.Setenv("USERPROFILE", h)
|
||||
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
||||
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
||||
if err := settings.Save(settings.Settings{Redact: true, RedactAllow: []string{"build-01"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer gwmw.Mask(masking.Masker{})()
|
||||
m, _ := gwmw.Served()
|
||||
tl := m.(gwmw.Teller)
|
||||
sent, hits := tl.TextHits("my key is " + key)
|
||||
if len(hits) != 1 || strings.Contains(sent, key) {
|
||||
t.Fatalf("masked %q %+v", sent, hits)
|
||||
}
|
||||
p := hits[0].Placeholder
|
||||
srv := webPageHandler(t, webHost{func() {}}, nil)
|
||||
call := func(method, body string) *httptest.ResponseRecorder {
|
||||
rw := httptest.NewRecorder()
|
||||
srv.ServeHTTP(rw, httptest.NewRequest(method, "/api/masking/allow", strings.NewReader(body)))
|
||||
return rw
|
||||
}
|
||||
if rw := call("GET", ""); rw.Code == http.StatusOK {
|
||||
t.Fatalf("GET allow: %d", rw.Code)
|
||||
}
|
||||
if rw := call("POST", `{"p":"{{EMAIL_00000000}}"}`); rw.Code != http.StatusNotFound {
|
||||
t.Fatalf("a placeholder it never made: %d %s", rw.Code, rw.Body)
|
||||
}
|
||||
if got := settings.Load().RedactAllow; len(got) != 1 {
|
||||
t.Fatalf("allow after the unknown one %q", got)
|
||||
}
|
||||
rw := call("POST", `{"p":"`+p+`"}`)
|
||||
var st struct {
|
||||
RedactAllow []string `json:"redactAllow"`
|
||||
}
|
||||
if err := json.Unmarshal(rw.Body.Bytes(), &st); rw.Code != http.StatusOK || err != nil {
|
||||
t.Fatalf("allow: %d %v %s", rw.Code, err, rw.Body)
|
||||
}
|
||||
want := []string{"build-01", key}
|
||||
if strings.Join(st.RedactAllow, "\n") != strings.Join(want, "\n") || strings.Join(settings.Load().RedactAllow, "\n") != strings.Join(want, "\n") {
|
||||
t.Fatalf("allow %q, saved %q", st.RedactAllow, settings.Load().RedactAllow)
|
||||
}
|
||||
// once: again, it is in the list already
|
||||
call("POST", `{"p":"`+p+`"}`)
|
||||
if got := settings.Load().RedactAllow; strings.Join(got, "\n") != strings.Join(want, "\n") {
|
||||
t.Fatalf("allow twice %q", got)
|
||||
}
|
||||
// the next request sends it as written
|
||||
if again, hits := tl.TextHits("my key is " + key); len(hits) != 0 || !strings.Contains(again, key) {
|
||||
t.Fatalf("after allow: %q %+v", again, hits)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// Insights › Masking, a request opened: a masked value in its text, as
|
||||
// written here or as the vendor got it, opens a menu (yew_fence on
|
||||
// Discord): Copy copies what the value was, and Never mask puts it on
|
||||
// Settings › Privacy's Never mask list through /api/masking/allow, so the
|
||||
// next request sends it as written. A value already there, or one of the
|
||||
// user's own Masked words, says why Never mask is off. A value from
|
||||
// before a restart has nothing to copy and opens nothing. A click scrolls
|
||||
// nothing, nothing is left in English, nothing is wider than the window.
|
||||
// Every language, Chromium and WebKit, 1100 and 640px; the API is faked.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const KEY = "{{API_KEY_aaaa1111}}", WORD = "{{WORD_eeee5555}}", NAME = "{{PERSON_bbbb2222}}";
|
||||
const SECRET = "sk-proj-abcdEFGH1234ijkl", NIGHTJAR = "Nightjar";
|
||||
const K1 = "1792987654321000001", K2 = "1792987654321000002";
|
||||
const ago = (ms) => new Date(Date.now() - ms).toISOString();
|
||||
const SENT = JSON.stringify({ model: "claude-opus-4-1", messages: [
|
||||
{ role: "user", content: [{ type: "text", text: `export OPENAI_API_KEY=${KEY} # project ${WORD}` }] },
|
||||
] });
|
||||
const records = [
|
||||
{ key: K2, t: ago(120e3), route: "messages", what: "chat", agent: "claude", provider: "anthropic", model: "claude-opus-4-1", n: 2, took: 1800,
|
||||
values: [{ p: KEY, k: "API_KEY", b: "rule", h: "sk-p", l: 24, n: 1, known: true }, { p: WORD, k: "WORD", b: "word", h: "N", l: 8, n: 1, known: true }],
|
||||
snips: { [KEY]: `export OPENAI_API_KEY=${KEY}`, [WORD]: `# project ${WORD}` } },
|
||||
// from before a restart: no values in memory
|
||||
{ key: K1, t: ago(300e3), route: "search", what: "search", agent: "codex", provider: "openai", model: "gpt-5", n: 1,
|
||||
values: [{ p: NAME, k: "PERSON", b: "model", h: "", l: 3, n: 1 }], snips: { [NAME]: `ask ${NAME} about it` } },
|
||||
];
|
||||
|
||||
function serve(lang, asked) {
|
||||
const settings = { theme: "light", lang, tray: "panel", currency: "usd", redact: true, redactPersonal: false, redactWords: [NIGHTJAR], redactAllow: ["build-01"] };
|
||||
return async (route) => {
|
||||
const req = route.request(), url = new URL(req.url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [{ id: "claude", name: "Claude Code", icon: "claudecode-color", fields: [] }], profiles: [], settings });
|
||||
if (url.pathname === "/api/settings") return json(settings);
|
||||
if (url.pathname === "/api/copy") { asked.push("copy " + JSON.parse(req.postData()).text); return route.fulfill({ status: 204, body: "" }); }
|
||||
if (url.pathname === "/api/masking/allow") {
|
||||
const p = JSON.parse(req.postData()).p;
|
||||
asked.push("allow " + p);
|
||||
if (p !== KEY) return route.fulfill({ status: 404, body: "404 page not found" });
|
||||
settings.redactAllow = [...settings.redactAllow, SECRET];
|
||||
return json(settings);
|
||||
}
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, mine: true, url: "http://127.0.0.1:3999", models: 0, groups: [], calls: [] } });
|
||||
if (url.pathname === "/api/masking/summary") return json({ days: [], requests: 2, n: 3, distinct: 3, blocked: 0, hours: [], kinds: [{ name: "API_KEY", n: 1, distinct: 1 }], by: { rule: 1 }, agents: [], providers: [], values: [], since: ago(7 * 86400e3) });
|
||||
if (url.pathname === "/api/masking/records") return json({ records, more: false });
|
||||
if (url.pathname === "/api/masking/record") {
|
||||
const r = records.find((r) => r.key === url.searchParams.get("key"));
|
||||
return r ? json(r) : route.fulfill({ status: 404, body: "404 page not found" });
|
||||
}
|
||||
if (url.pathname === "/api/masking/sent") return url.searchParams.get("key") === K2 ? json({ body: SENT }) : route.fulfill({ status: 404, body: "404 page not found" });
|
||||
if (url.pathname === "/api/masking/values") {
|
||||
const known = { [KEY]: SECRET, [WORD]: NIGHTJAR };
|
||||
const ps = JSON.parse(req.postData()).ps;
|
||||
return json({ values: Object.fromEntries(ps.filter((p) => known[p]).map((p) => [p, known[p]])) });
|
||||
}
|
||||
if (url.pathname === "/api/masking/value") return url.searchParams.get("p") === KEY ? json({ value: SECRET }) : route.fulfill({ status: 404, body: "404 page not found" });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
||||
};
|
||||
}
|
||||
|
||||
async function until(ok, ms = 8000) {
|
||||
for (const end = Date.now() + ms; !ok();) {
|
||||
if (Date.now() > end) throw new Error("never happened: " + ok);
|
||||
await new Promise((r) => setTimeout(r, 25));
|
||||
}
|
||||
}
|
||||
const scrolled = (page) => page.evaluate(() => [scrollX, scrollY, document.querySelector("#view-masking").scrollTop, document.querySelector("main, .main, #main")?.scrollTop ?? 0]);
|
||||
async function stillClick(page, loc) {
|
||||
await loc.scrollIntoViewIfNeeded();
|
||||
const before = await scrolled(page);
|
||||
await loc.click();
|
||||
await page.waitForTimeout(100);
|
||||
assert.deepEqual(await scrolled(page), before, "no click moved the page");
|
||||
}
|
||||
const wide = (page) => page.evaluate(() => {
|
||||
const over = [...document.querySelectorAll("#view-masking *, .row-menu, .row-menu *")].filter((n) => n.getClientRects().length && n.getBoundingClientRect().right > innerWidth + 1 && !n.closest(".msk-text, .msk-same")).map((n) => n.className?.baseVal ?? n.className);
|
||||
return { page: document.documentElement.scrollWidth > document.documentElement.clientWidth, over };
|
||||
});
|
||||
const english = ["Copy", "Never mask", "Value copied", "One of your Masked words", "In Never mask already", "Sent as written from the next request on"];
|
||||
async function untranslated(page, lang, where) {
|
||||
if (lang === "en") return;
|
||||
const said = await page.locator(where).innerText();
|
||||
for (const w of english) assert(!said.includes(w), `${w} left in English: ${said}`);
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
||||
for (const width of [1100, 640]) {
|
||||
test(`${engine} ${lang} ${width}px: a masked value in a request's text copies, and goes on Never mask`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 1000 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(8000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [], asked = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, asked));
|
||||
await page.goto("http://magpie.test/?view=masking");
|
||||
await page.locator("#maskList .msk-row").first().waitFor();
|
||||
await page.locator("#maskList .msk-row").first().click();
|
||||
const one = page.locator("#maskOne");
|
||||
await one.locator(".msk-msg").first().waitFor();
|
||||
const here = one.locator(".msk-msg .msk-text").first().locator("mark"), sent = one.locator(".msk-msg .msk-text").last().locator("mark");
|
||||
await here.first().waitFor();
|
||||
assert.equal(await one.locator("mark.acts").count(), 4, "each value, in both columns, opens a menu");
|
||||
assert.equal(await here.first().getAttribute("aria-haspopup"), "menu");
|
||||
|
||||
// as written here: Copy copies the value
|
||||
const menu = page.locator(".row-menu");
|
||||
await stillClick(page, here.first());
|
||||
await menu.waitFor();
|
||||
assert.equal(await menu.locator(".rm-item").count(), 2);
|
||||
assert.equal(await menu.locator(".rm-item:disabled").count(), 0, "a key not on the list yet");
|
||||
await untranslated(page, lang, ".row-menu");
|
||||
assert.deepEqual(await wide(page), { page: false, over: [] });
|
||||
await stillClick(page, menu.locator(".rm-item").first());
|
||||
await until(() => asked.includes("copy " + SECRET));
|
||||
assert.equal(await menu.count(), 0, "the menu closes");
|
||||
await page.waitForFunction(() => document.querySelector("#status")?.classList.contains("ok"));
|
||||
await untranslated(page, lang, "#status");
|
||||
|
||||
// as the vendor got it: Never mask asks the server, by placeholder
|
||||
await stillClick(page, sent.first());
|
||||
await menu.waitFor();
|
||||
await stillClick(page, menu.locator(".rm-item").nth(1));
|
||||
await until(() => asked.includes("allow " + KEY));
|
||||
await page.waitForFunction((s) => document.querySelector("#status")?.textContent && !document.querySelector("#status").textContent.includes(s), "copied");
|
||||
if (lang === "en") await page.waitForFunction(() => document.querySelector("#status").textContent === "Sent as written from the next request on");
|
||||
await untranslated(page, lang, "#status");
|
||||
assert.equal(asked.filter((a) => a.startsWith("allow")).length, 1);
|
||||
|
||||
// once on the list, Never mask is off and says why
|
||||
await stillClick(page, here.first());
|
||||
await menu.waitFor();
|
||||
assert.equal(await menu.locator(".rm-item:disabled").count(), 1);
|
||||
if (lang === "en") assert.match(await menu.locator(".rm-item:disabled").innerText(), /In Never mask already/);
|
||||
await untranslated(page, lang, ".row-menu");
|
||||
// the same value clicked again closes its menu
|
||||
await stillClick(page, here.first());
|
||||
assert.equal(await menu.count(), 0);
|
||||
|
||||
// one of the user's Masked words: Copy, but Never mask is off
|
||||
await stillClick(page, sent.nth(1));
|
||||
await menu.waitFor();
|
||||
assert.equal(await menu.locator(".rm-item:disabled").count(), 1);
|
||||
if (lang === "en") assert.match(await menu.locator(".rm-item:disabled").innerText(), /One of your Masked words/);
|
||||
await untranslated(page, lang, ".row-menu");
|
||||
assert.deepEqual(await wide(page), { page: false, over: [] });
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await menu.count(), 0);
|
||||
assert.equal(asked.filter((a) => a.startsWith("allow")).length, 1, "nothing more was put on the list");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
test(`${engine}: a value from before a restart opens nothing`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const page = await (await browser.newContext({ viewport: { width: 640, height: 1000 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(8000);
|
||||
const errors = [], asked = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve("en", asked));
|
||||
await page.goto("http://magpie.test/?view=masking");
|
||||
await page.locator("#maskList .msk-row").nth(1).waitFor();
|
||||
await page.locator("#maskList .msk-row").nth(1).click();
|
||||
const one = page.locator("#maskOne");
|
||||
await one.locator(".msk-gone").waitFor();
|
||||
assert.equal(await one.locator("mark.acts").count(), 0);
|
||||
await one.locator("mark").first().click();
|
||||
await page.waitForTimeout(100);
|
||||
assert.equal(await page.locator(".row-menu").count(), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user