Public: anyone can read this; the crew can change it.
A signed-out visitor who taps Make it yours signs up and lands on their own fork, not on the home page #16616
Check · Review · Land · Live — Its check is red.
scout/forge:scout/16304-a-signed-out-visitor-who-taps-make-it-yo → main 4 commits fork 2 threads · 2 unresolved
11 files
changed +135
−21
- src/web/chrome.ts
- src/web/pages/first_steps.ts
- src/web/studio/app.ts
- src/web/studio/make_it_yours.ts
- src/web/studio/yours_button.ts
- test/explore-fork.test.ts
- test/explore.test.ts
- test/explorer-make-it-yours.test.ts
- test/friend-journey.test.ts
- test/guest-contribute.test.ts
- test/make-it-yours-button.test.ts
src/web/chrome.ts +12 −1
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | |
| 11 | 11 | import { togetherHtml } from "./together.ts"; |
| 12 | 12 | import { repoOnRequest } from "../http/request_repo.ts"; |
| 13 | import { hereAddress, returnTo, withReturn } from "./return_to.ts"; | |
| 13 | import { hereAddress, returnTo, safeNext, withReturn } from "./return_to.ts"; | |
| 14 | 14 | import { MACHINE_PREFIX, typedMiss } from "../http/asset_miss.ts"; |
| 15 | 15 | import { audienceFacts, audienceOf } from "../core/audience.ts"; |
| 16 | 16 | import { activeEdgeToken, edgeLoginUrl, edgeStrangerLogin } from "../http/edge.ts"; |
| @@ -205,6 +205,17 @@ export function signInHref(ctx: Ctx, next: string = hereAddress(ctx)): string { | ||
| 205 | 205 | return `/signin?next=${encodeURIComponent(next)}`; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | /** | |
| 209 | * Where a signed-out visitor who tapped "Make it yours" starts: sign-up carrying the app's page | |
| 210 | * (`next`, a path on this forge, checked again by the door), or the usual sign-in where the | |
| 211 | * forge offers no sign-up. Coming back, the page makes the copy once; a copy that exists is opened. | |
| 212 | */ | |
| 213 | export function signUpHref(ctx: Ctx, next: string): string { | |
| 214 | const safe = safeNext(next); | |
| 215 | if (safe === undefined || !offersSignup(ctx) || activeEdgeToken(ctx.app) !== undefined) return signInHref(ctx, safe ?? "/"); | |
| 216 | return withReturn("/signup", safe); | |
| 217 | } | |
| 218 | ||
| 208 | 219 | /** |
| 209 | 220 | * Whether a signed-out visitor is offered Create an account beside Sign in. |
| 210 | 221 | * Behind a platform edge the edge is the one way in, unless it has vouched |
src/web/pages/first_steps.ts +2 −2
| @@ -29,9 +29,9 @@ export function firstRunHtml(run: FirstRun): Html { | ||
| 29 | 29 | /** |
| 30 | 30 | * The crew now, then the undone steps under one fixed heading; the crew block appears here only. |
| 31 | 31 | */ |
| 32 | export function firstSteps(ctx: Ctx, steps: readonly NextStep[]): Html { | |
| 32 | export function firstSteps(ctx: Ctx, steps: readonly NextStep[], hrefs: Partial<Record<StepKey, string>> = {}): Html { | |
| 33 | 33 | const todo = steps.filter((s) => !s.done); |
| 34 | 34 | return html`${crewNowHtml(crewNow(ctx.app.db))} |
| 35 | 35 | <section id="first-steps" class="mt" aria-label="${FIRST_STEPS_HEADING}"><h2 class="small">${FIRST_STEPS_HEADING}</h2> |
| 36 | ${listCard(todo.map((s) => row({ href: STEP_HREF[s.key], title: html`${STEP_TITLES[s.key]}`, data: { "first-step": s.key } })))}</section>`; | |
| 36 | ${listCard(todo.map((s) => row({ href: hrefs[s.key] ?? STEP_HREF[s.key], title: html`${STEP_TITLES[s.key]}`, data: { "first-step": s.key } })))}</section>`; | |
| 37 | 37 | } |
src/web/studio/app.ts +9 −1
| @@ -79,7 +79,8 @@ import { | ||
| 79 | 79 | timePhase, |
| 80 | 80 | timePhaseAsync, |
| 81 | 81 | } from "../../core/route_timing.ts"; |
| 82 | import { noteAppOpened } from "../../core/next-steps.ts"; | |
| 82 | import { firstSteps } from "../pages/first_steps.ts"; | |
| 83 | import { STEP_TITLES, noteAppOpened } from "../../core/next-steps.ts"; | |
| 83 | 84 | import { mayReadStatement } from "../../actions/statement.ts"; |
| 84 | 85 | import { appPicture } from "../../flow/pages.ts"; |
| 85 | 86 | import { moneyRows } from "./money_line.ts"; |
| @@ -506,6 +507,11 @@ export async function studioApp( | ||
| 506 | 507 | const migration = await timePhaseAsync(req, "migration", () => migrationRegion(ctx, repo, ownerFacts)); |
| 507 | 508 | const schedules = ownerFacts ? html`${schedulesCard(ctx, repo)}${jobsLink(ctx, repo)}` : null; |
| 508 | 509 | const rendering = performance.now(); |
| 510 | // A copy just made from sign-up (`?welcome=1`) shows its owner what to do first: tell the crew. | |
| 511 | const welcome = | |
| 512 | ctx.url.searchParams.get("welcome") === "1" && ctx.auth.user?.id === repo.ownerId | |
| 513 | ? firstSteps(ctx, [{ key: "tell", title: STEP_TITLES.tell, done: false }], { tell: "#tell" }) | |
| 514 | : null; | |
| 509 | 515 | const tellRegion = html`${tell} |
| 510 | 516 | ${ownerFacts && ctx.auth.user ? answersRegion(ctx, repo, ctx.auth.user) : null}`; |
| 511 | 517 | // A new app that has not run yet shows only its progress: the head's |
| @@ -518,6 +524,7 @@ export async function studioApp( | ||
| 518 | 524 | : followingCard(ctx, repo, following)} |
| 519 | 525 | ${archivedLine(ctx, repo)} |
| 520 | 526 | <div id="app-head">${head}</div> |
| 527 | ${welcome} | |
| 521 | 528 | ${ownerFacts ? crewKeyCard(ctx, true) : null} |
| 522 | 529 | ${ownerFacts ? landOnApp(ctx, repo) : null} |
| 523 | 530 | ${pausedLine(ctx, repo)} |
| @@ -545,6 +552,7 @@ export async function studioApp( | ||
| 545 | 552 | : followingCard(ctx, repo, following)} |
| 546 | 553 | ${archivedLine(ctx, repo)} |
| 547 | 554 | <div id="app-head">${head}</div> |
| 555 | ${welcome} | |
| 548 | 556 | ${askingLine(ctx, repo)} |
| 549 | 557 | ${policy} |
| 550 | 558 | ${ownerFacts ? crewKeyCard(ctx, true) : null} |
src/web/studio/make_it_yours.ts +30 −3
| @@ -16,6 +16,7 @@ import { | ||
| 16 | 16 | pageHead, |
| 17 | 17 | repoBase, |
| 18 | 18 | signInFirst, |
| 19 | signUpHref, | |
| 19 | 20 | } from "../chrome.ts"; |
| 20 | 21 | import { field, readForm } from "../form.ts"; |
| 21 | 22 | import { html, when } from "../html.ts"; |
| @@ -71,12 +72,33 @@ function helpBuildPage(ctx: Ctx, repo: Repo): Response { | ||
| 71 | 72 | }); |
| 72 | 73 | } |
| 73 | 74 | |
| 75 | /** | |
| 76 | * A signed-out visitor goes to sign-up carrying this app's make-it-yours page, and returns to it. | |
| 77 | */ | |
| 78 | const signUpFirst = (ctx: Ctx, repo: Repo): Response => { | |
| 79 | const q = ctx.url.searchParams.get("receipt") === "1" ? "?receipt=1" : ctx.url.searchParams.get("welcome") === "1" ? "?welcome=1" : ""; | |
| 80 | return redirect(signUpHref(ctx, `${repoBase(repo)}/make-it-yours${q}`)); | |
| 81 | }; | |
| 82 | ||
| 83 | /** How long after joining the sign-up return may make the copy on its own. */ | |
| 84 | const JUST_JOINED_MS = 30 * 60_000; | |
| 85 | ||
| 86 | /** | |
| 87 | * Whether this account was made in the last half hour: only then does a link's say-so stand for a | |
| 88 | * tap. | |
| 89 | */ | |
| 90 | function justJoined(createdAt: string): boolean { | |
| 91 | const iso = createdAt.includes("T") ? createdAt : createdAt.replace(" ", "T"); | |
| 92 | const at = Date.parse(/(?:Z|[+-]\d\d:?\d\d)$/.test(iso) ? iso : `${iso}Z`); | |
| 93 | return Number.isFinite(at) && Date.now() - at < JUST_JOINED_MS; | |
| 94 | } | |
| 95 | ||
| 74 | 96 | // GET /:owner/:name/make-it-yours |
| 75 | 97 | export async function makeItYoursPage(ctx: Ctx): Promise<Response> { |
| 76 | 98 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 77 | 99 | const repo = timePhase(ctx.request, "repo", () => loadRepo(ctx)); |
| 78 | 100 | if (!repo) return timePhase(ctx.request, "render", () => notFoundPage(ctx)); |
| 79 | if (!ctx.auth.user) return timePhase(ctx.request, "render", () => signInFirst(ctx)); | |
| 101 | if (!ctx.auth.user) return timePhase(ctx.request, "render", () => signUpFirst(ctx, repo)); | |
| 80 | 102 | const user = ctx.auth.user; |
| 81 | 103 | const plan = await timePhaseAsync(ctx.request, "plan", () => |
| 82 | 104 | makeItYours(ctx.app, user, repo, { dryRun: true }), |
| @@ -86,6 +108,10 @@ export async function makeItYoursPage(ctx: Ctx): Promise<Response> { | ||
| 86 | 108 | if (!plan.ok) |
| 87 | 109 | return timePhase(ctx.request, "render", () => planRefused(ctx, repo, plan.error)); |
| 88 | 110 | const p = plan.value; |
| 111 | // Back from sign-up with the intent kept (`welcome=1`): a new account's return is the tap, so the | |
| 112 | // page confirms itself, once, from its own origin. For anyone else the link waits for the button. | |
| 113 | const welcome = ctx.url.searchParams.get("welcome") === "1"; | |
| 114 | const selfTap = welcome && justJoined(user.createdAt); | |
| 89 | 115 | const rendering = performance.now(); |
| 90 | 116 | const body = html`<div class="narrow-wide"> |
| 91 | 117 | ${pageHead("Make it yours", { |
| @@ -106,6 +132,7 @@ export async function makeItYoursPage(ctx: Ctx): Promise<Response> { | ||
| 106 | 132 | ctx.url.searchParams.get("receipt") === "1", |
| 107 | 133 | () => html`<input type="hidden" name="receipt" value="1" />`, |
| 108 | 134 | )} |
| 135 | ${when(welcome, () => html`<input type="hidden" name="welcome" value="1" />`)} | |
| 109 | 136 | <ul class="list setting-list"> |
| 110 | 137 | ${row({ title: "Yours as", trail: html`<span class="mono">${p.repo}</span>` })} |
| 111 | 138 | ${row({ title: "Its address", trail: html`<span class="mono">${p.slug}</span>` })} |
| @@ -165,7 +192,7 @@ export async function makeItYoursPage(ctx: Ctx): Promise<Response> { | ||
| 165 | 192 | // The toolbar's tap is the whole ask only when its `go` token verifies for this viewer and |
| 166 | 193 | // repository (minted by the crew door, `apps/yours_go.ts`): then the page confirms itself, |
| 167 | 194 | // from its own origin. Any other link waits for the button below, which is the same ask. |
| 168 | ...(verifyYoursGo(ctx.app.config.dataDir, ctx.url.searchParams.get("go"), user.id, repo.id) | |
| 195 | ...(selfTap || verifyYoursGo(ctx.app.config.dataDir, ctx.url.searchParams.get("go"), user.id, repo.id) | |
| 169 | 196 | ? { scriptJs: AUTO_SUBMIT_JS } |
| 170 | 197 | : {}), |
| 171 | 198 | }); |
| @@ -197,7 +224,7 @@ export async function makeItYoursSubmit(ctx: Ctx): Promise<Response> { | ||
| 197 | 224 | url: ctx.url, |
| 198 | 225 | forgeUrl: ctx.app.config.url, |
| 199 | 226 | }); |
| 200 | return redirect(repoBase(made.value.made.repo), { | |
| 227 | return redirect(`${repoBase(made.value.made.repo)}${field(form, "welcome") === "1" ? "?welcome=1" : ""}`, { | |
| 201 | 228 | url: ctx.url, |
| 202 | 229 | forgeUrl: ctx.app.config.url, |
| 203 | 230 | flash: { |
src/web/studio/yours_button.ts +2 −2
| @@ -11,7 +11,7 @@ import type { AppRecord } from "../../core/apps.ts"; | ||
| 11 | 11 | import { getForkOf, type Repo } from "../../core/repos.ts"; |
| 12 | 12 | import { lacks } from "../../core/roles.ts"; |
| 13 | 13 | import type { Ctx } from "../../http/context.ts"; |
| 14 | import { repoBase, signInHref } from "../chrome.ts"; | |
| 14 | import { repoBase, signUpHref } from "../chrome.ts"; | |
| 15 | 15 | import { html, type Html } from "../html.ts"; |
| 16 | 16 | import { btn } from "../ui.ts"; |
| 17 | 17 | |
| @@ -19,7 +19,7 @@ export function yoursButton(ctx: Ctx, repo: Repo, record: AppRecord): Html | und | ||
| 19 | 19 | if (repo.visibility !== "public" || record.access !== "public") return undefined; |
| 20 | 20 | const base = repoBase(repo); |
| 21 | 21 | const user = ctx.auth.user; |
| 22 | if (user === undefined) return btn("Make it yours", { icon: "fork", href: signInHref(ctx) }); | |
| 22 | if (user === undefined) return btn("Make it yours", { icon: "fork", href: signUpHref(ctx, `${base}/make-it-yours?welcome=1`) }); | |
| 23 | 23 | if (user.kind !== "user") return undefined; |
| 24 | 24 | const db = ctx.app.db; |
| 25 | 25 | if (lacks(db, user, "make_it_yours")) return btn(HELP_BUILD, { icon: "fork", href: `${base}/make-it-yours` }); |
test/explore-fork.test.ts +2 −2
| @@ -68,8 +68,8 @@ describe("explore: make it yours", () => { | ||
| 68 | 68 | const res = await fetch(`${servers.url}${href!.replaceAll("&", "&")}`, { redirect: "manual" }); |
| 69 | 69 | expect(res.status).toBe(303); |
| 70 | 70 | const to = res.headers.get("location")!; |
| 71 | expect(to).toStartWith("/signin?next="); | |
| 72 | expect(decodeURIComponent(to.slice("/signin?next=".length))).toBe("/alice/open/make-it-yours?receipt=1"); | |
| 71 | expect(to).toStartWith("/signup?next="); | |
| 72 | expect(decodeURIComponent(to.slice("/signup?next=".length))).toBe("/alice/open/make-it-yours?receipt=1"); | |
| 73 | 73 | // A signed-out POST is sent the same way and makes nothing. |
| 74 | 74 | const post = await fetch(`${servers.url}/alice/open/make-it-yours`, { |
| 75 | 75 | method: "POST", |
test/explore.test.ts +1 −1
| @@ -334,7 +334,7 @@ describe("explore", () => { | ||
| 334 | 334 | const next = encodeURIComponent(path); |
| 335 | 335 | const res = await fetch(`${base}${path}`, { redirect: "manual" }); |
| 336 | 336 | expect(res.status).toBe(303); |
| 337 | expect(res.headers.get("location")).toBe(`/signin?next=${next}`); | |
| 337 | expect(res.headers.get("location")).toBe(`/signup?next=${next}`); | |
| 338 | 338 | const copies = () => (app.db.query(`SELECT COUNT(*) AS n FROM repo WHERE owner_id = ?1`).get(bob.id) as { n: number }).n; |
| 339 | 339 | const before = copies(); |
| 340 | 340 | const signedIn = await fetch(`${base}/signin?next=${next}`, { |
test/explorer-make-it-yours.test.ts +2 −2
| @@ -112,11 +112,11 @@ describe("explorer: make it yours", () => { | ||
| 112 | 112 | expect(getRepo(app.db, "bob", "garden")).toBeUndefined(); |
| 113 | 113 | }); |
| 114 | 114 | |
| 115 | test("signed out, the preview asks to sign in and offers no confirm", async () => { | |
| 115 | test("signed out, the preview asks to sign up and offers no confirm", async () => { | |
| 116 | 116 | const res = await fetch(`${servers.url}/alice/garden/make-it-yours?receipt=1`, { redirect: "manual" }); |
| 117 | 117 | const body = await res.text(); |
| 118 | 118 | expect(res.status).toBe(303); |
| 119 | expect(res.headers.get("location")).toBe("/signin?next=%2Falice%2Fgarden%2Fmake-it-yours%3Freceipt%3D1"); | |
| 119 | expect(res.headers.get("location")).toBe("/signup?next=%2Falice%2Fgarden%2Fmake-it-yours%3Freceipt%3D1"); | |
| 120 | 120 | expect(body).not.toContain('action="/alice/garden/make-it-yours"'); |
| 121 | 121 | expect(getRepo(app.db, "bob", "garden")).toBeUndefined(); |
| 122 | 122 | }); |
test/friend-journey.test.ts +1 −1
| @@ -92,7 +92,7 @@ describe("the Friend test", () => { | ||
| 92 | 92 | const lead = await fetch(`${servers.url}/alice/garden/make-it-yours?receipt=1`, { redirect: "manual" }); |
| 93 | 93 | expect(lead.status).toBe(303); |
| 94 | 94 | expect(lead.headers.get("location")).toBe( |
| 95 | `/signin?next=${encodeURIComponent("/alice/garden/make-it-yours?receipt=1")}`, | |
| 95 | `/signup?next=${encodeURIComponent("/alice/garden/make-it-yours?receipt=1")}`, | |
| 96 | 96 | ); |
| 97 | 97 | |
| 98 | 98 | // A stranger who only signed up is a guest: the page offers them help |
test/guest-contribute.test.ts +1 −1
| @@ -650,7 +650,7 @@ describe("a stranger's first pull starts from the app's page", () => { | ||
| 650 | 650 | expect(opts.status).toBe(200); |
| 651 | 651 | expect(((await opts.json()) as { challenge?: string }).challenge).toBeTruthy(); |
| 652 | 652 | const toSignIn = await fetch(`${servers.url}/olive/game/make-it-yours`, { redirect: "manual" }); |
| 653 | expect(toSignIn.headers.get("location")).toContain("/signin?next="); | |
| 653 | expect(toSignIn.headers.get("location")).toContain("/signup?next="); | |
| 654 | 654 | |
| 655 | 655 | // A private app offers nothing. |
| 656 | 656 | expect(await (await fetch(`${servers.url}/olive/secret`)).text()).not.toContain('id="contribute"'); |
test/make-it-yours-button.test.ts +73 −5
| @@ -10,8 +10,11 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 10 | 10 | import { updateApp, getAppByRepo } from "../src/core/apps.ts"; |
| 11 | 11 | import { newApp } from "../src/actions/apps.ts"; |
| 12 | 12 | import { createSession } from "../src/core/sessions.ts"; |
| 13 | import { createUser, getUserById } from "../src/core/users.ts"; | |
| 13 | import { createUser, getUserById, getUserByName } from "../src/core/users.ts"; | |
| 14 | 14 | import { getRepo } from "../src/core/repos.ts"; |
| 15 | import { setLimit } from "../src/settings/limits.ts"; | |
| 16 | import { markVerified } from "../src/core/verify.ts"; | |
| 17 | import { safeNext } from "../src/web/return_to.ts"; | |
| 15 | 18 | import { serve, type Servers } from "../src/http/server.ts"; |
| 16 | 19 | import { quietLogs } from "./helpers/globals.ts"; |
| 17 | 20 | import { promote } from "./helpers/members.ts"; |
| @@ -27,11 +30,11 @@ describe("make it yours on the repository page", () => { | ||
| 27 | 30 | |
| 28 | 31 | const get = async (path: string, cookie?: string) => |
| 29 | 32 | (await fetch(`${servers.url}${path}`, { headers: cookie ? { cookie } : {} })).text(); |
| 30 | const post = (path: string, headers: Record<string, string>) => | |
| 33 | const post = (path: string, headers: Record<string, string>, body = "") => | |
| 31 | 34 | fetch(`${servers.url}${path}`, { |
| 32 | 35 | method: "POST", |
| 33 | 36 | headers: { cookie: bobCookie, "content-type": "application/x-www-form-urlencoded", ...headers }, |
| 34 | body: "", | |
| 37 | body, | |
| 35 | 38 | redirect: "manual", |
| 36 | 39 | }); |
| 37 | 40 | |
| @@ -80,10 +83,10 @@ describe("make it yours on the repository page", () => { | ||
| 80 | 83 | await rm(dataDir, { recursive: true, force: true }); |
| 81 | 84 | }); |
| 82 | 85 | |
| 83 | test("signed out: the button leads to sign-in and back", async () => { | |
| 86 | test("signed out: the button leads to sign-up carrying the app", async () => { | |
| 84 | 87 | const page = await get("/alice/garden"); |
| 85 | 88 | expect(page).toContain("Make it yours"); |
| 86 | expect(page).toContain("/signin?next=%2Falice%2Fgarden"); | |
| 89 | expect(page).toContain("/signup?next=%2Falice%2Fgarden%2Fmake-it-yours%3Fwelcome%3D1"); | |
| 87 | 90 | }); |
| 88 | 91 | |
| 89 | 92 | test("signed out: the sign-in it leads to carries the visitor back to the app page", async () => { |
| @@ -140,4 +143,69 @@ describe("make it yours on the repository page", () => { | ||
| 140 | 143 | expect(after).toContain("Open your copy"); |
| 141 | 144 | expect(after).not.toContain('action="/alice/garden/make-it-yours"'); |
| 142 | 145 | }); |
| 146 | ||
| 147 | test("the whole path: signed out, through the real sign-up form, the return makes one copy and lands on it with first steps", async () => { | |
| 148 | setLimit(app.db, "signup.per_source", 100, "system"); | |
| 149 | const out = await fetch(`${servers.url}/alice/garden/make-it-yours?welcome=1`, { redirect: "manual" }); | |
| 150 | const to = out.headers.get("location")!; | |
| 151 | expect(to).toBe("/signup?next=%2Falice%2Fgarden%2Fmake-it-yours%3Fwelcome%3D1"); | |
| 152 | expect(await (await fetch(`${servers.url}${to}`)).text()).toContain("%2Falice%2Fgarden%2Fmake-it-yours"); | |
| 153 | const signed = await fetch(`${servers.url}${to}`, { | |
| 154 | method: "POST", | |
| 155 | headers: { origin: servers.url }, | |
| 156 | body: new URLSearchParams({ username: "erin", email: "[email protected]", password: "correct horse battery" }), | |
| 157 | redirect: "manual", | |
| 158 | }); | |
| 159 | expect(signed.status).toBe(303); | |
| 160 | const back = signed.headers.get("location")!; | |
| 161 | expect(back).toBe("/alice/garden/make-it-yours?welcome=1"); | |
| 162 | const cookie = signed.headers.get("set-cookie")!.split(";")[0]!; | |
| 163 | expect(getRepo(app.db, "erin", "garden")).toBeUndefined(); | |
| 164 | // A newcomer is a guest until a member admits them (a guest gets the help-build page instead); | |
| 165 | // this forge admits erin, as its owner would. | |
| 166 | promote(app.db); | |
| 167 | markVerified(app.db, getUserByName(app.db, "erin")!.id, new Date().toISOString()); | |
| 168 | // The return confirms itself from its own origin, and carries the intent to the post. | |
| 169 | const confirm = await get(back, cookie); | |
| 170 | expect(confirm).toContain('name="welcome" value="1"'); | |
| 171 | const script = confirm.match(/src="(\/assets\/page-[^"]+\.js)"/)?.[1]; | |
| 172 | expect(script).toBeDefined(); | |
| 173 | expect(await (await fetch(`${servers.url}${script}`)).text()).toContain("requestSubmit"); | |
| 174 | // That submit makes the copy once; a repeat opens it, never a second. | |
| 175 | for (let i = 0; i < 3; i++) { | |
| 176 | const res = await post("/alice/garden/make-it-yours", { | |
| 177 | origin: servers.url, | |
| 178 | cookie, | |
| 179 | "content-type": "application/x-www-form-urlencoded", | |
| 180 | }, "welcome=1"); | |
| 181 | expect(res.status).toBe(303); | |
| 182 | expect(res.headers.get("location")).toBe("/erin/garden?welcome=1"); | |
| 183 | } | |
| 184 | const erin = getUserByName(app.db, "erin")!; | |
| 185 | const copies = app.db.query<{ n: number }, [string]>("SELECT count(*) AS n FROM repo WHERE owner_id = ?1 AND name = 'garden'").get(erin.id)!; | |
| 186 | expect(copies.n).toBe(1); | |
| 187 | const landed = await get("/erin/garden?welcome=1", cookie); | |
| 188 | expect(landed).toContain('id="first-steps"'); | |
| 189 | expect(await get("/erin/garden", cookie)).not.toContain('id="first-steps"'); | |
| 190 | }); | |
| 191 | ||
| 192 | test("a link saying welcome does not make a copy for an account that is not new", async () => { | |
| 193 | const gina = await createUser(app.db, { | |
| 194 | origin: "seed", trusted: true, username: "gina", email: "[email protected]", password: "correct horse battery", | |
| 195 | }); | |
| 196 | if (!gina.ok) throw new Error(String(gina.error)); | |
| 197 | promote(app.db, gina.value); | |
| 198 | const cookie = `forge_session=${createSession(app.db, gina.value.id).token}`; | |
| 199 | const scripted = /src="\/assets\/page-[^"]+\.js"/; | |
| 200 | expect(await get("/alice/garden/make-it-yours?welcome=1", cookie)).toMatch(scripted); | |
| 201 | app.db.query("UPDATE user SET created_at = '2026-01-01T00:00:00.000Z' WHERE id = ?1").run(gina.value.id); | |
| 202 | expect(await get("/alice/garden/make-it-yours?welcome=1", cookie)).not.toMatch(scripted); | |
| 203 | expect(getRepo(app.db, "gina", "garden")).toBeUndefined(); | |
| 204 | }); | |
| 205 | ||
| 206 | test("a return target off the forge is refused", () => { | |
| 207 | for (const bad of ["https://evil.example/", "//evil.example", "/\\evil.example", "/\t/evil.example", "javascript:alert(1)"]) | |
| 208 | expect(safeNext(bad)).toBeUndefined(); | |
| 209 | expect(safeNext("/alice/garden/make-it-yours")).toBe("/alice/garden/make-it-yours"); | |
| 210 | }); | |
| 143 | 211 | }); |
new above
offline
This only moves the visitor to a page that still needs a second tap and never reaches the fork or first-steps; the issue asks for landing on their own fork. Make the return create the copy once and land on it.