1
+ /* eslint-disable no-alert, no-console */
1
2
'use strict' ;
2
3
3
4
const requestWrapper = require ( '../../lib/requestwrapper' ) ;
4
5
requestWrapper . sendRequest = jest . fn ( ) ;
5
6
6
7
const IamTokenManagerV1 = require ( '../../iam-token-manager/v1' ) . IamTokenManagerV1 ;
7
8
9
+ const CLIENT_ID_SECRET_WARNING =
10
+ 'Warning: Client ID and Secret must BOTH be given, or the defaults will be used.' ;
11
+
8
12
describe ( 'iam_token_manager_v1' , function ( ) {
9
13
beforeEach ( ( ) => {
10
14
requestWrapper . sendRequest . mockReset ( ) ;
@@ -235,11 +239,18 @@ describe('iam_token_manager_v1', function() {
235
239
} ) ;
236
240
237
241
it ( 'should use the default Authorization header - clientid only via ctor' , function ( done ) {
242
+ jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
243
+
238
244
const instance = new IamTokenManagerV1 ( {
239
245
iamApikey : 'abcd-1234' ,
240
246
iamClientId : 'foo' ,
241
247
} ) ;
242
248
249
+ // verify warning was triggered
250
+ expect ( console . log ) . toHaveBeenCalled ( ) ;
251
+ expect ( console . log . mock . calls [ 0 ] [ 0 ] ) . toBe ( CLIENT_ID_SECRET_WARNING ) ;
252
+ console . log . mockRestore ( ) ;
253
+
243
254
requestWrapper . sendRequest . mockImplementation ( ( parameters , _callback ) => {
244
255
_callback ( ) ;
245
256
} ) ;
@@ -253,11 +264,17 @@ describe('iam_token_manager_v1', function() {
253
264
} ) ;
254
265
255
266
it ( 'should use the default Authorization header, secret only via ctor' , function ( done ) {
267
+ jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
256
268
const instance = new IamTokenManagerV1 ( {
257
269
iamApikey : 'abcd-1234' ,
258
270
iamSecret : 'bar' ,
259
271
} ) ;
260
272
273
+ // verify warning was triggered
274
+ expect ( console . log ) . toHaveBeenCalled ( ) ;
275
+ expect ( console . log . mock . calls [ 0 ] [ 0 ] ) . toBe ( CLIENT_ID_SECRET_WARNING ) ;
276
+ console . log . mockRestore ( ) ;
277
+
261
278
requestWrapper . sendRequest . mockImplementation ( ( parameters , _callback ) => {
262
279
_callback ( ) ;
263
280
} ) ;
@@ -294,8 +311,15 @@ describe('iam_token_manager_v1', function() {
294
311
iamApikey : 'abcd-1234' ,
295
312
} ) ;
296
313
314
+ jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
315
+
297
316
instance . setIamAuthorizationInfo ( 'foo' , null ) ;
298
317
318
+ // verify warning was triggered
319
+ expect ( console . log ) . toHaveBeenCalled ( ) ;
320
+ expect ( console . log . mock . calls [ 0 ] [ 0 ] ) . toBe ( CLIENT_ID_SECRET_WARNING ) ;
321
+ console . log . mockRestore ( ) ;
322
+
299
323
requestWrapper . sendRequest . mockImplementation ( ( parameters , _callback ) => {
300
324
_callback ( ) ;
301
325
} ) ;
@@ -308,14 +332,20 @@ describe('iam_token_manager_v1', function() {
308
332
} ) ;
309
333
} ) ;
310
334
311
- it ( 'should use the default Authorization header, secret only via ctor ' , function ( done ) {
335
+ it ( 'should use the default Authorization header, secret only via setter ' , function ( done ) {
312
336
const instance = new IamTokenManagerV1 ( {
313
337
iamApikey : 'abcd-1234' ,
314
- iamSecret : 'bar' ,
315
338
} ) ;
316
339
340
+ jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
341
+
317
342
instance . setIamAuthorizationInfo ( null , 'bar' ) ;
318
343
344
+ // verify warning was triggered
345
+ expect ( console . log ) . toHaveBeenCalled ( ) ;
346
+ expect ( console . log . mock . calls [ 0 ] [ 0 ] ) . toBe ( CLIENT_ID_SECRET_WARNING ) ;
347
+ console . log . mockRestore ( ) ;
348
+
319
349
requestWrapper . sendRequest . mockImplementation ( ( parameters , _callback ) => {
320
350
_callback ( ) ;
321
351
} ) ;
@@ -331,7 +361,6 @@ describe('iam_token_manager_v1', function() {
331
361
it ( 'should use the default Authorization header, nulls passed to setter' , function ( done ) {
332
362
const instance = new IamTokenManagerV1 ( {
333
363
iamApikey : 'abcd-1234' ,
334
- iamSecret : 'bar' ,
335
364
} ) ;
336
365
337
366
instance . setIamAuthorizationInfo ( null , null ) ;
0 commit comments