Skip to content

Commit

Permalink
test: rewrite agent-ca tests with undici
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy1339 committed Jul 10, 2023
1 parent 81d17e0 commit 8a9a24e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 13 deletions.
36 changes: 35 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"semantic-release": "^21.0.0",
"semantic-release-plugin-update-version-in-files": "^1.0.0",
"ts-jest": "^29.0.0",
"typescript": "^5.0.0"
"typescript": "^5.0.0",
"undici": "^5.22.1"
},
"scripts": {
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
Expand Down
44 changes: 33 additions & 11 deletions test/integration/agent-ca/agent-ca-test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const https = require("https");
const { readFileSync } = require("fs");
const { resolve } = require("path");
const { fetch: undiciFetch, Agent } = require("undici");

const { Octokit } = require("../../..");
const ca = readFileSync(resolve(__dirname, "./ca.crt"));

describe.skip("custom client certificate", () => {
describe("custom client certificate", () => {
let server;
before((done) => {
server = https.createServer(
Expand All @@ -26,13 +26,23 @@ describe.skip("custom client certificate", () => {
server.listen(0, done);
});

it("https.Agent({ca})", () => {
const agent = new https.Agent({
ca,
it("undici.Agent({ca})", () => {
const agent = new Agent({
keepAliveTimeout: 10,
keepAliveMaxTimeout: 10,
connect: { ca: ca },
});
const myFetch = (url, opts) => {
return undiciFetch(url, {
...opts,
dispatcher: agent,
});
};
const octokit = new Octokit({
baseUrl: "https://localhost:" + server.address().port,
request: { agent },
request: {
fetch: myFetch,
},
});

return octokit.rest.repos.get({
Expand All @@ -41,14 +51,26 @@ describe.skip("custom client certificate", () => {
});
});

it("https.Agent({ca, rejectUnauthorized})", () => {
const agent = new https.Agent({
ca: "invalid",
rejectUnauthorized: false,
it("undici.Agent({ca, rejectUnauthorized})", () => {
const agent = new Agent({
keepAliveTimeout: 10,
keepAliveMaxTimeout: 10,
connect: {
ca: "invalid",
rejectUnauthorized: true,
},
});
const myFetch = (url, opts) => {
return undiciFetch(url, {
...opts,
dispatcher: agent,
});
};
const octokit = new Octokit({
baseUrl: "https://localhost:" + server.address().port,
request: { agent },
request: {
fetch: myFetch,
},
});

return octokit.rest.repos.get({
Expand Down

0 comments on commit 8a9a24e

Please sign in to comment.