Public: anyone can read this; the crew can change it.
A test proves the terminal's trusted hosts prompt: only a forge admin is offered it, a save is audited and live at once, a bad host is refused in the page's words #7609
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/7592-a-test-proves-the-terminal-s-trusted-hos → main 2 commits fork 1 thread · 1 unresolved
1 file
changed +8
−2
test/trusted-hosts-ui.test.ts +8 −2
| @@ -9,7 +9,7 @@ import { resolveSource } from "../src/actions/migrate.ts"; | ||
| 9 | 9 | import { createOrigin } from "../src/core/origins.ts"; |
| 10 | 10 | import { createUser, getUserByName } from "../src/core/users.ts"; |
| 11 | 11 | import { serve, type Servers } from "../src/http/server.ts"; |
| 12 | import { loadTrustedHosts, parseHosts, trustedHosts } from "../src/origins/trusted-hosts.ts"; | |
| 12 | import { loadTrustedHosts, parseHosts, rejectedSentence, trustedHosts } from "../src/origins/trusted-hosts.ts"; | |
| 13 | 13 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 14 | 14 | import type { TuiIdentity } from "../src/tui/session.ts"; |
| 15 | 15 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; |
| @@ -167,9 +167,12 @@ describe("trusted internal hosts", () => { | ||
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | test("a non-admin is not offered it", async () => { |
| 170 | const before = changes(); | |
| 170 | 171 | const h = boot("bob"); |
| 171 | 172 | await h.palette(); |
| 172 | 173 | expect(h.text()).not.toContain("internal hosts an origin may reach"); |
| 174 | expect(trustedHosts()).toEqual(["git.internal.test"]); | |
| 175 | expect(changes()).toEqual(before); | |
| 173 | 176 | h.stop(); |
| 174 | 177 | }); |
| 175 | 178 | |
| @@ -181,12 +184,13 @@ describe("trusted internal hosts", () => { | ||
| 181 | 184 | expect(h.text()).toContain("git.internal.test"); |
| 182 | 185 | await h.type(" 10.1.1.1"); |
| 183 | 186 | await h.enter(); |
| 184 | expect(h.text()).toContain("Not host names"); | |
| 187 | expect(h.text()).toContain(rejectedSentence(parseHosts("10.1.1.1").rejected).slice(0, 40)); | |
| 185 | 188 | expect(trustedHosts()).toEqual(["git.internal.test"]); |
| 186 | 189 | h.stop(); |
| 187 | 190 | }); |
| 188 | 191 | |
| 189 | 192 | test("an admin saves from the terminal: live and audited", async () => { |
| 193 | const before = changes().length; | |
| 190 | 194 | const h = boot("alice"); |
| 191 | 195 | await h.palette(); |
| 192 | 196 | await h.enter(); |
| @@ -194,6 +198,8 @@ describe("trusted internal hosts", () => { | ||
| 194 | 198 | await h.enter(); |
| 195 | 199 | expect(trustedHosts().sort()).toEqual(["git.internal.test", "second.test"]); |
| 196 | 200 | expect(changes().at(-1)).toBe('["git.internal.test","second.test"]'); |
| 201 | expect(changes()).toHaveLength(before + 1); | |
| 202 | expect(h.text()).toContain("Trusted: git.internal.test, second.test."); | |
| 197 | 203 | h.stop(); |
| 198 | 204 | }); |
| 199 | 205 | }); |
new above
offline