File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ Unreleased
9
9
10
10
** Improvements**
11
11
- Added ` copy_analytic_store ` method to ` model_repository ` service
12
+ - ` AuthenticationError ` returned instead of ` HTTPError ` if session authentication fails.
12
13
13
14
14
15
v0.9.7 (2019-07-18)
Original file line number Diff line number Diff line change @@ -484,11 +484,29 @@ def _get_token_with_password(self):
484
484
data = data ,
485
485
headers = headers ,
486
486
auth = ('sas.ec' , '' ))
487
- r .raise_for_status ()
487
+
488
+ if r .status_code == 401 :
489
+ raise AuthenticationError ("Authentication failed for user '%s'." % username )
490
+ else :
491
+ r .raise_for_status ()
488
492
489
493
return r .json ().get ('access_token' )
490
494
491
495
def get_token (self ):
496
+ """Authenticates with the session host and retrieves an
497
+ authorization token for use by subsequent requests.
498
+
499
+ Returns
500
+ -------
501
+ str
502
+ a bearer token for :class:`HTTPBearerAuth`
503
+
504
+ Raises
505
+ ------
506
+ AuthenticationError
507
+ authentication with the host failed
508
+
509
+ """
492
510
username = self ._settings ['username' ]
493
511
password = self ._settings ['password' ]
494
512
@@ -888,3 +906,6 @@ class SasctlError(Exception):
888
906
889
907
class TimeoutError (SasctlError ):
890
908
pass
909
+
910
+ class AuthenticationError (SasctlError ):
911
+ pass
Original file line number Diff line number Diff line change @@ -218,7 +218,6 @@ def test_ssl_context():
218
218
219
219
220
220
def test_verify_ssl ():
221
-
222
221
with mock .patch ('sasctl.core.Session.get_token' , return_value = 'token' ):
223
222
# Should verify SSL by default
224
223
s = Session ('hostname' , 'username' , 'password' )
@@ -261,3 +260,13 @@ def test_kerberos():
261
260
262
261
s = Session ('hostname' , 'username@REALM' )
263
262
assert s .auth .token == 'token'
263
+
264
+ def test_authentication_failure ():
265
+ from sasctl .core import AuthenticationError
266
+
267
+ with mock .patch ('sasctl.core.Session.request' ) as request :
268
+ request .return_value .status_code = 401
269
+
270
+ with pytest .raises (AuthenticationError ):
271
+ Session ('hostname' , 'username' , 'password' )
272
+
You can’t perform that action at this time.
0 commit comments