Exemplo n.º 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))
Exemplo n.º 2
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))
Exemplo n.º 3
0
    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__)
Exemplo n.º 4
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))
Exemplo n.º 5
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))
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 8
0
    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())
Exemplo n.º 9
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))
Exemplo n.º 10
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))
Exemplo n.º 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))
Exemplo n.º 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))
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
    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)
        )
Exemplo n.º 15
0
    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)
Exemplo n.º 16
0
    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))
Exemplo n.º 17
0
    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()
             )
Exemplo n.º 18
0
    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))
Exemplo n.º 19
0
    def test_user_query_bad_password(self, mock_verify):
        self.assertFalse(auth.verify_password(
            self.username, self.password
        ))

        self.assertTrue(mock_verify.called)
Exemplo n.º 20
0
 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)
Exemplo n.º 21
0
 def test_verify_token_no_token_found(self, mock_first):
     self.assertFalse(auth.verify_password(self.token_string))
     self.assertTrue(mock_first.called)
Exemplo n.º 22
0
 def test_verify_token_bad_token(self, mock_check_token):
     self.assertFalse(auth.verify_password(self.token_string))
     self.assertTrue(mock_check_token.called)
Exemplo n.º 23
0
    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__)
Exemplo n.º 24
0
    def test_user_query_bad_password(self, mock_verify):
        self.assertFalse(auth.verify_password(self.username, self.password))

        self.assertTrue(mock_verify.called)
Exemplo n.º 25
0
    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))
Exemplo n.º 26
0
 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)
Exemplo n.º 27
0
 def test_verify_token_bad_token(self, mock_check_token):
     self.assertFalse(auth.verify_password(self.token_string))
     self.assertTrue(mock_check_token.called)
Exemplo n.º 28
0
 def test_verify_token_no_token_found(self, mock_first):
     self.assertFalse(auth.verify_password(self.token_string))
     self.assertTrue(mock_first.called)