@@ -423,7 +423,7 @@ def request_handler(request: httpx.Request):
423423async def test_redirect_with_custom_scrubber ():
424424 """Test that custom scrubber can be provided and is used"""
425425
426- def custom_scrubber (headers , original_url , new_url ):
426+ def custom_scrubber (new_request , original_url ):
427427 # Custom logic: never remove headers
428428 pass
429429
@@ -457,110 +457,124 @@ def test_default_scrub_sensitive_headers_removes_on_host_change():
457457 """Test that default scrubber removes Authorization and Cookie when host changes"""
458458 from kiota_http .middleware .options .redirect_handler_option import default_scrub_sensitive_headers
459459
460- headers = httpx .Headers ({
461- AUTHORIZATION_HEADER : "Bearer token" ,
462- "Cookie" : "session=SECRET" ,
463- "Content-Type" : "application/json"
464- })
465460 original_url = httpx .URL ("https://example.com/v1/api" )
466- new_url = httpx .URL ("https://other.com/api" )
461+ new_request = httpx .Request (
462+ "GET" ,
463+ "https://other.com/api" ,
464+ headers = {
465+ AUTHORIZATION_HEADER : "Bearer token" ,
466+ "Cookie" : "session=SECRET" ,
467+ "Content-Type" : "application/json"
468+ }
469+ )
467470
468- default_scrub_sensitive_headers (headers , original_url , new_url )
471+ default_scrub_sensitive_headers (new_request , original_url )
469472
470- assert AUTHORIZATION_HEADER not in headers
471- assert "Cookie" not in headers
472- assert "Content-Type" in headers # Other headers should remain
473+ assert AUTHORIZATION_HEADER not in new_request . headers
474+ assert "Cookie" not in new_request . headers
475+ assert "Content-Type" in new_request . headers # Other headers should remain
473476
474477
475478def test_default_scrub_sensitive_headers_removes_on_scheme_change ():
476479 """Test that default scrubber removes Authorization and Cookie when scheme changes"""
477480 from kiota_http .middleware .options .redirect_handler_option import default_scrub_sensitive_headers
478481
479- headers = httpx .Headers ({
480- AUTHORIZATION_HEADER : "Bearer token" ,
481- "Cookie" : "session=SECRET" ,
482- "Content-Type" : "application/json"
483- })
484482 original_url = httpx .URL ("https://example.com/v1/api" )
485- new_url = httpx .URL ("http://example.com/v1/api" )
483+ new_request = httpx .Request (
484+ "GET" ,
485+ "http://example.com/v1/api" ,
486+ headers = {
487+ AUTHORIZATION_HEADER : "Bearer token" ,
488+ "Cookie" : "session=SECRET" ,
489+ "Content-Type" : "application/json"
490+ }
491+ )
486492
487- default_scrub_sensitive_headers (headers , original_url , new_url )
493+ default_scrub_sensitive_headers (new_request , original_url )
488494
489- assert AUTHORIZATION_HEADER not in headers
490- assert "Cookie" not in headers
491- assert "Content-Type" in headers
495+ assert AUTHORIZATION_HEADER not in new_request . headers
496+ assert "Cookie" not in new_request . headers
497+ assert "Content-Type" in new_request . headers
492498
493499
494500def test_default_scrub_sensitive_headers_keeps_on_same_origin ():
495501 """Test that default scrubber keeps headers when host and scheme are the same"""
496502 from kiota_http .middleware .options .redirect_handler_option import default_scrub_sensitive_headers
497503
498- headers = httpx .Headers ({
499- AUTHORIZATION_HEADER : "Bearer token" ,
500- "Cookie" : "session=SECRET" ,
501- "Content-Type" : "application/json"
502- })
503504 original_url = httpx .URL ("https://example.com/v1/api" )
504- new_url = httpx .URL ("https://example.com/v2/api" )
505+ new_request = httpx .Request (
506+ "GET" ,
507+ "https://example.com/v2/api" ,
508+ headers = {
509+ AUTHORIZATION_HEADER : "Bearer token" ,
510+ "Cookie" : "session=SECRET" ,
511+ "Content-Type" : "application/json"
512+ }
513+ )
505514
506- default_scrub_sensitive_headers (headers , original_url , new_url )
515+ default_scrub_sensitive_headers (new_request , original_url )
507516
508- assert AUTHORIZATION_HEADER in headers
509- assert "Cookie" in headers
510- assert "Content-Type" in headers
517+ assert AUTHORIZATION_HEADER in new_request . headers
518+ assert "Cookie" in new_request . headers
519+ assert "Content-Type" in new_request . headers
511520
512521
513522def test_default_scrub_sensitive_headers_removes_on_port_change ():
514523 """Test that default scrubber removes Authorization and Cookie when port changes"""
515524 from kiota_http .middleware .options .redirect_handler_option import default_scrub_sensitive_headers
516525
517- headers = httpx .Headers ({
518- AUTHORIZATION_HEADER : "Bearer token" ,
519- "Cookie" : "session=SECRET" ,
520- "Content-Type" : "application/json"
521- })
522526 original_url = httpx .URL ("http://example.org:8080/foo" )
523- new_url = httpx .URL ("http://example.org:9090/bar" )
527+ new_request = httpx .Request (
528+ "GET" ,
529+ "http://example.org:9090/bar" ,
530+ headers = {
531+ AUTHORIZATION_HEADER : "Bearer token" ,
532+ "Cookie" : "session=SECRET" ,
533+ "Content-Type" : "application/json"
534+ }
535+ )
524536
525- default_scrub_sensitive_headers (headers , original_url , new_url )
537+ default_scrub_sensitive_headers (new_request , original_url )
526538
527- assert AUTHORIZATION_HEADER not in headers
528- assert "Cookie" not in headers
529- assert "Content-Type" in headers # Other headers should remain
539+ assert AUTHORIZATION_HEADER not in new_request . headers
540+ assert "Cookie" not in new_request . headers
541+ assert "Content-Type" in new_request . headers # Other headers should remain
530542
531543
532544def test_default_scrub_sensitive_headers_keeps_on_same_port ():
533545 """Test that default scrubber keeps headers when port is the same"""
534546 from kiota_http .middleware .options .redirect_handler_option import default_scrub_sensitive_headers
535547
536- headers = httpx .Headers ({
537- AUTHORIZATION_HEADER : "Bearer token" ,
538- "Cookie" : "session=SECRET" ,
539- "Content-Type" : "application/json"
540- })
541548 original_url = httpx .URL ("http://example.org:8080/foo" )
542- new_url = httpx .URL ("http://example.org:8080/bar" )
549+ new_request = httpx .Request (
550+ "GET" ,
551+ "http://example.org:8080/bar" ,
552+ headers = {
553+ AUTHORIZATION_HEADER : "Bearer token" ,
554+ "Cookie" : "session=SECRET" ,
555+ "Content-Type" : "application/json"
556+ }
557+ )
543558
544- default_scrub_sensitive_headers (headers , original_url , new_url )
559+ default_scrub_sensitive_headers (new_request , original_url )
545560
546- assert AUTHORIZATION_HEADER in headers
547- assert "Cookie" in headers
548- assert "Content-Type" in headers
561+ assert AUTHORIZATION_HEADER in new_request . headers
562+ assert "Cookie" in new_request . headers
563+ assert "Content-Type" in new_request . headers
549564
550565
551566def test_default_scrub_sensitive_headers_handles_none_gracefully ():
552567 """Test that default scrubber handles None/empty inputs gracefully"""
553568 from kiota_http .middleware .options .redirect_handler_option import default_scrub_sensitive_headers
554569
555570 # Should not raise exceptions
556- default_scrub_sensitive_headers (None , httpx .URL (BASE_URL ), httpx .URL (BASE_URL ))
557- default_scrub_sensitive_headers (httpx .Headers (), None , httpx .URL (BASE_URL ))
558- default_scrub_sensitive_headers (httpx .Headers (), httpx .URL (BASE_URL ), None )
571+ default_scrub_sensitive_headers (None , httpx .URL (BASE_URL ))
572+ default_scrub_sensitive_headers (httpx .Request ("GET" , BASE_URL ), None )
559573
560574
561575def test_custom_scrub_sensitive_headers ():
562576 """Test that custom scrubber can be set on options"""
563- def custom_scrubber (headers , original_url , new_url ):
577+ def custom_scrubber (new_request , original_url ):
564578 # Custom logic
565579 pass
566580
0 commit comments