Skip to content

Commit ecbb751

Browse files
authored
Allow empty string in auth (#283)
* Allow empty string in auth * @grahamalama review * Raise ValueError only if not empty
1 parent c3da083 commit ecbb751

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ This document describes changes between each past release.
77
10.11.0 (unreleased)
88
====================
99

10-
- Nothing changed yet.
10+
**Bug fixes**
11+
12+
- Fix breaking change introduced in previous version, accept empty string in ``auth`` parameter
1113

1214

1315
10.10.0 (2022-06-27)

kinto_http/session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ def create_session(server_url=None, auth=None, session=None, **kwargs):
3333
msg = "You need to either set session or auth + server_url"
3434
raise AttributeError(msg)
3535

36-
if auth is not None and isinstance(auth, str):
36+
if isinstance(auth, str):
3737
if ":" in auth:
3838
auth = tuple(auth.split(":", 1))
3939
elif "bearer" in auth.lower():
4040
# eg, "Bearer ghruhgrwyhg"
4141
_type, token = auth.split(" ", 1)
4242
auth = kinto_http.BearerTokenAuth(token, type=_type)
43-
else:
43+
elif auth: # not empty
4444
raise ValueError(
4545
"Unsupported `auth` parameter value. Must be a tuple() or string "
4646
"in the form of `user:pass` or `Bearer xyz`"

kinto_http/tests/test_session.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ def test_auth_can_be_passed_as_basic_header(session_setup: Tuple[MagicMock, Sess
227227
assert session.auth.token == "abcdef"
228228

229229

230+
def test_auth_cannot_be_an_empty_string(session_setup: Tuple[MagicMock, Session]):
231+
session = create_session(auth="")
232+
assert session.auth == ""
233+
234+
230235
def test_auth_cannot_be_an_arbitrary_string(session_setup: Tuple[MagicMock, Session]):
231236
with pytest.raises(ValueError) as exc:
232237
create_session(auth="Some abcdef")

0 commit comments

Comments
 (0)