Skip to content

Commit 147ada9

Browse files
authored
Merge pull request #176 from ryana/feat/mask-token-fields
2 parents 1eee24a + e121b6a commit 147ada9

3 files changed

Lines changed: 60 additions & 8 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { describe, expect, it } from "bun:test";
2+
import { join } from "node:path";
3+
4+
function findInputBlock(markup: string, inputId: string): string | undefined {
5+
const inputBlocks = markup.match(/<Input\b[\s\S]*?\/>/g) ?? [];
6+
return inputBlocks.find((block) => block.includes(`id="${inputId}"`));
7+
}
8+
9+
async function readWorkspaceSettingsMarkup(relativePath: string): Promise<string> {
10+
const absolutePath = join(process.cwd(), relativePath);
11+
return Bun.file(absolutePath).text();
12+
}
13+
14+
describe("web-ui credential fields", () => {
15+
it("masks token fields in add workspace dialog", async () => {
16+
const markup = await readWorkspaceSettingsMarkup("packages/web-ui/src/routes/(settings)/+layout.svelte");
17+
18+
for (const inputId of [
19+
"new-workspace-app-token",
20+
"new-workspace-bot-token",
21+
"new-workspace-discord-bot-token",
22+
"new-workspace-lark-app-secret",
23+
]) {
24+
const block = findInputBlock(markup, inputId);
25+
expect(block).toBeDefined();
26+
expect(block).toContain('type="password"');
27+
}
28+
});
29+
30+
it("masks token fields in workspace detail editor", async () => {
31+
const markup = await readWorkspaceSettingsMarkup("packages/web-ui/src/routes/(settings)/workspace/[workspaceName]/+page.svelte");
32+
33+
for (const inputId of [
34+
"workspace-app-token",
35+
"workspace-bot-token",
36+
"workspace-discord-bot-token",
37+
"workspace-lark-app-secret",
38+
]) {
39+
const block = findInputBlock(markup, inputId);
40+
expect(block).toBeDefined();
41+
expect(block).toContain('type="password"');
42+
}
43+
});
44+
});

packages/web-ui/src/routes/(settings)/+layout.svelte

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,19 +306,21 @@
306306
<Label for="new-workspace-app-token">Slack App Token</Label>
307307
<Input
308308
id="new-workspace-app-token"
309-
type="text"
309+
type="password"
310310
value={pendingSlackAppToken}
311311
on:input={onPendingSlackAppTokenInput}
312+
autocomplete="new-password"
312313
placeholder="xapp-..."
313314
/>
314315
</div>
315316
<div class="grid gap-2">
316317
<Label for="new-workspace-bot-token">Slack Bot Token</Label>
317318
<Input
318319
id="new-workspace-bot-token"
319-
type="text"
320+
type="password"
320321
value={pendingSlackBotToken}
321322
on:input={onPendingSlackBotTokenInput}
323+
autocomplete="new-password"
322324
placeholder="xoxb-..."
323325
/>
324326
</div>
@@ -327,9 +329,10 @@
327329
<Label for="new-workspace-discord-bot-token">Discord Bot Token</Label>
328330
<Input
329331
id="new-workspace-discord-bot-token"
330-
type="text"
332+
type="password"
331333
value={pendingDiscordBotToken}
332334
on:input={onPendingDiscordBotTokenInput}
335+
autocomplete="new-password"
333336
placeholder="Bot token"
334337
/>
335338
</div>
@@ -349,9 +352,10 @@
349352
<Label for="new-workspace-lark-app-secret">Lark App Secret</Label>
350353
<Input
351354
id="new-workspace-lark-app-secret"
352-
type="text"
355+
type="password"
353356
value={pendingLarkAppSecret}
354357
on:input={onPendingLarkAppSecretInput}
358+
autocomplete="new-password"
355359
placeholder="app secret"
356360
/>
357361
</div>

packages/web-ui/src/routes/(settings)/workspace/[workspaceName]/+page.svelte

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,29 +372,32 @@
372372
<Label for="workspace-app-token">Slack App Token</Label>
373373
<Input
374374
id="workspace-app-token"
375-
type="text"
375+
type="password"
376376
value={selectedWorkspace.slackAppToken ?? ""}
377377
on:input={(event) => onWorkspaceTextInput(selectedWorkspace.id, "slackAppToken", event)}
378+
autocomplete="new-password"
378379
/>
379380
</div>
380381

381382
<div class="grid gap-2">
382383
<Label for="workspace-bot-token">Slack Bot Token</Label>
383384
<Input
384385
id="workspace-bot-token"
385-
type="text"
386+
type="password"
386387
value={selectedWorkspace.slackBotToken ?? ""}
387388
on:input={(event) => onWorkspaceTextInput(selectedWorkspace.id, "slackBotToken", event)}
389+
autocomplete="new-password"
388390
/>
389391
</div>
390392
{:else if selectedWorkspace.type === "discord"}
391393
<div class="grid gap-2 md:col-span-2">
392394
<Label for="workspace-discord-bot-token">Discord Bot Token</Label>
393395
<Input
394396
id="workspace-discord-bot-token"
395-
type="text"
397+
type="password"
396398
value={selectedWorkspace.discordBotToken ?? ""}
397399
on:input={(event) => onWorkspaceTextInput(selectedWorkspace.id, "discordBotToken", event)}
400+
autocomplete="new-password"
398401
/>
399402
</div>
400403
{:else}
@@ -412,9 +415,10 @@
412415
<Label for="workspace-lark-app-secret">Lark App Secret</Label>
413416
<Input
414417
id="workspace-lark-app-secret"
415-
type="text"
418+
type="password"
416419
value={selectedWorkspace.larkAppSecret ?? ""}
417420
on:input={(event) => onWorkspaceTextInput(selectedWorkspace.id, "larkAppSecret", event)}
421+
autocomplete="new-password"
418422
/>
419423
</div>
420424
{/if}

0 commit comments

Comments
 (0)