Public: anyone can read this; the crew can change it.
test/origins-security-provider.test.ts: the off-host redirect test cannot connect to its own `localhost` origin #990
scout/forge:scout/585-test-origins-security-provider-test-ts-t → main 1 commit fork
1 file
changed +14
−7
test/origins-security-provider.test.ts +14 −7
| @@ -111,6 +111,7 @@ describe("a provider request cannot be turned against the credential", () => { | ||
| 111 | 111 | const paths: string[] = []; |
| 112 | 112 | const origin = Bun.serve({ |
| 113 | 113 | port: 0, |
| 114 | hostname: "127.0.0.1", | |
| 114 | 115 | fetch(request) { |
| 115 | 116 | const url = new URL(request.url); |
| 116 | 117 | paths.push(url.pathname); |
| @@ -124,7 +125,7 @@ describe("a provider request cannot be turned against the credential", () => { | ||
| 124 | 125 | }); |
| 125 | 126 | try { |
| 126 | 127 | const result = await client( |
| 127 | `http://localhost:${origin.port}/api/v1`, | |
| 128 | `http://127.0.0.1:${origin.port}/api/v1`, | |
| 128 | 129 | ).call({ path: "/repos/octo/old" }); |
| 129 | 130 | expect(result.ok).toBe(true); |
| 130 | 131 | expect(paths).toEqual([ |
| @@ -139,6 +140,7 @@ describe("a provider request cannot be turned against the credential", () => { | ||
| 139 | 140 | test("a redirect loop ends, and a Location-less redirect is an error", async () => { |
| 140 | 141 | const origin = Bun.serve({ |
| 141 | 142 | port: 0, |
| 143 | hostname: "127.0.0.1", | |
| 142 | 144 | fetch(request) { |
| 143 | 145 | const url = new URL(request.url); |
| 144 | 146 | if (url.pathname.endsWith("/loop")) |
| @@ -150,7 +152,7 @@ describe("a provider request cannot be turned against the credential", () => { | ||
| 150 | 152 | }, |
| 151 | 153 | }); |
| 152 | 154 | try { |
| 153 | const api = client(`http://localhost:${origin.port}/api/v1`); | |
| 155 | const api = client(`http://127.0.0.1:${origin.port}/api/v1`); | |
| 154 | 156 | const loop = await api.call({ path: "/loop" }); |
| 155 | 157 | expect(loop.ok).toBe(false); |
| 156 | 158 | const nowhere = await api.call({ path: "/nowhere" }); |
| @@ -163,6 +165,7 @@ describe("a provider request cannot be turned against the credential", () => { | ||
| 163 | 165 | test("an error body that quotes the token back is scrubbed", async () => { |
| 164 | 166 | const origin = Bun.serve({ |
| 165 | 167 | port: 0, |
| 168 | hostname: "127.0.0.1", | |
| 166 | 169 | fetch(request) { |
| 167 | 170 | const auth = request.headers.get("authorization") ?? ""; |
| 168 | 171 | const url = new URL(request.url); |
| @@ -177,7 +180,7 @@ describe("a provider request cannot be turned against the credential", () => { | ||
| 177 | 180 | }, |
| 178 | 181 | }); |
| 179 | 182 | try { |
| 180 | const api = client(`http://localhost:${origin.port}/api/v1`); | |
| 183 | const api = client(`http://127.0.0.1:${origin.port}/api/v1`); | |
| 181 | 184 | for (const path of ["/422", "/500", "/418"]) { |
| 182 | 185 | const result = await api.call({ path }); |
| 183 | 186 | expect(result.ok).toBe(false); |
| @@ -197,6 +200,7 @@ describe("a provider request cannot be turned against the credential", () => { | ||
| 197 | 200 | let sent = 0; |
| 198 | 201 | const origin = Bun.serve({ |
| 199 | 202 | port: 0, |
| 203 | hostname: "127.0.0.1", | |
| 200 | 204 | fetch() { |
| 201 | 205 | const stream = new ReadableStream<Uint8Array>({ |
| 202 | 206 | pull(controller) { |
| @@ -215,7 +219,7 @@ describe("a provider request cannot be turned against the credential", () => { | ||
| 215 | 219 | }); |
| 216 | 220 | try { |
| 217 | 221 | const cap = 1024 * 1024; |
| 218 | const result = await client(`http://localhost:${origin.port}/api/v1`, { | |
| 222 | const result = await client(`http://127.0.0.1:${origin.port}/api/v1`, { | |
| 219 | 223 | maxBytes: cap, |
| 220 | 224 | }).call({ path: "/user" }); |
| 221 | 225 | expect(result.ok).toBe(false); |
| @@ -231,6 +235,7 @@ describe("a provider request cannot be turned against the credential", () => { | ||
| 231 | 235 | test("a declared oversized body is refused on its Content-Length alone", async () => { |
| 232 | 236 | const origin = Bun.serve({ |
| 233 | 237 | port: 0, |
| 238 | hostname: "127.0.0.1", | |
| 234 | 239 | fetch() { |
| 235 | 240 | return new Response(new Uint8Array(4096), { |
| 236 | 241 | headers: { "content-length": String(64 * 1024 * 1024) }, |
| @@ -239,7 +244,7 @@ describe("a provider request cannot be turned against the credential", () => { | ||
| 239 | 244 | }); |
| 240 | 245 | try { |
| 241 | 246 | const started = Date.now(); |
| 242 | const result = await client(`http://localhost:${origin.port}/api/v1`, { | |
| 247 | const result = await client(`http://127.0.0.1:${origin.port}/api/v1`, { | |
| 243 | 248 | maxBytes: 1024, |
| 244 | 249 | }).call({ path: "/user" }); |
| 245 | 250 | expect(result.ok).toBe(false); |
| @@ -271,6 +276,7 @@ describe("a provider request cannot be turned against the credential", () => { | ||
| 271 | 276 | test("a body that never finishes is cut by the deadline", async () => { |
| 272 | 277 | const origin = Bun.serve({ |
| 273 | 278 | port: 0, |
| 279 | hostname: "127.0.0.1", | |
| 274 | 280 | fetch() { |
| 275 | 281 | // Headers now, a first chunk, then silence forever. |
| 276 | 282 | const stream = new ReadableStream<Uint8Array>({ |
| @@ -283,7 +289,7 @@ describe("a provider request cannot be turned against the credential", () => { | ||
| 283 | 289 | }); |
| 284 | 290 | try { |
| 285 | 291 | const started = Date.now(); |
| 286 | const result = await client(`http://localhost:${origin.port}/api/v1`, { | |
| 292 | const result = await client(`http://127.0.0.1:${origin.port}/api/v1`, { | |
| 287 | 293 | timeoutMs: 300, |
| 288 | 294 | }).call({ path: "/user" }); |
| 289 | 295 | expect(result.ok).toBe(false); |
| @@ -297,11 +303,12 @@ describe("a provider request cannot be turned against the credential", () => { | ||
| 297 | 303 | test("headers that never arrive are cut by the same deadline", async () => { |
| 298 | 304 | const origin = Bun.serve({ |
| 299 | 305 | port: 0, |
| 306 | hostname: "127.0.0.1", | |
| 300 | 307 | fetch: () => new Promise<Response>(() => undefined), |
| 301 | 308 | }); |
| 302 | 309 | try { |
| 303 | 310 | const started = Date.now(); |
| 304 | const result = await client(`http://localhost:${origin.port}/api/v1`, { | |
| 311 | const result = await client(`http://127.0.0.1:${origin.port}/api/v1`, { | |
| 305 | 312 | timeoutMs: 300, |
| 306 | 313 | }).call({ path: "/user" }); |
| 307 | 314 | expect(result.ok).toBe(false); |
new above
offline