Handle empty passwords in URL credentials

Closes #242
This commit is contained in:
Jakub Roztocil 2014-07-18 13:38:33 +02:00
parent 0f96348fd1
commit ca36f1de04
3 changed files with 21 additions and 3 deletions

View File

@ -1272,10 +1272,11 @@ Changelog
* Added ``--cert`` and ``--certkey`` parameters to specify a client side * Added ``--cert`` and ``--certkey`` parameters to specify a client side
certificate and private key for SSL certificate and private key for SSL
* Improved unicode support. * Improved unicode support.
* Fixed ``User-Agent`` overwriting when used within a session.
* Switched from ``unittest`` to ``pytest``. * Switched from ``unittest`` to ``pytest``.
* Various test suite improvements. * Various test suite improvements.
* Added `CONTRIBUTING`_. * 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) * `0.8.0`_ (2014-01-25)
* Added ``field=@file.txt`` and ``field:=@file.json`` for embedding * Added ``field=@file.txt`` and ``field:=@file.json`` for embedding
the contents of text and JSON files into request data. the contents of text and JSON files into request data.

View File

@ -211,7 +211,8 @@ class Parser(ArgumentParser):
elif url.username is not None: elif url.username is not None:
# Handle http://username:password@hostname/ # Handle http://username:password@hostname/
username, password = url.username, url.password username = url.username
password = url.password or ''
self.args.auth = AuthCredentials( self.args.auth = AuthCredentials(
key=username, key=username,
value=password, value=password,

View File

@ -2,8 +2,9 @@
import requests import requests
import pytest import pytest
from utils import http, add_auth, HTTP_OK from utils import http, add_auth, HTTP_OK, TestEnvironment
import httpie.input import httpie.input
import httpie.cli
class TestAuth: class TestAuth:
@ -44,3 +45,18 @@ class TestAuth:
r = http('--auth=user:password', 'GET', url) r = http('--auth=user:password', 'GET', url)
assert HTTP_OK in r assert HTTP_OK in r
assert r.json == {'authenticated': True, 'user': 'user'} 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 == ''