@@ -337,6 +337,66 @@ def test_redirect_auth_failure_r1
337
337
}
338
338
end
339
339
340
+ def test_redirect_without_request_specific_fields_hash
341
+ authorization_header = nil
342
+ redirected_authorization_header = nil
343
+ with_http { |srv , url |
344
+ srv . mount_proc ( "/r1/" , lambda { |req , res | res . status = 301 ; res [ "location" ] = "#{ url } /r2" ; authorization_header = req [ "Authorization" ] ; } )
345
+ srv . mount_proc ( "/r2/" , lambda { |req , res | redirected_authorization_header = req [ "Authorization" ] ; } )
346
+ URI . open ( "#{ url } /r1/" , "Authorization" => "dummy_token" ) { |f |
347
+ assert_equal ( "dummy_token" , authorization_header )
348
+ assert_equal ( "#{ url } /r2" , f . base_uri . to_s )
349
+ assert_equal ( "dummy_token" , redirected_authorization_header )
350
+ }
351
+ }
352
+ end
353
+
354
+ def test_redirect_with_request_specific_fields_hash
355
+ authorization_header = nil
356
+ redirected_authorization_header = "exposed_dummy_token"
357
+ with_http { |srv , url |
358
+ srv . mount_proc ( "/r1/" , lambda { |req , res | res . status = 301 ; res [ "location" ] = "#{ url } /r2" ; authorization_header = req [ "Authorization" ] ; } )
359
+ srv . mount_proc ( "/r2/" , lambda { |req , res | redirected_authorization_header = req [ "Authorization" ] ; } )
360
+ URI . open ( "#{ url } /r1/" , request_specific_fields : { "Authorization" => "dummy_token" } ) { |f |
361
+ assert_equal ( "dummy_token" , authorization_header )
362
+ assert_equal ( "#{ url } /r2" , f . base_uri . to_s )
363
+ assert_equal ( nil , redirected_authorization_header )
364
+ }
365
+ }
366
+ end
367
+
368
+ def test_redirect_with_request_specific_fields_proc
369
+ authorization_header = nil
370
+ redirected_authorization_header = nil
371
+
372
+ modify_authorization_header = Proc . new do |uri |
373
+ authorization_token = if uri . to_s . include? ( "/r1" )
374
+ "dummy_token"
375
+ else
376
+ "masked_dummy_token"
377
+ end
378
+ { "Authorization" => authorization_token }
379
+ end
380
+
381
+ with_http { |srv , url |
382
+ srv . mount_proc ( "/r1/" , lambda { |req , res | res . status = 301 ; res [ "location" ] = "#{ url } /r2" ; authorization_header = req [ "Authorization" ] } )
383
+ srv . mount_proc ( "/r2/" , lambda { |req , res | redirected_authorization_header = req [ "Authorization" ] ; } )
384
+ URI . open ( "#{ url } /r1/" , request_specific_fields : modify_authorization_header ) { |f |
385
+ assert_equal ( "dummy_token" , authorization_header )
386
+ assert_equal ( "#{ url } /r2" , f . base_uri . to_s )
387
+ assert_equal ( "masked_dummy_token" , redirected_authorization_header )
388
+ }
389
+ }
390
+ end
391
+
392
+ def test_redirect_with_invalid_request_specific_fields_format
393
+ with_http { |srv , url |
394
+ srv . mount_proc ( "/r1/" , lambda { |req , res | res . body = "r1" } )
395
+ exc = assert_raise ( ArgumentError ) { URI . open ( "#{ url } /r1/" , request_specific_fields : "dummy_token" ) { } }
396
+ assert_equal ( "Invalid request_specific_fields' format: dummy_token" , exc . message )
397
+ }
398
+ end
399
+
340
400
def test_max_redirects_success
341
401
with_http { |srv , url |
342
402
srv . mount_proc ( "/r1/" , lambda { |req , res | res . status = 301 ; res [ "location" ] = "#{ url } /r2" ; res . body = "r1" } )
0 commit comments