Skip to content
Myr

Merge pull request #3673 from klimenko-forks/auth-unicode

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Enable unicode in basic http auth

authored by Cory Benfield · committed by GitHub · parents 22ec73d, 005f93f · Browse files · 2 files+29 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+29 added−4 removed

  • tests:+22 added−3 removed
  • other:+7 added−1 removed

2 files+29 added−4 removed

modified:requests/auth.py+7 added-1 removed
25 unmodified lines
262728def _basic_auth_str(username, password):29 """Returns a Basic Auth string."""30 31 if isinstance(username, str):32 username = username.encode('latin1')3334 if isinstance(password, str):35 password = password.encode('latin1')3637 authstr = 'Basic ' + to_native_string(32 b64encode(('%s:%s' % (username, password)).encode('latin1')).strip()38 b64encode(b':'.join((username, password))).strip()39 )4041 return authstr42
217 unmodified lines
modified:tests/test_requests.py+22 added-3 removed
479 unmodified lines
480 r = s.get(url)481 assert r.status_code == 200482483 @pytest.mark.parametrize(484 'username, password', (485 ('user', 'pass'),486 (u'имя'.encode('utf-8'), u'пароль'.encode('utf-8')),487 ))488 def test_set_basicauth(self, httpbin, username, password):489 auth = (username, password)490 url = httpbin('get')491492 r = requests.Request('GET', url, auth=auth)493 p = r.prepare()494495 assert p.headers['Authorization'] == _basic_auth_str(username, password)496497 @pytest.mark.parametrize(498 'url, exception', (499 # Connecting to an unknown domain should raise a ConnectionError500 ('http://doesnotexist.google.com', ConnectionError),501 # Connecting to an invalid port should raise a ConnectionError
1084 unmodified lines
1586 url = httpbin('redirect/1')1587 self._patch_adapter_gzipped_redirect(s, url)1588 s.get(url)15891590 @pytest.mark.parametrize(1591 'username, password, auth_str', (1592 ('test', 'test', 'Basic dGVzdDp0ZXN0'),1593 (u'имя'.encode('utf-8'), u'пароль'.encode('utf-8'), 'Basic 0LjQvNGPOtC/0LDRgNC+0LvRjA=='),1594 ))1576 def test_basic_auth_str_is_always_native(self):1577 s = _basic_auth_str("test", "test")1595 def test_basic_auth_str_is_always_native(self, username, password, auth_str):1596 s = _basic_auth_str(username, password)1597 assert isinstance(s, builtin_str)1579 assert s == "Basic dGVzdDp0ZXN0"1598 assert s == auth_str15991600 def test_requests_history_is_saved(self, httpbin):1601 r = requests.get(httpbin('redirect/5'))1602 total = r.history[-1].history
574 unmodified lines