@@ -5,8 +5,10 @@ import { join } from 'path';
5
5
import { User , Cluster } from './config_types' ;
6
6
import { GoogleCloudPlatformAuth } from './gcp_auth' ;
7
7
import { KubeConfig } from './config' ;
8
+ import { HttpMethod , RequestContext } from './gen' ;
8
9
9
10
describe ( 'GoogleCloudPlatformAuth' , ( ) => {
11
+ const testUrl1 = 'https://test-gcp.com' ;
10
12
var auth : GoogleCloudPlatformAuth ;
11
13
beforeEach ( ( ) => {
12
14
auth = new GoogleCloudPlatformAuth ( ) ;
@@ -53,18 +55,18 @@ describe('GoogleCloudPlatformAuth', () => {
53
55
} ,
54
56
} as User ,
55
57
) ;
56
- const opts = { } as requestlib . Options ;
58
+ let requestContext = new RequestContext ( testUrl1 , HttpMethod . GET )
57
59
58
- await config . applyToRequest ( opts ) ;
59
- expect ( opts . headers ) . to . not . be . undefined ;
60
- if ( opts . headers ) {
61
- expect ( opts . headers . Authorization ) . to . equal ( `Bearer ${ token } ` ) ;
60
+ await config . applySecurityAuthentication ( requestContext ) ;
61
+ expect ( requestContext . getHeaders ( ) ) . to . not . be . undefined ;
62
+ if ( requestContext . getHeaders ( ) ) {
63
+ expect ( requestContext . getHeaders ( ) [ ' Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
62
64
}
63
- opts . headers = [ ] ;
64
- opts . headers . Host = 'foo.com' ;
65
- await config . applyToRequest ( opts ) ;
66
- expect ( opts . headers . Authorization ) . to . equal ( `Bearer ${ token } ` ) ;
67
- } ) ;
65
+ requestContext . setUrl ( 'foo.com' )
66
+ // opts.headers.Host = 'foo.com';
67
+ await config . applySecurityAuthentication ( requestContext ) ;
68
+ expect ( requestContext . getHeaders ( ) [ ' Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
69
+ } ) ;
68
70
69
71
it ( 'should populate from auth provider without expirty' , async ( ) => {
70
72
const config = new KubeConfig ( ) ;
@@ -80,12 +82,12 @@ describe('GoogleCloudPlatformAuth', () => {
80
82
} ,
81
83
} as User ,
82
84
) ;
83
- const opts = { } as requestlib . Options ;
84
-
85
- await config . applyToRequest ( opts ) ;
86
- expect ( opts . headers ) . to . not . be . undefined ;
87
- if ( opts . headers ) {
88
- expect ( opts . headers . Authorization ) . to . equal ( `Bearer ${ token } ` ) ;
85
+ let requestContext = new RequestContext ( testUrl1 , HttpMethod . GET )
86
+
87
+ await config . applySecurityAuthentication ( requestContext ) ;
88
+ expect ( requestContext . getHeaders ( ) ) . to . not . be . undefined ;
89
+ if ( requestContext . getHeaders ( ) ) {
90
+ expect ( requestContext . getHeaders ( ) [ ' Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
89
91
}
90
92
} ) ;
91
93
@@ -103,10 +105,10 @@ describe('GoogleCloudPlatformAuth', () => {
103
105
} ,
104
106
} as User ,
105
107
) ;
106
- const opts = { } as requestlib . Options ;
108
+ let requestContext = new RequestContext ( testUrl1 , HttpMethod . GET )
107
109
108
- await config . applyToRequest ( opts ) ;
109
- expect ( opts . rejectUnauthorized ) . to . equal ( false ) ;
110
+ await config . applySecurityAuthentication ( requestContext ) ;
111
+ expect ( requestContext . getHeaders ( ) [ ' rejectUnauthorized' ] ) . to . equal ( false ) ;
110
112
} ) ;
111
113
112
114
it ( 'should not set rejectUnauthorized if skipTLSVerify is not set' , async ( ) => {
@@ -125,10 +127,10 @@ describe('GoogleCloudPlatformAuth', () => {
125
127
} ,
126
128
} as User ,
127
129
) ;
128
- const opts = { } as requestlib . Options ;
130
+ let requestContext = new RequestContext ( testUrl1 , HttpMethod . GET )
129
131
130
- await config . applyToRequest ( opts ) ;
131
- expect ( opts . rejectUnauthorized ) . to . equal ( undefined ) ;
132
+ await config . applySecurityAuthentication ( requestContext ) ;
133
+ expect ( requestContext . getHeaders ( ) [ ' rejectUnauthorized' ] ) . to . equal ( undefined ) ;
132
134
} ) ;
133
135
134
136
it ( 'should throw with expired token and no cmd' , ( ) => {
@@ -144,9 +146,9 @@ describe('GoogleCloudPlatformAuth', () => {
144
146
} ,
145
147
} as User ,
146
148
) ;
147
- const opts = { } as requestlib . Options ;
149
+ let requestContext = new RequestContext ( testUrl1 , HttpMethod . GET )
148
150
149
- return expect ( config . applyToRequest ( opts ) ) . to . eventually . be . rejectedWith ( 'Token is expired!' ) ;
151
+ return expect ( config . applySecurityAuthentication ( requestContext ) ) . to . eventually . be . rejectedWith ( 'Token is expired!' ) ;
150
152
} ) ;
151
153
152
154
it ( 'should throw with bad command' , ( ) => {
@@ -164,8 +166,8 @@ describe('GoogleCloudPlatformAuth', () => {
164
166
} ,
165
167
} as User ,
166
168
) ;
167
- const opts = { } as requestlib . Options ;
168
- return expect ( config . applyToRequest ( opts ) ) . to . eventually . be . rejectedWith ( / F a i l e d t o r e f r e s h t o k e n / ) ;
169
+ let requestContext = new RequestContext ( testUrl1 , HttpMethod . GET )
170
+ return expect ( config . applySecurityAuthentication ( requestContext ) ) . to . eventually . be . rejectedWith ( / F a i l e d t o r e f r e s h t o k e n / ) ;
169
171
} ) ;
170
172
171
173
it ( 'should exec with expired token' , async ( ) => {
@@ -191,11 +193,11 @@ describe('GoogleCloudPlatformAuth', () => {
191
193
} ,
192
194
} as User ,
193
195
) ;
194
- const opts = { } as requestlib . Options ;
195
- await config . applyToRequest ( opts ) ;
196
- expect ( opts . headers ) . to . not . be . undefined ;
197
- if ( opts . headers ) {
198
- expect ( opts . headers . Authorization ) . to . equal ( `Bearer ${ token } ` ) ;
196
+ let requestContext = new RequestContext ( testUrl1 , HttpMethod . GET )
197
+ await config . applySecurityAuthentication ( requestContext ) ;
198
+ expect ( requestContext . getHeaders ( ) ) . to . not . be . undefined ;
199
+ if ( requestContext . getHeaders ( ) ) {
200
+ expect ( requestContext . getHeaders ( ) [ ' Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
199
201
}
200
202
} ) ;
201
203
it ( 'should exec without access-token' , async ( ) => {
@@ -220,11 +222,11 @@ describe('GoogleCloudPlatformAuth', () => {
220
222
} ,
221
223
} as User ,
222
224
) ;
223
- const opts = { } as requestlib . Options ;
224
- await config . applyToRequest ( opts ) ;
225
- expect ( opts . headers ) . to . not . be . undefined ;
226
- if ( opts . headers ) {
227
- expect ( opts . headers . Authorization ) . to . equal ( `Bearer ${ token } ` ) ;
225
+ let requestContext = new RequestContext ( testUrl1 , HttpMethod . GET )
226
+ await config . applySecurityAuthentication ( requestContext ) ;
227
+ expect ( requestContext . getHeaders ( ) ) . to . not . be . undefined ;
228
+ if ( requestContext . getHeaders ( ) ) {
229
+ expect ( requestContext . getHeaders ( ) [ ' Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
228
230
}
229
231
} ) ;
230
232
it ( 'should exec without access-token' , async ( ) => {
@@ -249,11 +251,11 @@ describe('GoogleCloudPlatformAuth', () => {
249
251
} ,
250
252
} as User ,
251
253
) ;
252
- const opts = { } as requestlib . Options ;
253
- await config . applyToRequest ( opts ) ;
254
- expect ( opts . headers ) . to . not . be . undefined ;
255
- if ( opts . headers ) {
256
- expect ( opts . headers . Authorization ) . to . equal ( `Bearer ${ token } ` ) ;
254
+ let requestContext = new RequestContext ( testUrl1 , HttpMethod . GET )
255
+ await config . applySecurityAuthentication ( requestContext ) ;
256
+ expect ( requestContext . getHeaders ( ) ) . to . not . be . undefined ;
257
+ if ( requestContext . getHeaders ( ) ) {
258
+ expect ( requestContext . getHeaders ( ) [ ' Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
257
259
}
258
260
} ) ;
259
261
it ( 'should exec succesfully with spaces in cmd' , async ( ) => {
@@ -278,11 +280,11 @@ describe('GoogleCloudPlatformAuth', () => {
278
280
} ,
279
281
} as User ,
280
282
) ;
281
- const opts = { } as requestlib . Options ;
282
- await config . applyToRequest ( opts ) ;
283
- expect ( opts . headers ) . to . not . be . undefined ;
284
- if ( opts . headers ) {
285
- expect ( opts . headers . Authorization ) . to . equal ( `Bearer ${ token } ` ) ;
283
+ let requestContext = new RequestContext ( testUrl1 , HttpMethod . GET )
284
+ await config . applySecurityAuthentication ( requestContext ) ;
285
+ expect ( requestContext . getHeaders ( ) ) . to . not . be . undefined ;
286
+ if ( requestContext . getHeaders ( ) ) {
287
+ expect ( requestContext . getHeaders ( ) [ ' Authorization' ] ) . to . equal ( `Bearer ${ token } ` ) ;
286
288
}
287
289
} ) ;
288
290
} ) ;
0 commit comments