forked from extern/httpie-cli
Store prompted passwords in local sessions (#1239)
Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
This commit is contained in:
parent
05c02f0f39
commit
17ed3bb8c5
@ -296,6 +296,10 @@ class HTTPieArgumentParser(BaseHTTPieArgumentParser):
|
||||
' --ignore-stdin is set.'
|
||||
)
|
||||
credentials.prompt_password(url.netloc)
|
||||
|
||||
if (credentials.key and credentials.value):
|
||||
plugin.raw_auth = credentials.key + ":" + credentials.value
|
||||
|
||||
self.args.auth = plugin.get_auth(
|
||||
username=credentials.key,
|
||||
password=credentials.value,
|
||||
|
@ -15,6 +15,7 @@ from httpie.sessions import Session
|
||||
from httpie.utils import get_expired_cookies
|
||||
from .test_auth_plugins import basic_auth
|
||||
from .utils import HTTP_OK, MockEnvironment, http, mk_config_dir
|
||||
from base64 import b64encode
|
||||
|
||||
|
||||
class SessionTestBase:
|
||||
@ -298,8 +299,6 @@ class TestSession(SessionTestBase):
|
||||
assert f'Authorization: {header}' in r2
|
||||
plugin_manager.unregister(Plugin)
|
||||
|
||||
@mock.patch('httpie.cli.argtypes.AuthCredentials._getpass',
|
||||
new=lambda self, prompt: 'password')
|
||||
def test_auth_plugin_prompt_password_in_session(self, httpbin):
|
||||
self.start_session(httpbin)
|
||||
session_path = self.config_dir / 'test-session.json'
|
||||
@ -308,17 +307,22 @@ class TestSession(SessionTestBase):
|
||||
auth_type = 'test-prompted'
|
||||
|
||||
def get_auth(self, username=None, password=None):
|
||||
return basic_auth()
|
||||
basic_auth_header = "Basic " + b64encode(self.raw_auth.encode()).strip().decode('latin1')
|
||||
return basic_auth(basic_auth_header)
|
||||
|
||||
plugin_manager.register(Plugin)
|
||||
|
||||
r1 = http(
|
||||
'--session', str(session_path),
|
||||
httpbin + '/basic-auth/user/password',
|
||||
'--auth-type',
|
||||
Plugin.auth_type,
|
||||
'--auth', 'user:',
|
||||
)
|
||||
with mock.patch(
|
||||
'httpie.cli.argtypes.AuthCredentials._getpass',
|
||||
new=lambda self, prompt: 'password'
|
||||
):
|
||||
r1 = http(
|
||||
'--session', str(session_path),
|
||||
httpbin + '/basic-auth/user/password',
|
||||
'--auth-type',
|
||||
Plugin.auth_type,
|
||||
'--auth', 'user',
|
||||
)
|
||||
|
||||
r2 = http(
|
||||
'--session', str(session_path),
|
||||
@ -326,6 +330,13 @@ class TestSession(SessionTestBase):
|
||||
)
|
||||
assert HTTP_OK in r1
|
||||
assert HTTP_OK in r2
|
||||
|
||||
# additional test for issue: https://github.com/httpie/httpie/issues/1098
|
||||
with open(session_path) as session_file:
|
||||
session_file_lines = ''.join(session_file.readlines())
|
||||
assert "\"type\": \"test-prompted\"" in session_file_lines
|
||||
assert "\"raw_auth\": \"user:password\"" in session_file_lines
|
||||
|
||||
plugin_manager.unregister(Plugin)
|
||||
|
||||
def test_auth_type_stored_in_session_file(self, httpbin):
|
||||
|
Loading…
Reference in New Issue
Block a user