Ejemplo n.º 1
0
 def testTokenClient(self):
     """
     Test the AWSSRP client is invoked and throws an error
     """
     sa = StaxAuth("ApiAuth")
     with self.assertRaises(InvalidCredentialsException):
         sa.id_token_from_cognito(username="******", password="******")
Ejemplo n.º 2
0
 def testToken(self):
     """
     Test valid JWT is returned
     """
     sa = StaxAuth("ApiAuth")
     self.stub_aws_srp(sa, "valid_username")
     token = sa.id_token_from_cognito(
         username="******",
         password="******",
         srp_client=self.aws_srp_client,
     )
     self.assertEqual(token, "valid_token")
Ejemplo n.º 3
0
    def testCredentialErrors(self):
        """
        Test that boto errors are caught and converted to InvalidCredentialExceptions
        """
        sa = StaxAuth("ApiAuth")
        # Test with invalid username password
        self.stub_aws_srp(sa, "bad_password", "NotAuthorizedException")
        user_not_found_success = False
        try:
            sa.id_token_from_cognito(
                username="******",
                password="******",
                srp_client=self.aws_srp_client,
            )
        except InvalidCredentialsException as e:
            self.assertIn("Please check your Secret Key is correct", str(e))
            user_not_found_success = True
        self.assertTrue(user_not_found_success)

        # Test with no access
        self.stub_aws_srp(sa, "no_access", "UserNotFoundException")
        no_access_success = False
        try:
            sa.id_token_from_cognito(username="******",
                                     password="******",
                                     srp_client=self.aws_srp_client)
        except InvalidCredentialsException as e:
            self.assertIn(
                "Please check your Access Key, that you have created your Api Token and that you are using the right STAX REGION",
                str(e),
            )
            no_access_success = True
        self.assertTrue(no_access_success)

        # Test Unknown Error
        self.stub_aws_srp(sa, "Unknown", "UnitTesting")
        with self.assertRaises(InvalidCredentialsException):
            sa.id_token_from_cognito(username="******",
                                     password="******",
                                     srp_client=self.aws_srp_client)