Skip to content

Commit

Permalink
Changed how verify_token brings in env var, fixed verify_token test
Browse files Browse the repository at this point in the history
  • Loading branch information
bjinwright committed Apr 24, 2017
1 parent f5e1fc3 commit f22f9ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions warrant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def get_keys(self):
return self.pool_jwk
except AttributeError:
#Check for the dictionary in environment variables.
pool_jwk_env = env('COGNITO_JWKS', var_type='dict')
if isinstance(pool_jwk_env, dict):
pool_jwk_env = env('COGNITO_JWKS', {},var_type='dict')
if len(pool_jwk_env.keys()) > 0:
self.pool_jwk = pool_jwk_env
return self.pool_jwk
#If it is not there use the requests library to get it
Expand Down Expand Up @@ -251,9 +251,9 @@ def authenticate(self, password):
aws = AWSSRP(username=self.username, password=password, pool_id=self.user_pool_id,
client_id=self.client_id, client=self.client)
tokens = aws.authenticate_user()
self.verify_token(tokens['AuthenticationResult']['IdToken'],'id_token')
self.verify_token(tokens['AuthenticationResult']['IdToken'],'id_token','id')
self.refresh_token = tokens['AuthenticationResult']['RefreshToken']
self.verify_token(tokens['AuthenticationResult']['AccessToken'], 'access_token')
self.verify_token(tokens['AuthenticationResult']['AccessToken'], 'access_token','access')
self.token_type = tokens['AuthenticationResult']['TokenType']

def logout(self):
Expand Down
7 changes: 4 additions & 3 deletions warrant/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from envs import env
from botocore.exceptions import ClientError

from warrant import Cognito,UserObj
from warrant import Cognito, UserObj, TokenVerificationException
from warrant.aws_srp import AWSSRP


Expand Down Expand Up @@ -53,8 +53,9 @@ def test_authenticate(self):
def test_verify_token(self):
self.user.authenticate(self.password)
bad_access_token = '{}wrong'.format(self.user.access_token)
verify = self.user.verify_token(bad_access_token,'access_token')
self.assertFalse(verify)

with self.assertRaises(TokenVerificationException) as vm:
self.user.verify_token(bad_access_token, 'access_token', 'access')

def test_logout(self):
self.user.authenticate(self.password)
Expand Down

0 comments on commit f22f9ca

Please sign in to comment.