Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle empty passwords in URL credentials

Closes #242
  • Loading branch information...
commit ca36f1de04310de644857ebbea9c94984971ab7c 1 parent 0f96348
@jakubroztocil authored
Showing with 21 additions and 3 deletions.
  1. +2 −1  README.rst
  2. +2 −1  httpie/input.py
  3. +17 −1 tests/test_auth.py
View
3  README.rst
@@ -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.
View
3  httpie/input.py
@@ -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,
View
18 tests/test_auth.py
@@ -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:
@@ -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 == ''
+
Please sign in to comment.
Something went wrong with that request. Please try again.