@@ -59,10 +59,20 @@ def testToken(self):
5959 sa = StaxAuth ("ApiAuth" )
6060 self .stub_aws_srp (sa , "valid_username" )
6161 token = sa .id_token_from_cognito (
62- username = "valid_username" , password = "correct" , srp_client = self .aws_srp_client
62+ username = "valid_username" ,
63+ password = "correct" ,
64+ srp_client = self .aws_srp_client ,
6365 )
6466 self .assertEqual (token , "valid_token" )
6567
68+ def testTokenClient (self ):
69+ """
70+ Test the AWSSRP client is invoked and throws an error
71+ """
72+ sa = StaxAuth ("ApiAuth" )
73+ with self .assertRaises (InvalidCredentialsException ):
74+ sa .id_token_from_cognito (username = "username" , password = "password" )
75+
6676 def testCredentialErrors (self ):
6777 """
6878 Test that boto errors are caught and converted to InvalidCredentialExceptions
@@ -73,7 +83,9 @@ def testCredentialErrors(self):
7383 user_not_found_success = False
7484 try :
7585 sa .id_token_from_cognito (
76- username = "bad_password" , password = "wrong" , srp_client = self .aws_srp_client
86+ username = "bad_password" ,
87+ password = "wrong" ,
88+ srp_client = self .aws_srp_client ,
7789 )
7890 except InvalidCredentialsException as e :
7991 self .assertIn ("Please check your Secret Key is correct" , e .message )
@@ -116,6 +128,16 @@ def testCreds(self):
116128 self .assertIn ("Credentials" , creds )
117129 self .assertTrue (creds .get ("IdentityId" ).startswith ("ap-southeast-2" ))
118130
131+ def testCredsClient (self ):
132+ """
133+ Test the cognito client is invoked and throws an error
134+ """
135+ sa = StaxAuth ("ApiAuth" )
136+ token = jwt .encode ({"sub" : "unittest" }, "secret" , algorithm = "HS256" )
137+ jwt_token = jwt .decode (token , verify = False )
138+ with self .assertRaises (InvalidCredentialsException ):
139+ sa .sts_from_cognito_identity_pool (jwt_token .get ("sub" ))
140+
119141 def testAuthErrors (self ):
120142 """
121143 Test that errors are thrown when keys are invalid
0 commit comments