Skip to content

Commit 7366d08

Browse files
committed
add specs for shouldPassThrough
1 parent 235a512 commit 7366d08

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/server/http-combo-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ function analyzeAndMaybePassThroughTls(
421421
});
422422
}
423423

424-
function shouldPassThrough(
424+
export function shouldPassThrough(
425425
hostname: string | undefined,
426426
// Only one of these two should have values (validated above):
427427
passThroughHostnames: string[],

test/http-combo-server.spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { shouldPassThrough } from "../src/server/http-combo-server";
2+
import { expect } from "./test-utils";
3+
4+
describe("shouldPassThrough", () => {
5+
it("should return false when passThroughHostnames is empty and interceptOnlyHostnames is undefined", async () => {
6+
const should = shouldPassThrough("example.org", [], undefined);
7+
expect(should).to.be.false;
8+
});
9+
10+
it("should return true when both lists empty", async () => {
11+
const should = shouldPassThrough("example.org", [], []);
12+
expect(should).to.be.true;
13+
});
14+
15+
it("should return false when hostname is falsy", () => {
16+
const should = shouldPassThrough("", [], []);
17+
expect(should).to.be.false;
18+
});
19+
20+
describe("passThroughHostnames", () => {
21+
it("should return true when hostname is in passThroughHostnames", () => {
22+
const should = shouldPassThrough(
23+
"example.org",
24+
["example.org"],
25+
undefined
26+
);
27+
expect(should).to.be.true;
28+
});
29+
30+
it("should return false when hostname is not in passThroughHostnames", () => {
31+
const should = shouldPassThrough(
32+
"example.org",
33+
["example.com"],
34+
undefined
35+
);
36+
expect(should).to.be.false;
37+
});
38+
});
39+
describe("interceptOnlyHostnames", () => {
40+
it("should return false when hostname is in interceptOnlyHostnames", () => {
41+
const should = shouldPassThrough("example.org", [], ["example.org"]);
42+
expect(should).to.be.false;
43+
});
44+
45+
it("should return true when hostname is not in interceptOnlyHostnames", () => {
46+
const should = shouldPassThrough("example.org", [], ["example.com"]);
47+
expect(should).to.be.true;
48+
});
49+
});
50+
});

0 commit comments

Comments
 (0)