File tree Expand file tree Collapse file tree
core/packages/google-auth-library-nodejs Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -297,10 +297,6 @@ export class GdchClient extends OAuth2Client {
297297
298298 private base64UrlEncode ( str : string | Buffer ) : string {
299299 const buffer = typeof str === 'string' ? Buffer . from ( str ) : str ;
300- return buffer
301- . toString ( 'base64' )
302- . replace ( / = / g, '' )
303- . replace ( / \+ / g, '-' )
304- . replace ( / \/ / g, '_' ) ;
300+ return buffer . toString ( 'base64url' ) ;
305301 }
306302}
Original file line number Diff line number Diff line change @@ -484,4 +484,24 @@ describe('GdchClient', () => {
484484 } ) ;
485485 scope . done ( ) ;
486486 } ) ;
487+
488+ describe ( 'base64UrlEncode' , ( ) => {
489+ it ( 'should correctly encode strings and buffers in base64url format' , ( ) => {
490+ const client = new GdchClient ( ) ;
491+ const testCases = [
492+ { input : 'hello world' , expected : 'aGVsbG8gd29ybGQ' } ,
493+ { input : 'foo bar baz' , expected : 'Zm9vIGJhciBiYXo' } ,
494+ { input : 'this is a test' , expected : 'dGhpcyBpcyBhIHRlc3Q' } ,
495+ { input : 'n>?' , expected : 'bj4_' } ,
496+ { input : 'n>~' , expected : 'bj5-' } ,
497+ ] ;
498+
499+ for ( const tc of testCases ) {
500+ const stringResult = ( client as any ) . base64UrlEncode ( tc . input ) ;
501+ const bufferResult = ( client as any ) . base64UrlEncode ( Buffer . from ( tc . input ) ) ;
502+ assert . strictEqual ( stringResult , tc . expected ) ;
503+ assert . strictEqual ( bufferResult , tc . expected ) ;
504+ }
505+ } ) ;
506+ } ) ;
487507} ) ;
You can’t perform that action at this time.
0 commit comments