@@ -29,7 +29,7 @@ const tokenPath = `${BASE_PATH}/instance/service-accounts/default/token`;
2929function mockToken ( statusCode = 200 , scopes ?: string [ ] ) {
3030 let path = tokenPath ;
3131 if ( scopes && scopes . length > 0 ) {
32- path += '?' + qs . stringify ( { scopes} ) ;
32+ path += `?scopes= ${ encodeURIComponent ( scopes . join ( ',' ) ) } ` ;
3333 }
3434 return nock ( HOST_ADDRESS )
3535 . get ( path , undefined , { reqheaders : HEADERS } )
@@ -68,15 +68,25 @@ it('should get an access token for the first request', async () => {
6868 assert . strictEqual ( compute . credentials . access_token , 'abc123' ) ;
6969} ) ;
7070
71- it ( 'should include scopes when asking for the token' , async ( ) => {
71+ it ( 'should URI-encode and comma-separate scopes when fetching the token' , async ( ) => {
7272 const scopes = [
7373 'https://www.googleapis.com/reader' ,
7474 'https://www.googleapis.com/auth/plus' ,
7575 ] ;
76- const nockScopes = [ mockToken ( 200 , scopes ) , mockExample ( ) ] ;
76+
77+ const path = `${ tokenPath } ?scopes=${ encodeURIComponent ( scopes . join ( ',' ) ) } ` ;
78+
79+ const tokenFetchNock = nock ( HOST_ADDRESS )
80+ . get ( path , undefined , { reqheaders : HEADERS } )
81+ . reply ( 200 , { access_token : 'abc123' , expires_in : 10000 } , HEADERS ) ;
82+ const apiRequestNock = mockExample ( ) ;
83+
7784 const compute = new Compute ( { scopes} ) ;
7885 await compute . request ( { url} ) ;
79- nockScopes . forEach ( s => s . done ( ) ) ;
86+
87+ tokenFetchNock . done ( ) ;
88+ apiRequestNock . done ( ) ;
89+
8090 assert . strictEqual ( compute . credentials . access_token , 'abc123' ) ;
8191} ) ;
8292
0 commit comments