Esempio n. 1
0
    def test_validation_auth_checker_suspended(self):
        from ptah.authentication import AuthInfo
        from ptah.crowd.validation import validationAndSuspendedChecker

        principal = Principal('2', 'user', 'user')

        props = ptah.crowd.get_properties(principal.uri)
        props.validated = True
        props.suspended = False

        info = AuthInfo(True, principal)
        self.assertTrue(validationAndSuspendedChecker(info))

        props.suspended = True
        transaction.commit()

        info = AuthInfo(True, principal)
        self.assertFalse(validationAndSuspendedChecker(info))
        self.assertEqual(info.message, 'Account is suspended.')
Esempio n. 2
0
    def test_validation_auth_checker_validation(self):
        from ptah.crowd.validation import validationAndSuspendedChecker

        principal = Principal('1', 'user', 'user')

        props = ptah.crowd.get_properties(principal.uri)
        props.validated = False

        # validation disabled
        info = AuthInfo(True, principal)
        ptah.crowd.CONFIG['validation'] = False
        self.assertTrue(validationAndSuspendedChecker(info))
        transaction.commit()

        info = AuthInfo(True, principal)
        ptah.crowd.CONFIG['allow-unvalidated'] = False
        self.assertTrue(validationAndSuspendedChecker(info))
        transaction.commit()

        # validation enabled
        info = AuthInfo(True, principal)
        ptah.crowd.CONFIG['validation'] = True
        ptah.crowd.CONFIG['allow-unvalidated'] = False
        self.assertFalse(validationAndSuspendedChecker(info))
        self.assertEqual(info.message, 'Account is not validated.')
        transaction.commit()

        info = AuthInfo(True, principal)
        ptah.crowd.CONFIG['allow-unvalidated'] = True
        self.assertTrue(validationAndSuspendedChecker(info))
        transaction.commit()

        # validated
        props = ptah.crowd.get_properties(principal.uri)
        props.validated = True
        transaction.commit()

        info = AuthInfo(True, principal)
        ptah.crowd.CONFIG['validation'] = True
        self.assertTrue(validationAndSuspendedChecker(info))