1
- import { use , expect } from 'chai' ;
2
- import chaiAsPromised from 'chai-as-promised' ;
1
+ import { rejects , strictEqual } from 'node:assert' ;
3
2
import { dirname , join } from 'node:path' ;
4
3
import { fileURLToPath } from 'node:url' ;
5
4
@@ -10,8 +9,6 @@ import { HttpMethod, RequestContext } from './index.js';
10
9
11
10
const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
12
11
13
- use ( chaiAsPromised ) ;
14
-
15
12
describe ( 'AzureAuth' , ( ) => {
16
13
const testUrl1 = 'https://test1.com' ;
17
14
let auth : AzureAuth ;
@@ -26,7 +23,7 @@ describe('AzureAuth', () => {
26
23
} ,
27
24
} as User ;
28
25
29
- expect ( auth . isAuthProvider ( user ) ) . to . equal ( true ) ;
26
+ strictEqual ( auth . isAuthProvider ( user ) , true ) ;
30
27
} ) ;
31
28
32
29
it ( 'should be false for other user' , ( ) => {
@@ -36,13 +33,13 @@ describe('AzureAuth', () => {
36
33
} ,
37
34
} as User ;
38
35
39
- expect ( auth . isAuthProvider ( user ) ) . to . equal ( false ) ;
36
+ strictEqual ( auth . isAuthProvider ( user ) , false ) ;
40
37
} ) ;
41
38
42
39
it ( 'should be false for null user.authProvider' , ( ) => {
43
40
const user = { } as User ;
44
41
45
- expect ( auth . isAuthProvider ( user ) ) . to . equal ( false ) ;
42
+ strictEqual ( auth . isAuthProvider ( user ) , false ) ;
46
43
} ) ;
47
44
48
45
it ( 'should populate from auth provider' , async ( ) => {
@@ -63,12 +60,11 @@ describe('AzureAuth', () => {
63
60
const requestContext = new RequestContext ( testUrl1 , HttpMethod . GET ) ;
64
61
65
62
await config . applySecurityAuthentication ( requestContext ) ;
66
- expect ( requestContext . getHeaders ( ) ) . to . not . be . undefined ;
67
- expect ( requestContext . getHeaders ( ) [ 'Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
63
+ strictEqual ( requestContext . getHeaders ( ) ?. [ 'Authorization' ] , `Bearer ${ token } ` ) ;
68
64
69
65
requestContext . setHeaderParam ( 'Host' , 'foo.com' ) ;
70
66
await config . applySecurityAuthentication ( requestContext ) ;
71
- expect ( requestContext . getHeaders ( ) . Authorization ) . to . equal ( `Bearer ${ token } ` ) ;
67
+ strictEqual ( requestContext . getHeaders ( ) . Authorization , `Bearer ${ token } ` ) ;
72
68
} ) ;
73
69
74
70
it ( 'should populate from auth provider without expiry' , async ( ) => {
@@ -88,8 +84,7 @@ describe('AzureAuth', () => {
88
84
const requestContext = new RequestContext ( testUrl1 , HttpMethod . GET ) ;
89
85
90
86
await config . applySecurityAuthentication ( requestContext ) ;
91
- expect ( requestContext . getHeaders ( ) ) . to . not . be . undefined ;
92
- expect ( requestContext . getHeaders ( ) [ 'Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
87
+ strictEqual ( requestContext . getHeaders ( ) ?. [ 'Authorization' ] , `Bearer ${ token } ` ) ;
93
88
} ) ;
94
89
95
90
it ( 'should populate rejectUnauthorized=false when skipTLSVerify is set' , async ( ) => {
@@ -110,7 +105,7 @@ describe('AzureAuth', () => {
110
105
111
106
await config . applySecurityAuthentication ( requestContext ) ;
112
107
// @ts -expect-error
113
- expect ( requestContext . getAgent ( ) . options . rejectUnauthorized ) . to . equal ( false ) ;
108
+ strictEqual ( requestContext . getAgent ( ) . options . rejectUnauthorized , false ) ;
114
109
} ) ;
115
110
116
111
it ( 'should not set rejectUnauthorized if skipTLSVerify is not set' , async ( ) => {
@@ -133,10 +128,10 @@ describe('AzureAuth', () => {
133
128
134
129
await config . applySecurityAuthentication ( requestContext ) ;
135
130
// @ts -expect-error
136
- expect ( requestContext . getAgent ( ) . options . rejectUnauthorized ) . to . equal ( undefined ) ;
131
+ strictEqual ( requestContext . getAgent ( ) . options . rejectUnauthorized , undefined ) ;
137
132
} ) ;
138
133
139
- it ( 'should throw with expired token and no cmd' , ( ) => {
134
+ it ( 'should throw with expired token and no cmd' , async ( ) => {
140
135
const config = new KubeConfig ( ) ;
141
136
config . loadFromClusterAndUser (
142
137
{ skipTLSVerify : false } as Cluster ,
@@ -151,12 +146,12 @@ describe('AzureAuth', () => {
151
146
) ;
152
147
const requestContext = new RequestContext ( testUrl1 , HttpMethod . GET ) ;
153
148
154
- return expect ( config . applySecurityAuthentication ( requestContext ) ) . to . eventually . be . rejectedWith (
155
- 'Token is expired!' ,
156
- ) ;
149
+ await rejects ( config . applySecurityAuthentication ( requestContext ) , {
150
+ message : 'Token is expired!' ,
151
+ } ) ;
157
152
} ) ;
158
153
159
- it ( 'should throw with bad command' , ( ) => {
154
+ it ( 'should throw with bad command' , async ( ) => {
160
155
const config = new KubeConfig ( ) ;
161
156
config . loadFromClusterAndUser (
162
157
{ skipTLSVerify : false } as Cluster ,
@@ -173,9 +168,9 @@ describe('AzureAuth', () => {
173
168
) ;
174
169
const requestContext = new RequestContext ( testUrl1 , HttpMethod . GET ) ;
175
170
176
- return expect ( config . applySecurityAuthentication ( requestContext ) ) . to . eventually . be . rejectedWith (
177
- / F a i l e d t o r e f r e s h t o k e n / ,
178
- ) ;
171
+ await rejects ( config . applySecurityAuthentication ( requestContext ) , {
172
+ message : / F a i l e d t o r e f r e s h t o k e n / ,
173
+ } ) ;
179
174
} ) ;
180
175
181
176
it ( 'should exec when no cmd and token is not expired' , async ( ) => {
@@ -224,8 +219,7 @@ describe('AzureAuth', () => {
224
219
const requestContext = new RequestContext ( testUrl1 , HttpMethod . GET ) ;
225
220
await config . applySecurityAuthentication ( requestContext ) ;
226
221
227
- expect ( requestContext . getHeaders ( ) ) . to . not . be . undefined ;
228
- expect ( requestContext . getHeaders ( ) [ 'Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
222
+ strictEqual ( requestContext . getHeaders ( ) ?. [ 'Authorization' ] , `Bearer ${ token } ` ) ;
229
223
} ) ;
230
224
it ( 'should exec without access-token' , async ( ) => {
231
225
// TODO: fix this test for Windows
@@ -252,8 +246,7 @@ describe('AzureAuth', () => {
252
246
const requestContext = new RequestContext ( testUrl1 , HttpMethod . GET ) ;
253
247
await config . applySecurityAuthentication ( requestContext ) ;
254
248
255
- expect ( requestContext . getHeaders ( ) ) . to . not . be . undefined ;
256
- expect ( requestContext . getHeaders ( ) [ 'Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
249
+ strictEqual ( requestContext . getHeaders ( ) ?. [ 'Authorization' ] , `Bearer ${ token } ` ) ;
257
250
} ) ;
258
251
it ( 'should exec without access-token' , async ( ) => {
259
252
// TODO: fix this test for Windows
@@ -280,8 +273,7 @@ describe('AzureAuth', () => {
280
273
const requestContext = new RequestContext ( testUrl1 , HttpMethod . GET ) ;
281
274
await config . applySecurityAuthentication ( requestContext ) ;
282
275
283
- expect ( requestContext . getHeaders ( ) ) . to . not . be . undefined ;
284
- expect ( requestContext . getHeaders ( ) [ 'Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
276
+ strictEqual ( requestContext . getHeaders ( ) ?. [ 'Authorization' ] , `Bearer ${ token } ` ) ;
285
277
} ) ;
286
278
it ( 'should exec succesfully with spaces in cmd' , async ( ) => {
287
279
// TODO: fix this test for Windows
@@ -308,7 +300,6 @@ describe('AzureAuth', () => {
308
300
const requestContext = new RequestContext ( testUrl1 , HttpMethod . GET ) ;
309
301
await config . applySecurityAuthentication ( requestContext ) ;
310
302
311
- expect ( requestContext . getHeaders ( ) ) . to . not . be . undefined ;
312
- expect ( requestContext . getHeaders ( ) [ 'Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
303
+ strictEqual ( requestContext . getHeaders ( ) ?. [ 'Authorization' ] , `Bearer ${ token } ` ) ;
313
304
} ) ;
314
305
} ) ;
0 commit comments