@@ -789,9 +789,9 @@ def test_retry_config_external():
789
789
790
790
791
791
@responses .activate
792
- def test_redirect_ibm_to_ibm_success ():
793
- url_from = 'http ://region1.cloud.ibm.com/'
794
- url_to = 'http ://region2.cloud.ibm.com/'
792
+ def test_redirect_ibm_to_ibm ():
793
+ url_from = 'https ://region1.cloud.ibm.com/'
794
+ url_to = 'https ://region2.cloud.ibm.com/'
795
795
796
796
safe_headers = {
797
797
'Authorization' : 'foo' ,
@@ -822,9 +822,9 @@ def test_redirect_ibm_to_ibm_success():
822
822
823
823
824
824
@responses .activate
825
- def test_redirect_not_ibm_to_ibm_fail ():
826
- url_from = 'http ://region1.notcloud.ibm.com/'
827
- url_to = 'http ://region2.cloud.ibm.com/'
825
+ def test_redirect_not_ibm_to_ibm ():
826
+ url_from = 'https ://region1.notcloud.ibm.com/'
827
+ url_to = 'https ://region2.cloud.ibm.com/'
828
828
829
829
safe_headers = {
830
830
'Authorization' : 'foo' ,
@@ -855,9 +855,9 @@ def test_redirect_not_ibm_to_ibm_fail():
855
855
856
856
857
857
@responses .activate
858
- def test_redirect_ibm_to_not_ibm_fail ():
859
- url_from = 'http ://region1.cloud.ibm.com/'
860
- url_to = 'http ://region2.notcloud.ibm.com/'
858
+ def test_redirect_ibm_to_not_ibm ():
859
+ url_from = 'https ://region1.cloud.ibm.com/'
860
+ url_to = 'https ://region2.notcloud.ibm.com/'
861
861
862
862
safe_headers = {
863
863
'Authorization' : 'foo' ,
@@ -888,9 +888,9 @@ def test_redirect_ibm_to_not_ibm_fail():
888
888
889
889
890
890
@responses .activate
891
- def test_redirect_not_ibm_to_not_ibm_fail ():
892
- url_from = 'http ://region1.notcloud.ibm.com/'
893
- url_to = 'http ://region2.notcloud.ibm.com/'
891
+ def test_redirect_not_ibm_to_not_ibm ():
892
+ url_from = 'https ://region1.notcloud.ibm.com/'
893
+ url_to = 'https ://region2.notcloud.ibm.com/'
894
894
895
895
safe_headers = {
896
896
'Authorization' : 'foo' ,
@@ -921,7 +921,73 @@ def test_redirect_not_ibm_to_not_ibm_fail():
921
921
922
922
923
923
@responses .activate
924
- def test_redirect_ibm_to_ibm_exhausted_fail ():
924
+ def test_redirect_ibm_same_host ():
925
+ url_from = 'https://region1.cloud.ibm.com/'
926
+ url_to = 'https://region1.cloud.ibm.com/'
927
+
928
+ safe_headers = {
929
+ 'Authorization' : 'foo' ,
930
+ 'WWW-Authenticate' : 'bar' ,
931
+ 'Cookie' : 'baz' ,
932
+ 'Cookie2' : 'baz2' ,
933
+ }
934
+
935
+ responses .add (
936
+ responses .GET , url_from , status = 302 , adding_headers = {'Location' : url_to }, body = 'just about to redirect'
937
+ )
938
+ responses .add (responses .GET , url_to , status = 200 , body = 'successfully redirected' )
939
+
940
+ service = BaseService (service_url = url_from , authenticator = NoAuthAuthenticator ())
941
+
942
+ prepped = service .prepare_request ('GET' , '' , headers = safe_headers )
943
+ response = service .send (prepped )
944
+ result = response .get_result ()
945
+
946
+ assert result .status_code == 200
947
+ assert result .url == url_to
948
+ assert result .text == 'successfully redirected'
949
+
950
+ # Make sure the headers have been excluded from the 2nd, redirected request.
951
+ redirected_headers = responses .calls [1 ].request .headers
952
+ for key in safe_headers :
953
+ assert key in redirected_headers
954
+
955
+
956
+ @responses .activate
957
+ def test_redirect_not_ibm_same_host ():
958
+ url_from = 'https://region1.notcloud.ibm.com/'
959
+ url_to = 'https://region1.notcloud.ibm.com/'
960
+
961
+ safe_headers = {
962
+ 'Authorization' : 'foo' ,
963
+ 'WWW-Authenticate' : 'bar' ,
964
+ 'Cookie' : 'baz' ,
965
+ 'Cookie2' : 'baz2' ,
966
+ }
967
+
968
+ responses .add (
969
+ responses .GET , url_from , status = 302 , adding_headers = {'Location' : url_to }, body = 'just about to redirect'
970
+ )
971
+ responses .add (responses .GET , url_to , status = 200 , body = 'successfully redirected' )
972
+
973
+ service = BaseService (service_url = url_from , authenticator = NoAuthAuthenticator ())
974
+
975
+ prepped = service .prepare_request ('GET' , '' , headers = safe_headers )
976
+ response = service .send (prepped )
977
+ result = response .get_result ()
978
+
979
+ assert result .status_code == 200
980
+ assert result .url == url_to
981
+ assert result .text == 'successfully redirected'
982
+
983
+ # Make sure the headers have been excluded from the 2nd, redirected request.
984
+ redirected_headers = responses .calls [1 ].request .headers
985
+ for key in safe_headers :
986
+ assert key in redirected_headers
987
+
988
+
989
+ @responses .activate
990
+ def test_redirect_ibm_to_ibm_exhausted ():
925
991
redirects = 11
926
992
safe_headers = {
927
993
'Authorization' : 'foo' ,
@@ -933,13 +999,13 @@ def test_redirect_ibm_to_ibm_exhausted_fail():
933
999
for i in range (redirects ):
934
1000
responses .add (
935
1001
responses .GET ,
936
- f'http ://region{ i + 1 } .cloud.ibm.com/' ,
1002
+ f'https ://region{ i + 1 } .cloud.ibm.com/' ,
937
1003
status = 302 ,
938
- adding_headers = {'Location' : f'http ://region{ i + 2 } .cloud.ibm.com/' },
1004
+ adding_headers = {'Location' : f'https ://region{ i + 2 } .cloud.ibm.com/' },
939
1005
body = 'just about to redirect' ,
940
1006
)
941
1007
942
- service = BaseService (service_url = 'http ://region1.cloud.ibm.com/' , authenticator = NoAuthAuthenticator ())
1008
+ service = BaseService (service_url = 'https ://region1.cloud.ibm.com/' , authenticator = NoAuthAuthenticator ())
943
1009
944
1010
with pytest .raises (MaxRetryError ) as ex :
945
1011
prepped = service .prepare_request ('GET' , '' , headers = safe_headers )
0 commit comments