Skip to content

Commit b149648

Browse files
committed
chore: add tests for redirecting to the exact same domain
Signed-off-by: Norbert Biczo <[email protected]>
1 parent 885dbfb commit b149648

File tree

1 file changed

+71
-5
lines changed

1 file changed

+71
-5
lines changed

test/test_base_service.py

+71-5
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ def test_retry_config_external():
789789

790790

791791
@responses.activate
792-
def test_redirect_ibm_to_ibm_success():
792+
def test_redirect_ibm_to_ibm():
793793
url_from = 'http://region1.cloud.ibm.com/'
794794
url_to = 'http://region2.cloud.ibm.com/'
795795

@@ -822,7 +822,7 @@ def test_redirect_ibm_to_ibm_success():
822822

823823

824824
@responses.activate
825-
def test_redirect_not_ibm_to_ibm_fail():
825+
def test_redirect_not_ibm_to_ibm():
826826
url_from = 'http://region1.notcloud.ibm.com/'
827827
url_to = 'http://region2.cloud.ibm.com/'
828828

@@ -855,7 +855,7 @@ def test_redirect_not_ibm_to_ibm_fail():
855855

856856

857857
@responses.activate
858-
def test_redirect_ibm_to_not_ibm_fail():
858+
def test_redirect_ibm_to_not_ibm():
859859
url_from = 'http://region1.cloud.ibm.com/'
860860
url_to = 'http://region2.notcloud.ibm.com/'
861861

@@ -888,7 +888,7 @@ def test_redirect_ibm_to_not_ibm_fail():
888888

889889

890890
@responses.activate
891-
def test_redirect_not_ibm_to_not_ibm_fail():
891+
def test_redirect_not_ibm_to_not_ibm():
892892
url_from = 'http://region1.notcloud.ibm.com/'
893893
url_to = 'http://region2.notcloud.ibm.com/'
894894

@@ -921,7 +921,73 @@ def test_redirect_not_ibm_to_not_ibm_fail():
921921

922922

923923
@responses.activate
924-
def test_redirect_ibm_to_ibm_exhausted_fail():
924+
def test_redirect_ibm_same_host():
925+
url_from = 'http://region1.cloud.ibm.com/'
926+
url_to = 'http://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 = 'http://region1.notcloud.ibm.com/'
959+
url_to = 'http://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():
925991
redirects = 11
926992
safe_headers = {
927993
'Authorization': 'foo',

0 commit comments

Comments
 (0)