Skip to content

Commit a3613f3

Browse files
committed
Improve test coverage
1 parent 91c09e3 commit a3613f3

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

library/sinks/Fetch.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ t.test(
9999
};
100100
addHook("beforeOutboundRequest", hook);
101101
await fetch("http://app.aikido.dev");
102+
await fetch(new Request("https://app.aikido.dev", { method: "POST" }));
102103
t.same(agent.getHostnames().asArray(), [
103104
{ hostname: "app.aikido.dev", port: 80, hits: 1 },
105+
{ hostname: "app.aikido.dev", port: 443, hits: 1 },
104106
]);
105107
agent.getHostnames().clear();
106108
t.same(hookArgs, [
@@ -109,6 +111,11 @@ t.test(
109111
method: "GET",
110112
port: 80,
111113
},
114+
{
115+
url: new URL("https://app.aikido.dev/"),
116+
method: "POST",
117+
port: 443,
118+
},
112119
]);
113120
removeHook("beforeOutboundRequest", hook);
114121

library/sinks/Undici.tests.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ export async function createUndiciTests(undiciPkgName: string, port: number) {
8383
pathname: "/my-path",
8484
search: "?a=b",
8585
});
86+
await request(`http://localhost:${port}/api/internal`, {
87+
method: "POST",
88+
});
8689
t.same(agent.getHostnames().asArray(), [
8790
{ hostname: "ssrf-redirects.testssandbox.com", port: 443, hits: 1 },
91+
{ hostname: "localhost", port: port, hits: 1 },
8892
]);
8993
agent.getHostnames().clear();
9094
t.same(hookArgs, [
@@ -93,6 +97,11 @@ export async function createUndiciTests(undiciPkgName: string, port: number) {
9397
method: "GET",
9498
port: 443,
9599
},
100+
{
101+
url: new URL(`http://localhost:${port}/api/internal`),
102+
method: "POST",
103+
port: port,
104+
},
96105
]);
97106
removeHook("beforeOutboundRequest", beforeOutbound);
98107

library/sinks/undici/buildURLFromObject.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import * as t from "tap";
22
import { buildURLFromArgs } from "./buildURLFromObject";
33
import { parse as parseUrl } from "url";
44

5+
t.test("empty", async (t) => {
6+
const url = buildURLFromArgs([]);
7+
t.same(url, undefined);
8+
});
9+
510
t.test("it returns an URL instance", async (t) => {
611
const url = buildURLFromArgs(["http://localhost:4000"]);
712
t.ok(url instanceof URL);
@@ -22,6 +27,21 @@ t.test("it returns the full url", async () => {
2227
);
2328
});
2429

30+
t.test("origin ends with slash", async (t) => {
31+
t.same(
32+
buildURLFromArgs([
33+
{ origin: "http://localhost:4000/", pathname: "/api", search: "?page=1" },
34+
])?.toString(),
35+
"http://localhost:4000/api?page=1"
36+
);
37+
t.same(
38+
buildURLFromArgs([
39+
{ origin: "http://localhost:4000/", path: "/api?page=1" },
40+
])?.toString(),
41+
"http://localhost:4000/api?page=1"
42+
);
43+
});
44+
2545
t.test("it works with url string", async (t) => {
2646
t.same(
2747
buildURLFromArgs(["http://localhost:4000"])?.toString(),

0 commit comments

Comments
 (0)