Skip to content

Commit 003d375

Browse files
committed
bugfix: authinfo file
1 parent 1b14589 commit 003d375

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
Unreleased
33
----------
44

5-
-
5+
-
6+
7+
8+
v1.1.1 (2019-8-6)
9+
-----------------
10+
**Bugfixes**
11+
- Fixed an issue where usernames were not parsed correctly from .authinfo files, resulting in failed logins.
12+
613

714
v1.1.0 (2019-8-5)
815
-----------------

src/sasctl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
55
# SPDX-License-Identifier: Apache-2.0
66

7-
__version__ = '1.1.0'
7+
__version__ = '1.1.1'
88
__author__ = 'SAS'
99
__credits__ = ['Yi Jian Ching, Lucas De Paula, Peter Tobac, Chris Toth, Jon '
1010
'Walker']

src/sasctl/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ def __init__(self, hostname,
304304
if 'swat' in sys.modules:
305305
auth = swat.utils.authinfo.query_authinfo(domain, user=username,
306306
path=authinfo)
307-
self._settings['username'], self._settings[
308-
'password'] = auth.get('username'), auth.get('password')
307+
self._settings['username'] = auth.get('user')
308+
self._settings['password'] = auth.get('password')
309309

310310
# Not able to load credentials using SWAT. Try Netrc.
311311
# TODO: IF a username was specified, verify that the credentials found

tests/unit/test_session.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,49 @@ def test_session_from_url():
3333
assert s.hostname == 'example.com'
3434
assert s._settings['protocol'] == 'http'
3535

36+
37+
def test_from_authinfo(tmpdir_factory):
38+
filename = str(tmpdir_factory.mktemp('tmp').join('authinfo'))
39+
40+
HOSTNAME = 'example.com'
41+
USERNAME = 'BlackKnight'
42+
PASSWORD = 'iaminvincible!'
43+
44+
with open(filename, 'w') as f:
45+
f.write('machine %s login %s password %s'
46+
% (HOSTNAME, USERNAME, PASSWORD))
47+
48+
# Get username & password from matching hostname
49+
with mock.patch('sasctl.core.Session.get_token'):
50+
s = Session('http://example.com', authinfo=filename)
51+
assert s.hostname == HOSTNAME
52+
assert s.username == USERNAME
53+
assert s._settings['password'] == PASSWORD
54+
55+
56+
with open(filename, 'w') as f:
57+
f.write('host %s user %s password %s'
58+
% (HOSTNAME, USERNAME, PASSWORD))
59+
60+
with mock.patch('sasctl.core.Session.get_token'):
61+
s = Session('http://example.com', authinfo=filename)
62+
assert s.hostname == HOSTNAME
63+
assert s.username == USERNAME
64+
assert s._settings['password'] == PASSWORD
65+
66+
with open(filename, 'w') as f:
67+
f.write('host %s user %s password %s\n'
68+
% (HOSTNAME, 'Arthur', 'kingofthebrittons'))
69+
f.write('host %s user %s password %s\n'
70+
% (HOSTNAME, USERNAME, PASSWORD))
71+
72+
with mock.patch('sasctl.core.Session.get_token'):
73+
s = Session('http://example.com', username=USERNAME, authinfo=filename)
74+
assert s.hostname == HOSTNAME
75+
assert s.username == USERNAME
76+
assert s._settings['password'] == PASSWORD
77+
78+
3679
def test_new_session(missing_packages):
3780
HOST = 'example.com'
3881
USERNAME = 'user'

0 commit comments

Comments
 (0)