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
99
1010 ** Improvements**
1111 - Added ` copy_analytic_store ` method to ` model_repository ` service
12+ - ` AuthenticationError ` returned instead of ` HTTPError ` if session authentication fails.
1213
1314
1415v0.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):
484484 data = data ,
485485 headers = headers ,
486486 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 ()
488492
489493 return r .json ().get ('access_token' )
490494
491495 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+ """
492510 username = self ._settings ['username' ]
493511 password = self ._settings ['password' ]
494512
@@ -888,3 +906,6 @@ class SasctlError(Exception):
888906
889907class TimeoutError (SasctlError ):
890908 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():
218218
219219
220220def test_verify_ssl ():
221-
222221 with mock .patch ('sasctl.core.Session.get_token' , return_value = 'token' ):
223222 # Should verify SSL by default
224223 s = Session ('hostname' , 'username' , 'password' )
@@ -261,3 +260,13 @@ def test_kerberos():
261260
262261 s = Session ('hostname' , 'username@REALM' )
263262 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