|
| 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 | +}); |
0 commit comments