예제 #1
0
    def test_login(self, logger: MagicMock):
        username = "******"
        password = "******"
        email = "*****@*****.**"

        user = BaseUser(username=username, password=password, email=email)
        user.save().run_sync()

        # Test correct password
        authenticated = BaseUser.login_sync(username, password)
        self.assertTrue(authenticated == user.id)

        # Test incorrect password
        authenticated = BaseUser.login_sync(username, "blablabla")
        self.assertTrue(authenticated is None)

        # Test ultra long password
        malicious_password = secrets.token_urlsafe(1000)
        authenticated = BaseUser.login_sync(username, malicious_password)
        self.assertTrue(authenticated is None)
        self.assertEqual(
            logger.method_calls,
            [call.warning("Excessively long password provided.")],
        )

        # Test ulta long username
        logger.reset_mock()
        malicious_username = secrets.token_urlsafe(1000)
        authenticated = BaseUser.login_sync(malicious_username, password)
        self.assertTrue(authenticated is None)
        self.assertEqual(
            logger.method_calls,
            [call.warning("Excessively long username provided.")],
        )
예제 #2
0
    def test_update_password(self):
        username = "******"
        password = "******"
        email = "*****@*****.**"

        user = BaseUser(username=username, password=password, email=email)
        user.save().run_sync()

        authenticated = BaseUser.login_sync(username, password)
        self.assertTrue(authenticated is not None)

        # Test success
        new_password = "******"
        BaseUser.update_password_sync(username, new_password)
        authenticated = BaseUser.login_sync(username, new_password)
        self.assertTrue(authenticated is not None)

        # Test ultra long password
        malicious_password = secrets.token_urlsafe(1000)
        with self.assertRaises(ValueError) as manager:
            BaseUser.update_password_sync(username, malicious_password)
        self.assertEqual(
            manager.exception.__str__(),
            "The password is too long.",
        )
예제 #3
0
파일: test_tables.py 프로젝트: zkan/piccolo
    def test_update_password(self):
        username = "******"
        password = "******"
        email = "*****@*****.**"

        user = BaseUser(username=username, password=password, email=email)
        user.save().run_sync()

        authenticated = BaseUser.login_sync(username, password)
        self.assertTrue(authenticated is not None)

        new_password = "******"
        BaseUser.update_password_sync(username, new_password)
        authenticated = BaseUser.login_sync(username, new_password)
        self.assertTrue(authenticated is not None)
예제 #4
0
    def test_create(self, *args, **kwargs):
        user = BaseUser(username="******", password="******")
        user.save().run_sync()

        change_password()

        self.assertTrue(
            BaseUser.login_sync(username="******", password="******")
            is not None
        )
예제 #5
0
 def test_success(self):
     user = BaseUser.create_user_sync(username="******", password="******")
     self.assertTrue(isinstance(user, BaseUser))
     self.assertEqual(
         BaseUser.login_sync(username="******", password="******"), user.id)