1
- const https = require ( "https" ) ;
2
1
const { readFileSync } = require ( "fs" ) ;
3
2
const { resolve } = require ( "path" ) ;
3
+ const { fetch : undiciFetch , Agent } = require ( "undici" ) ;
4
4
5
5
const { Octokit } = require ( "../../.." ) ;
6
6
const ca = readFileSync ( resolve ( __dirname , "./ca.crt" ) ) ;
7
7
8
- require ( "../../mocha-node-setup" ) ;
9
-
10
8
describe ( "custom client certificate" , ( ) => {
11
9
let server ;
12
10
before ( ( done ) => {
@@ -28,13 +26,23 @@ describe("custom client certificate", () => {
28
26
server . listen ( 0 , done ) ;
29
27
} ) ;
30
28
31
- it ( "https.Agent({ca})" , ( ) => {
32
- const agent = new https . Agent ( {
33
- ca,
29
+ it ( "undici.Agent({ca})" , ( ) => {
30
+ const agent = new Agent ( {
31
+ keepAliveTimeout : 10 ,
32
+ keepAliveMaxTimeout : 10 ,
33
+ connect : { ca : ca } ,
34
34
} ) ;
35
+ const myFetch = ( url , opts ) => {
36
+ return undiciFetch ( url , {
37
+ ...opts ,
38
+ dispatcher : agent ,
39
+ } ) ;
40
+ } ;
35
41
const octokit = new Octokit ( {
36
42
baseUrl : "https://localhost:" + server . address ( ) . port ,
37
- request : { agent } ,
43
+ request : {
44
+ fetch : myFetch ,
45
+ } ,
38
46
} ) ;
39
47
40
48
return octokit . rest . repos . get ( {
@@ -43,14 +51,26 @@ describe("custom client certificate", () => {
43
51
} ) ;
44
52
} ) ;
45
53
46
- it ( "https.Agent({ca, rejectUnauthorized})" , ( ) => {
47
- const agent = new https . Agent ( {
48
- ca : "invalid" ,
49
- rejectUnauthorized : false ,
54
+ it ( "undici.Agent({ca, rejectUnauthorized})" , ( ) => {
55
+ const agent = new Agent ( {
56
+ keepAliveTimeout : 10 ,
57
+ keepAliveMaxTimeout : 10 ,
58
+ connect : {
59
+ ca : "invalid" ,
60
+ rejectUnauthorized : true ,
61
+ } ,
50
62
} ) ;
63
+ const myFetch = ( url , opts ) => {
64
+ return undiciFetch ( url , {
65
+ ...opts ,
66
+ dispatcher : agent ,
67
+ } ) ;
68
+ } ;
51
69
const octokit = new Octokit ( {
52
70
baseUrl : "https://localhost:" + server . address ( ) . port ,
53
- request : { agent } ,
71
+ request : {
72
+ fetch : myFetch ,
73
+ } ,
54
74
} ) ;
55
75
56
76
return octokit . rest . repos . get ( {
0 commit comments