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

Closed opened this
Closed without merging

scout/forge:scout/585-test-origins-security-provider-test-ts-t → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
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", () => {
111111 const paths: string[] = [];
112112 const origin = Bun.serve({
113113 port: 0,
114 hostname: "127.0.0.1",
114115 fetch(request) {
115116 const url = new URL(request.url);
116117 paths.push(url.pathname);
@@ -124,7 +125,7 @@ describe("a provider request cannot be turned against the credential", () => {
124125 });
125126 try {
126127 const result = await client(
127 `http://localhost:${origin.port}/api/v1`,
128 `http://127.0.0.1:${origin.port}/api/v1`,
128129 ).call({ path: "/repos/octo/old" });
129130 expect(result.ok).toBe(true);
130131 expect(paths).toEqual([
@@ -139,6 +140,7 @@ describe("a provider request cannot be turned against the credential", () => {
139140 test("a redirect loop ends, and a Location-less redirect is an error", async () => {
140141 const origin = Bun.serve({
141142 port: 0,
143 hostname: "127.0.0.1",
142144 fetch(request) {
143145 const url = new URL(request.url);
144146 if (url.pathname.endsWith("/loop"))
@@ -150,7 +152,7 @@ describe("a provider request cannot be turned against the credential", () => {
150152 },
151153 });
152154 try {
153 const api = client(`http://localhost:${origin.port}/api/v1`);
155 const api = client(`http://127.0.0.1:${origin.port}/api/v1`);
154156 const loop = await api.call({ path: "/loop" });
155157 expect(loop.ok).toBe(false);
156158 const nowhere = await api.call({ path: "/nowhere" });
@@ -163,6 +165,7 @@ describe("a provider request cannot be turned against the credential", () => {
163165 test("an error body that quotes the token back is scrubbed", async () => {
164166 const origin = Bun.serve({
165167 port: 0,
168 hostname: "127.0.0.1",
166169 fetch(request) {
167170 const auth = request.headers.get("authorization") ?? "";
168171 const url = new URL(request.url);
@@ -177,7 +180,7 @@ describe("a provider request cannot be turned against the credential", () => {
177180 },
178181 });
179182 try {
180 const api = client(`http://localhost:${origin.port}/api/v1`);
183 const api = client(`http://127.0.0.1:${origin.port}/api/v1`);
181184 for (const path of ["/422", "/500", "/418"]) {
182185 const result = await api.call({ path });
183186 expect(result.ok).toBe(false);
@@ -197,6 +200,7 @@ describe("a provider request cannot be turned against the credential", () => {
197200 let sent = 0;
198201 const origin = Bun.serve({
199202 port: 0,
203 hostname: "127.0.0.1",
200204 fetch() {
201205 const stream = new ReadableStream<Uint8Array>({
202206 pull(controller) {
@@ -215,7 +219,7 @@ describe("a provider request cannot be turned against the credential", () => {
215219 });
216220 try {
217221 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`, {
219223 maxBytes: cap,
220224 }).call({ path: "/user" });
221225 expect(result.ok).toBe(false);
@@ -231,6 +235,7 @@ describe("a provider request cannot be turned against the credential", () => {
231235 test("a declared oversized body is refused on its Content-Length alone", async () => {
232236 const origin = Bun.serve({
233237 port: 0,
238 hostname: "127.0.0.1",
234239 fetch() {
235240 return new Response(new Uint8Array(4096), {
236241 headers: { "content-length": String(64 * 1024 * 1024) },
@@ -239,7 +244,7 @@ describe("a provider request cannot be turned against the credential", () => {
239244 });
240245 try {
241246 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`, {
243248 maxBytes: 1024,
244249 }).call({ path: "/user" });
245250 expect(result.ok).toBe(false);
@@ -271,6 +276,7 @@ describe("a provider request cannot be turned against the credential", () => {
271276 test("a body that never finishes is cut by the deadline", async () => {
272277 const origin = Bun.serve({
273278 port: 0,
279 hostname: "127.0.0.1",
274280 fetch() {
275281 // Headers now, a first chunk, then silence forever.
276282 const stream = new ReadableStream<Uint8Array>({
@@ -283,7 +289,7 @@ describe("a provider request cannot be turned against the credential", () => {
283289 });
284290 try {
285291 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`, {
287293 timeoutMs: 300,
288294 }).call({ path: "/user" });
289295 expect(result.ok).toBe(false);
@@ -297,11 +303,12 @@ describe("a provider request cannot be turned against the credential", () => {
297303 test("headers that never arrive are cut by the same deadline", async () => {
298304 const origin = Bun.serve({
299305 port: 0,
306 hostname: "127.0.0.1",
300307 fetch: () => new Promise<Response>(() => undefined),
301308 });
302309 try {
303310 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`, {
305312 timeoutMs: 300,
306313 }).call({ path: "/user" });
307314 expect(result.ok).toBe(false);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs