Beispiel #1
0
    def test_token_auth_bad_token(self):
        """
        Tests that the user cannot be authenticated if an incorrect token is
        provided.
        """
        bad_token = str(uuid4())
        self.assertNotEqual(bad_token, self.token)

        with self.context:
            self.assertFalse(auth.verify_password(bad_token))
            self.assertTrue(auth.verify_password(self.token))
    def test_token_auth_bad_token(self):
        """
        Tests that the user cannot be authenticated if an incorrect token is
        provided.
        """
        bad_token = str(uuid4())
        self.assertNotEqual(bad_token, self.token)

        with self.context:
            self.assertFalse(auth.verify_password(bad_token))
            self.assertTrue(auth.verify_password(self.token))
    def test_user_query_token_adds_to_g(self):

        self.assertTrue(auth.verify_password(
            self.username, self.password
        ))

        self.assertIsInstance(auth.g.user, self.user.__class__)
 def test_verify_password_correct_credentials(self):
     """
     Tests that the callback returns ``True`` if the correct username and
     password are provided.
     """
     with self.context:
         self.assertTrue(auth.verify_password(self.username, self.password))
 def test_token_auth(self):
     """
     Tests that the ``verify_password`` callback can authenticate a user
     when the correct token is provided.
     """
     with self.context:
         self.assertTrue(auth.verify_password(self.token))
Beispiel #6
0
 def test_token_auth(self):
     """
     Tests that the ``verify_password`` callback can authenticate a user
     when the correct token is provided.
     """
     with self.context:
         self.assertTrue(auth.verify_password(self.token))
Beispiel #7
0
 def test_verify_password_correct_credentials(self):
     """
     Tests that the callback returns ``True`` if the correct username and
     password are provided.
     """
     with self.context:
         self.assertTrue(auth.verify_password(self.username, self.password))
    def test_auth_token_correct(self):

        with mock.patch('sqlalchemy.orm.Query.first',
                        return_value=self.user) as mock_verify_auth:

            self.assertTrue(auth.verify_password(self.username, self.password))
            self.assertEqual(mock_verify_auth.call_args, mock.call())
 def test_verify_correct_uname_bad_pwd(self):
     """
     Tests that the callback returns ``False`` if the correct username but
     an incorrect password are supplied.
     """
     bad_password = '******'
     with self.context:
         self.assertFalse(auth.verify_password(self.username, bad_password))
 def test_verify_incorrect_username_correct_pwd(self):
     """
     Tests that the callback returns ``False`` if an incorrect username
     but correct password are supplied.
     """
     bad_username = '******'
     with self.context:
         self.assertFalse(auth.verify_password(bad_username, self.password))
Beispiel #11
0
 def test_verify_incorrect_username_correct_pwd(self):
     """
     Tests that the callback returns ``False`` if an incorrect username
     but correct password are supplied.
     """
     bad_username = '******'
     with self.context:
         self.assertFalse(auth.verify_password(bad_username, self.password))
Beispiel #12
0
 def test_verify_correct_uname_bad_pwd(self):
     """
     Tests that the callback returns ``False`` if the correct username but
     an incorrect password are supplied.
     """
     bad_password = '******'
     with self.context:
         self.assertFalse(auth.verify_password(self.username, bad_password))
    def test_user_query_no_user_found(self, mock_verify):
        with auth.database_session() as session:
            user = session.query(
                self.user.__class__).filter_by(username=self.username).first()
            session.delete(user)

        self.assertFalse(auth.verify_password(self.username, self.password))

        self.assertFalse(mock_verify.called)
    def test_user_query(self, mock_verify_pwd):

        self.assertTrue(auth.verify_password(
            self.username, self.password
        ))

        self.assertEqual(
            mock_verify_pwd.call_args,
            mock.call(self.password)
        )
    def test_user_query_no_user_found(self, mock_verify):
        with auth.database_session() as session:
            user = session.query(self.user.__class__).filter_by(
                username=self.username
            ).first()
            session.delete(user)

        self.assertFalse(auth.verify_password(
            self.username, self.password))

        self.assertFalse(mock_verify.called)
    def test_user_password_verify_adds_to_g(self, mock_verify_password,
                                            mock_query, mock_verify_token):
        mock_query.return_value = self.user

        self.assertTrue(auth.verify_password(self.username, self.password))

        self.assertEqual(auth.g.user, self.user)

        self.assertEqual(mock_query.call_args, mock.call())
        self.assertEqual(mock_verify_password.call_args,
                         mock.call(self.password))
    def test_auth_token_correct(self):

        with mock.patch(
                'sqlalchemy.orm.Query.first', return_value=self.user
        ) as mock_verify_auth:

            self.assertTrue(auth.verify_password(
                self.username, self.password
            )
            )
            self.assertEqual(
                mock_verify_auth.call_args,
                mock.call()
             )
    def test_user_password_verify_adds_to_g(
            self, mock_verify_password, mock_query, mock_verify_token
    ):
        mock_query.return_value = self.user

        self.assertTrue(auth.verify_password(
            self.username, self.password
        ))

        self.assertEqual(auth.g.user, self.user)

        self.assertEqual(mock_query.call_args, mock.call())
        self.assertEqual(mock_verify_password.call_args,
                         mock.call(self.password))
    def test_user_query_bad_password(self, mock_verify):
        self.assertFalse(auth.verify_password(
            self.username, self.password
        ))

        self.assertTrue(mock_verify.called)
 def test_verify_token(self):
     self.assertTrue(auth.verify_password(self.token_string))
     self.assertEqual(auth.g.user, self.user)
     self.assertTrue(auth.g.verified_from_token)
 def test_verify_token_no_token_found(self, mock_first):
     self.assertFalse(auth.verify_password(self.token_string))
     self.assertTrue(mock_first.called)
 def test_verify_token_bad_token(self, mock_check_token):
     self.assertFalse(auth.verify_password(self.token_string))
     self.assertTrue(mock_check_token.called)
    def test_user_query_token_adds_to_g(self):

        self.assertTrue(auth.verify_password(self.username, self.password))

        self.assertIsInstance(auth.g.user, self.user.__class__)
    def test_user_query_bad_password(self, mock_verify):
        self.assertFalse(auth.verify_password(self.username, self.password))

        self.assertTrue(mock_verify.called)
    def test_user_query(self, mock_verify_pwd):

        self.assertTrue(auth.verify_password(self.username, self.password))

        self.assertEqual(mock_verify_pwd.call_args, mock.call(self.password))
 def test_verify_token(self):
     self.assertTrue(auth.verify_password(self.token_string))
     self.assertEqual(auth.g.user, self.user)
     self.assertTrue(auth.g.verified_from_token)
 def test_verify_token_bad_token(self, mock_check_token):
     self.assertFalse(auth.verify_password(self.token_string))
     self.assertTrue(mock_check_token.called)
 def test_verify_token_no_token_found(self, mock_first):
     self.assertFalse(auth.verify_password(self.token_string))
     self.assertTrue(mock_first.called)