@@ -243,13 +243,12 @@ describe('Service', function() {
243243 } ) ;
244244
245245 describe ( '#exchangeGrant_()' , function ( ) {
246- var getValueCaseInsensitive_ = OAuth2 . getValueCaseInsensitive_ ;
246+ var witLowerCaseKeys_ = OAuth2 . witLowerCaseKeys_ ;
247247
248248 it ( 'should not set auth header if the grant type is not client_credentials' ,
249249 function ( done ) {
250250 mocks . UrlFetchApp . resultFunction = function ( url , urlOptions ) {
251- assert . isUndefined (
252- getValueCaseInsensitive_ ( urlOptions . headers , 'Authorization' ) ) ;
251+ assert . isUndefined ( witLowerCaseKeys_ ( urlOptions . headers ) . authorization ) ;
253252 done ( ) ;
254253 } ;
255254 var service = OAuth2 . createService ( 'test' )
@@ -261,8 +260,7 @@ describe('Service', function() {
261260 it ( 'should not set auth header if the client ID is not set' ,
262261 function ( done ) {
263262 mocks . UrlFetchApp . resultFunction = function ( url , urlOptions ) {
264- assert . isUndefined (
265- getValueCaseInsensitive_ ( urlOptions . headers , 'Authorization' ) ) ;
263+ assert . isUndefined ( witLowerCaseKeys_ ( urlOptions . headers ) . authorization ) ;
266264 done ( ) ;
267265 } ;
268266 var service = OAuth2 . createService ( 'test' )
@@ -274,8 +272,7 @@ describe('Service', function() {
274272 it ( 'should not set auth header if the client secret is not set' ,
275273 function ( done ) {
276274 mocks . UrlFetchApp . resultFunction = function ( url , urlOptions ) {
277- assert . isUndefined (
278- getValueCaseInsensitive_ ( urlOptions . headers , 'Authorization' ) ) ;
275+ assert . isUndefined ( witLowerCaseKeys_ ( urlOptions . headers ) . authorization ) ;
279276 done ( ) ;
280277 } ;
281278 var service = OAuth2 . createService ( 'test' )
@@ -288,7 +285,8 @@ describe('Service', function() {
288285 it ( 'should not set auth header if it is already set' ,
289286 function ( done ) {
290287 mocks . UrlFetchApp . resultFunction = function ( url , urlOptions ) {
291- assert . equal ( urlOptions . headers . Authorization , 'something' ) ;
288+ assert . equal ( witLowerCaseKeys_ ( urlOptions . headers ) . authorization ,
289+ 'something' ) ;
292290 done ( ) ;
293291 } ;
294292 var service = OAuth2 . createService ( 'test' )
@@ -297,7 +295,7 @@ describe('Service', function() {
297295 . setClientId ( 'abc' )
298296 . setClientSecret ( 'def' )
299297 . setTokenHeaders ( {
300- Authorization : 'something'
298+ authorization : 'something'
301299 } ) ;
302300 service . exchangeGrant_ ( ) ;
303301 } ) ;
@@ -306,7 +304,8 @@ describe('Service', function() {
306304 'the client ID and client secret are set and the authorization header' +
307305 'is not already set' , function ( done ) {
308306 mocks . UrlFetchApp . resultFunction = function ( url , urlOptions ) {
309- assert . equal ( urlOptions . headers . Authorization , 'Basic YWJjOmRlZg==' ) ;
307+ assert . equal ( witLowerCaseKeys_ ( urlOptions . headers ) . authorization ,
308+ 'Basic YWJjOmRlZg==' ) ;
310309 done ( ) ;
311310 } ;
312311 var service = OAuth2 . createService ( 'test' )
@@ -337,34 +336,38 @@ describe('Utilities', function() {
337336 } ) ;
338337 } ) ;
339338
340- describe ( '#getValueCaseInsensitive_()' , function ( ) {
341- var getValueCaseInsensitive_ = OAuth2 . getValueCaseInsensitive_ ;
342-
343- it ( 'should find identical keys' , function ( ) {
344- assert . isTrue ( getValueCaseInsensitive_ ( { 'a' : true } , 'a' ) ) ;
345- assert . isTrue ( getValueCaseInsensitive_ ( { 'A' : true } , 'A' ) ) ;
346- assert . isTrue ( getValueCaseInsensitive_ ( { 'Ab' : true } , 'Ab' ) ) ;
347- } ) ;
348-
349- it ( 'should find matching keys of different cases' , function ( ) {
350- assert . isTrue ( getValueCaseInsensitive_ ( { 'a' : true } , 'A' ) ) ;
351- assert . isTrue ( getValueCaseInsensitive_ ( { 'A' : true } , 'a' ) ) ;
352- assert . isTrue ( getValueCaseInsensitive_ ( { 'Ab' : true } , 'aB' ) ) ;
353- assert . isTrue ( getValueCaseInsensitive_ ( { 'a2' : true } , 'A2' ) ) ;
339+ describe ( '#witLowerCaseKeys_()' , function ( ) {
340+ var witLowerCaseKeys_ = OAuth2 . witLowerCaseKeys_ ;
341+ var data = {
342+ 'a' : true ,
343+ 'A' : true ,
344+ 'B' : true ,
345+ 'Cc' : true ,
346+ 'D2' : true ,
347+ 'E!@#' : true
348+ } ;
349+ var lowerCaseData = witLowerCaseKeys_ ( data ) ;
350+
351+ it ( 'should contain lower-case keys' , function ( ) {
352+ assert . isTrue ( lowerCaseData [ 'a' ] ) ;
353+ assert . isTrue ( lowerCaseData [ 'b' ] ) ;
354+ assert . isTrue ( lowerCaseData [ 'cc' ] ) ;
355+ assert . isTrue ( lowerCaseData [ 'd2' ] ) ;
356+ assert . isTrue ( lowerCaseData [ 'e!@#' ] ) ;
354357 } ) ;
355358
356- it ( 'should work with non-alphabetic keys' , function ( ) {
357- assert . isTrue ( getValueCaseInsensitive_ ( { 'A2' : true } , 'a2' ) ) ;
358- assert . isTrue ( getValueCaseInsensitive_ ( { '2' : true } , '2' ) ) ;
359- assert . isTrue ( getValueCaseInsensitive_ ( { 2 : true } , 2 ) ) ;
360- assert . isTrue ( getValueCaseInsensitive_ ( { '!@#' : true } , '!@#' ) ) ;
359+ it ( 'should not contain upper-case keys' , function ( ) {
360+ assert . isUndefined ( lowerCaseData [ 'A' ] ) ;
361+ assert . isUndefined ( lowerCaseData [ 'B' ] ) ;
362+ assert . isUndefined ( lowerCaseData [ 'Cc' ] ) ;
363+ assert . isUndefined ( lowerCaseData [ 'D2' ] ) ;
364+ assert . isUndefined ( lowerCaseData [ 'E!@#' ] ) ;
361365 } ) ;
362366
363- it ( 'should work null and undefined' , function ( ) {
364- assert . isUndefined ( getValueCaseInsensitive_ ( null , 'key' ) ) ;
365- assert . isUndefined ( getValueCaseInsensitive_ ( undefined , 'key' ) ) ;
366- assert . isUndefined ( getValueCaseInsensitive_ ( { 'a' : true } , null ) ) ;
367- assert . isUndefined ( getValueCaseInsensitive_ ( { 'a' : true } , undefined ) ) ;
367+ it ( 'should handle null, undefined, and empty objects' , function ( ) {
368+ assert . isNull ( witLowerCaseKeys_ ( null ) ) ;
369+ assert . isUndefined ( witLowerCaseKeys_ ( undefined ) ) ;
370+ assert . isEmpty ( witLowerCaseKeys_ ( { } ) ) ;
368371 } ) ;
369372 } ) ;
370373} ) ;
0 commit comments