Skip to content

Commit

Permalink
Handle empty passwords in URL credentials
Browse files Browse the repository at this point in the history
Closes #242
  • Loading branch information
jkbrzt committed Jul 18, 2014
1 parent 0f96348 commit ca36f1d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.rst
Expand Up @@ -1272,10 +1272,11 @@ Changelog
* Added ``--cert`` and ``--certkey`` parameters to specify a client side
certificate and private key for SSL
* Improved unicode support.
* Fixed ``User-Agent`` overwriting when used within a session.
* Switched from ``unittest`` to ``pytest``.
* Various test suite improvements.
* Added `CONTRIBUTING`_.
* Fixed ``User-Agent`` overwriting when used within a session.
* Fixed handling of empty passwords in URL credentials.
* `0.8.0`_ (2014-01-25)
* Added ``field=@file.txt`` and ``field:=@file.json`` for embedding
the contents of text and JSON files into request data.
Expand Down
3 changes: 2 additions & 1 deletion httpie/input.py
Expand Up @@ -211,7 +211,8 @@ def _process_auth(self):

elif url.username is not None:
# Handle http://username:password@hostname/
username, password = url.username, url.password
username = url.username
password = url.password or ''
self.args.auth = AuthCredentials(
key=username,
value=password,
Expand Down
18 changes: 17 additions & 1 deletion tests/test_auth.py
Expand Up @@ -2,8 +2,9 @@
import requests
import pytest

from utils import http, add_auth, HTTP_OK
from utils import http, add_auth, HTTP_OK, TestEnvironment
import httpie.input
import httpie.cli


class TestAuth:
Expand Down Expand Up @@ -44,3 +45,18 @@ def test_credentials_in_url_auth_flag_has_priority(self, httpbin):
r = http('--auth=user:password', 'GET', url)
assert HTTP_OK in r
assert r.json == {'authenticated': True, 'user': 'user'}

@pytest.mark.parametrize('url', [
'username@example.org',
'username:@example.org',
])
def test_only_username_in_url(self, url):
"""
https://github.com/jakubroztocil/httpie/issues/242
"""
args = httpie.cli.parser.parse_args(args=[url], env=TestEnvironment())
assert args.auth
assert args.auth.key == 'username'
assert args.auth.value == ''

0 comments on commit ca36f1d

Please sign in to comment.