1- import { use , expect } from 'chai' ;
2- import chaiAsPromised from 'chai-as-promised' ;
1+ import { rejects , strictEqual } from 'node:assert' ;
32import { dirname , join } from 'node:path' ;
43import { fileURLToPath } from 'node:url' ;
54
@@ -10,8 +9,6 @@ import { HttpMethod, RequestContext } from './index.js';
109
1110const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
1211
13- use ( chaiAsPromised ) ;
14-
1512describe ( 'AzureAuth' , ( ) => {
1613 const testUrl1 = 'https://test1.com' ;
1714 let auth : AzureAuth ;
@@ -26,7 +23,7 @@ describe('AzureAuth', () => {
2623 } ,
2724 } as User ;
2825
29- expect ( auth . isAuthProvider ( user ) ) . to . equal ( true ) ;
26+ strictEqual ( auth . isAuthProvider ( user ) , true ) ;
3027 } ) ;
3128
3229 it ( 'should be false for other user' , ( ) => {
@@ -36,13 +33,13 @@ describe('AzureAuth', () => {
3633 } ,
3734 } as User ;
3835
39- expect ( auth . isAuthProvider ( user ) ) . to . equal ( false ) ;
36+ strictEqual ( auth . isAuthProvider ( user ) , false ) ;
4037 } ) ;
4138
4239 it ( 'should be false for null user.authProvider' , ( ) => {
4340 const user = { } as User ;
4441
45- expect ( auth . isAuthProvider ( user ) ) . to . equal ( false ) ;
42+ strictEqual ( auth . isAuthProvider ( user ) , false ) ;
4643 } ) ;
4744
4845 it ( 'should populate from auth provider' , async ( ) => {
@@ -63,12 +60,11 @@ describe('AzureAuth', () => {
6360 const requestContext = new RequestContext ( testUrl1 , HttpMethod . GET ) ;
6461
6562 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 } ` ) ;
6864
6965 requestContext . setHeaderParam ( 'Host' , 'foo.com' ) ;
7066 await config . applySecurityAuthentication ( requestContext ) ;
71- expect ( requestContext . getHeaders ( ) . Authorization ) . to . equal ( `Bearer ${ token } ` ) ;
67+ strictEqual ( requestContext . getHeaders ( ) . Authorization , `Bearer ${ token } ` ) ;
7268 } ) ;
7369
7470 it ( 'should populate from auth provider without expiry' , async ( ) => {
@@ -88,8 +84,7 @@ describe('AzureAuth', () => {
8884 const requestContext = new RequestContext ( testUrl1 , HttpMethod . GET ) ;
8985
9086 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 } ` ) ;
9388 } ) ;
9489
9590 it ( 'should populate rejectUnauthorized=false when skipTLSVerify is set' , async ( ) => {
@@ -110,7 +105,7 @@ describe('AzureAuth', () => {
110105
111106 await config . applySecurityAuthentication ( requestContext ) ;
112107 // @ts -expect-error
113- expect ( requestContext . getAgent ( ) . options . rejectUnauthorized ) . to . equal ( false ) ;
108+ strictEqual ( requestContext . getAgent ( ) . options . rejectUnauthorized , false ) ;
114109 } ) ;
115110
116111 it ( 'should not set rejectUnauthorized if skipTLSVerify is not set' , async ( ) => {
@@ -133,10 +128,10 @@ describe('AzureAuth', () => {
133128
134129 await config . applySecurityAuthentication ( requestContext ) ;
135130 // @ts -expect-error
136- expect ( requestContext . getAgent ( ) . options . rejectUnauthorized ) . to . equal ( undefined ) ;
131+ strictEqual ( requestContext . getAgent ( ) . options . rejectUnauthorized , undefined ) ;
137132 } ) ;
138133
139- it ( 'should throw with expired token and no cmd' , ( ) => {
134+ it ( 'should throw with expired token and no cmd' , async ( ) => {
140135 const config = new KubeConfig ( ) ;
141136 config . loadFromClusterAndUser (
142137 { skipTLSVerify : false } as Cluster ,
@@ -151,12 +146,12 @@ describe('AzureAuth', () => {
151146 ) ;
152147 const requestContext = new RequestContext ( testUrl1 , HttpMethod . GET ) ;
153148
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+ } ) ;
157152 } ) ;
158153
159- it ( 'should throw with bad command' , ( ) => {
154+ it ( 'should throw with bad command' , async ( ) => {
160155 const config = new KubeConfig ( ) ;
161156 config . loadFromClusterAndUser (
162157 { skipTLSVerify : false } as Cluster ,
@@ -173,9 +168,9 @@ describe('AzureAuth', () => {
173168 ) ;
174169 const requestContext = new RequestContext ( testUrl1 , HttpMethod . GET ) ;
175170
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+ } ) ;
179174 } ) ;
180175
181176 it ( 'should exec when no cmd and token is not expired' , async ( ) => {
@@ -224,8 +219,7 @@ describe('AzureAuth', () => {
224219 const requestContext = new RequestContext ( testUrl1 , HttpMethod . GET ) ;
225220 await config . applySecurityAuthentication ( requestContext ) ;
226221
227- expect ( requestContext . getHeaders ( ) ) . to . not . be . undefined ;
228- expect ( requestContext . getHeaders ( ) [ 'Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
222+ strictEqual ( requestContext . getHeaders ( ) ?. [ 'Authorization' ] , `Bearer ${ token } ` ) ;
229223 } ) ;
230224 it ( 'should exec without access-token' , async ( ) => {
231225 // TODO: fix this test for Windows
@@ -252,8 +246,7 @@ describe('AzureAuth', () => {
252246 const requestContext = new RequestContext ( testUrl1 , HttpMethod . GET ) ;
253247 await config . applySecurityAuthentication ( requestContext ) ;
254248
255- expect ( requestContext . getHeaders ( ) ) . to . not . be . undefined ;
256- expect ( requestContext . getHeaders ( ) [ 'Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
249+ strictEqual ( requestContext . getHeaders ( ) ?. [ 'Authorization' ] , `Bearer ${ token } ` ) ;
257250 } ) ;
258251 it ( 'should exec without access-token' , async ( ) => {
259252 // TODO: fix this test for Windows
@@ -280,8 +273,7 @@ describe('AzureAuth', () => {
280273 const requestContext = new RequestContext ( testUrl1 , HttpMethod . GET ) ;
281274 await config . applySecurityAuthentication ( requestContext ) ;
282275
283- expect ( requestContext . getHeaders ( ) ) . to . not . be . undefined ;
284- expect ( requestContext . getHeaders ( ) [ 'Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
276+ strictEqual ( requestContext . getHeaders ( ) ?. [ 'Authorization' ] , `Bearer ${ token } ` ) ;
285277 } ) ;
286278 it ( 'should exec succesfully with spaces in cmd' , async ( ) => {
287279 // TODO: fix this test for Windows
@@ -308,7 +300,6 @@ describe('AzureAuth', () => {
308300 const requestContext = new RequestContext ( testUrl1 , HttpMethod . GET ) ;
309301 await config . applySecurityAuthentication ( requestContext ) ;
310302
311- expect ( requestContext . getHeaders ( ) ) . to . not . be . undefined ;
312- expect ( requestContext . getHeaders ( ) [ 'Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
303+ strictEqual ( requestContext . getHeaders ( ) ?. [ 'Authorization' ] , `Bearer ${ token } ` ) ;
313304 } ) ;
314305} ) ;
0 commit comments