Skip to content

Commit e3d8e60

Browse files
authored
Merge pull request #370 from ASFHyP3/fix-non-asf-host-token
Do not update cookie domain for non-asf hosts when token is given
2 parents dce89bc + a6b3991 commit e3d8e60

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/)
77
and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## [7.7.2]
10+
11+
### Fixed
12+
* `HyP3.__init__` no longer attempts to update the domain of the `asf-urs` cookie for non-`.asf.alaska.edu` API URLs when the `token` parameter is given. Fixes https://github.com/ASFHyP3/hyp3-sdk/issues/369
13+
914
## [7.7.1]
1015

1116
### Changed

src/hyp3_sdk/hyp3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __init__(
7070

7171
hostname = urlsplit(self.url).hostname
7272
assert hostname is not None
73-
if not hostname.endswith('.asf.alaska.edu'):
73+
if not hostname.endswith('.asf.alaska.edu') and 'asf-urs' in self.session.cookies:
7474
self.session.cookies.set('asf-urs', self.session.cookies['asf-urs'], domain=hostname)
7575

7676
def _get_endpoint_url(self, endpoint: str) -> str:

tests/conftest.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@
1414
@pytest.fixture(autouse=True)
1515
def get_mock_hyp3():
1616
def mock_get_authenticated_session(username, password, token):
17-
session = requests.Session()
18-
session.cookies.set('asf-urs', 'test-cookie', domain='.asf.alaska.edu')
19-
return session
17+
s = requests.Session()
2018

21-
def default_hyp3(api_url: str = 'https://dummy-api.asf.alaska.edu'):
19+
if token is not None:
20+
s.headers.update({'Authorization': f'Bearer {token}'})
21+
return s
22+
23+
s.cookies.set('asf-urs', 'test-cookie', domain='.asf.alaska.edu')
24+
return s
25+
26+
def mock_hyp3(api_url: str = 'https://dummy-api.asf.alaska.edu', token: str | None = None):
2227
with patch('hyp3_sdk.util.get_authenticated_session', mock_get_authenticated_session):
23-
return HyP3(api_url=api_url)
28+
return HyP3(api_url=api_url, token=token)
2429

25-
return default_hyp3
30+
return mock_hyp3
2631

2732

2833
@pytest.fixture(autouse=True)

tests/test_hyp3.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,11 @@ def test_update_cookie(get_mock_hyp3):
608608
assert api.session.cookies.get('asf-urs', domain='.asf.alaska.edu') == 'test-cookie'
609609
assert api.session.cookies.get('asf-urs', domain='foo.example.com') == 'test-cookie'
610610

611+
api = get_mock_hyp3(api_url='https://foo.example.com:8000/api', token='test-token')
612+
assert api.session.headers['Authorization'] == 'Bearer test-token'
613+
assert api.session.cookies.get('asf-urs', domain='.asf.alaska.edu') is None
614+
assert api.session.cookies.get('asf-urs', domain='foo.example.com') is None
615+
611616
api = get_mock_hyp3(api_url='https://foo.asf.alaska.edu:8000/api')
612617
assert api.session.cookies.get('asf-urs', domain='.asf.alaska.edu') == 'test-cookie'
613618
assert api.session.cookies.get('asf-urs', domain='foo.asf.alaska.edu') is None

0 commit comments

Comments
 (0)