Skip to content

Commit

Permalink
legacy repository: support redirected url
Browse files Browse the repository at this point in the history
  • Loading branch information
jpyams authored and finswimmer committed Jan 30, 2021
1 parent eca5ad8 commit 63a952e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
13 changes: 11 additions & 2 deletions poetry/repositories/legacy_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,17 @@ def _get(self, endpoint): # type: (str) -> Union[Page, None]

if response.status_code in (401, 403):
self._log(
"Authorization error accessing {url}".format(url=url), level="warn"
"Authorization error accessing {url}".format(url=response.url),
level="warn",
)
return

return Page(url, response.content, response.headers)
if response.url != url:
self._log(
"Response URL {response_url} differs from request URL {url}".format(
response_url=response.url, url=url
),
level="debug",
)

return Page(response.url, response.content, response.headers)
15 changes: 15 additions & 0 deletions tests/repositories/test_legacy_repository.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import shutil

import pytest
import requests

from poetry.core.packages import Dependency
from poetry.factory import Factory
Expand Down Expand Up @@ -332,3 +333,17 @@ def test_get_4xx_and_5xx_raises(http):
for endpoint in endpoints:
with pytest.raises(RepositoryError):
repo._get(endpoint)


def test_get_redirected_response_url(http, monkeypatch):
repo = MockHttpRepository({"/foo": 200}, http)
redirect_url = "http://legacy.redirect.bar"

def get_mock(url):
response = requests.Response()
response.status_code = 200
response.url = redirect_url + "/foo"
return response

monkeypatch.setattr(repo.session, "get", get_mock)
assert repo._get("/foo")._url == "http://legacy.redirect.bar/foo/"

0 comments on commit 63a952e

Please sign in to comment.