Skip to content

Commit 6ce1dd1

Browse files
committed
add integration specs for wildcards
1 parent 8e19588 commit 6ce1dd1

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

test/integration/https.spec.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,61 @@ describe("When configured for HTTPS", () => {
252252
});
253253
});
254254

255+
describe("with wildcards hostnames excluded", () => {
256+
let server = getLocal({
257+
https: {
258+
keyPath: './test/fixtures/test-ca.key',
259+
certPath: './test/fixtures/test-ca.pem',
260+
tlsPassthrough: [
261+
{ hostname: '*.com' }
262+
]
263+
}
264+
});
265+
266+
beforeEach(async () => {
267+
await server.start();
268+
await server.forGet('/').thenReply(200, "Mock response");
269+
});
270+
271+
afterEach(async () => {
272+
await server.stop()
273+
});
274+
275+
it("handles matching HTTPS requests", async () => {
276+
const response: http.IncomingMessage = await new Promise((resolve) =>
277+
https.get({
278+
host: 'localhost',
279+
port: server.port,
280+
servername: 'wikipedia.org',
281+
headers: { 'Host': 'wikipedia.org' }
282+
}).on('response', resolve)
283+
);
284+
285+
expect(response.statusCode).to.equal(200);
286+
const body = (await streamToBuffer(response)).toString();
287+
expect(body).to.equal("Mock response");
288+
});
289+
290+
it("skips the server for non-matching HTTPS requests", async function () {
291+
this.retries(3); // Example.com can be unreliable
292+
293+
const response: http.IncomingMessage = await new Promise((resolve, reject) =>
294+
https.get({
295+
host: 'localhost',
296+
port: server.port,
297+
servername: 'example.com',
298+
headers: { 'Host': 'example.com' }
299+
}).on('response', resolve).on('error', reject)
300+
);
301+
302+
expect(response.statusCode).to.equal(200);
303+
const body = (await streamToBuffer(response)).toString();
304+
expect(body).to.include(
305+
"This domain is for use in illustrative examples in documents."
306+
);
307+
});
308+
});
309+
255310
describe("with some hostnames included", () => {
256311
let server = getLocal({
257312
https: {
@@ -306,5 +361,60 @@ describe("When configured for HTTPS", () => {
306361
);
307362
});
308363
});
364+
365+
describe("with wildcards hostnames included", () => {
366+
let server = getLocal({
367+
https: {
368+
keyPath: './test/fixtures/test-ca.key',
369+
certPath: './test/fixtures/test-ca.pem',
370+
tlsInterceptOnly: [
371+
{ hostname: '*.org' }
372+
]
373+
}
374+
});
375+
376+
beforeEach(async () => {
377+
await server.start();
378+
await server.forGet('/').thenReply(200, "Mock response");
379+
});
380+
381+
afterEach(async () => {
382+
await server.stop()
383+
});
384+
385+
it("handles matching HTTPS requests", async () => {
386+
const response: http.IncomingMessage = await new Promise((resolve) =>
387+
https.get({
388+
host: 'localhost',
389+
port: server.port,
390+
servername: 'wikipedia.org',
391+
headers: { 'Host': 'wikipedia.org' }
392+
}).on('response', resolve)
393+
);
394+
395+
expect(response.statusCode).to.equal(200);
396+
const body = (await streamToBuffer(response)).toString();
397+
expect(body).to.equal("Mock response");
398+
});
399+
400+
it("skips the server for non-matching HTTPS requests", async function () {
401+
this.retries(3); // Example.com can be unreliable
402+
403+
const response: http.IncomingMessage = await new Promise((resolve, reject) =>
404+
https.get({
405+
host: 'localhost',
406+
port: server.port,
407+
servername: 'example.com',
408+
headers: { 'Host': 'example.com' }
409+
}).on('response', resolve).on('error', reject)
410+
);
411+
412+
expect(response.statusCode).to.equal(200);
413+
const body = (await streamToBuffer(response)).toString();
414+
expect(body).to.include(
415+
"This domain is for use in illustrative examples in documents."
416+
);
417+
});
418+
});
309419
});
310420
});

0 commit comments

Comments
 (0)