コード例 #1
0
class TestAuthenticator(unittest.TestCase):
    """Tests for the authenticator function"""
    def setUp(self):
        databasesetup_sa.setup_database()
        self.plugin = SQLAlchemyAuthenticatorPlugin(sa_model.User,
                                                    sa_model.DBSession)

    def tearDown(self):
        databasesetup_sa.teardownDatabase()

    def test_implements(self):
        verifyClass(IAuthenticator,
                    SQLAlchemyAuthenticatorPlugin,
                    tentative=True)

    def test_no_identity(self):
        identity = {}
        self.assertEqual(None, self.plugin.authenticate(None, identity))

    def test_incomplete_credentials(self):
        identity = {'login': '******'}
        self.assertEqual(None, self.plugin.authenticate(None, identity))
        identity = {'password': '******'}
        self.assertEqual(None, self.plugin.authenticate(None, identity))

    def test_no_match(self):
        identity = {'login': u'gustavo', 'password': u'narea'}
        self.assertEqual(None, self.plugin.authenticate(None, identity))

    def test_match(self):
        identity = {'login': u'rms', 'password': u'freedom'}
        self.assertEqual(u'rms', self.plugin.authenticate(None, identity))
コード例 #2
0
class TestAuthenticatorWithElixir(TestAuthenticator):
    def setUp(self):
        databasesetup_elixir.setup_database()
        self.plugin = SQLAlchemyAuthenticatorPlugin(elixir_model.User,
                                                    elixir_model.DBSession)

    def tearDown(self):
        databasesetup_elixir.teardownDatabase()

    def test_rollback(self):
        """The session must be rolled back before use."""
        # Make the transaction invalid by attempting to add an existing user:
        try:
            user = elixir_model.User()
            user.user_name = compat.u("rms")
            user.password = "******"
            elixir_model.DBSession.add(user)
            elixir_model.DBSession.commit()
        except IntegrityError:
            pass
        else:
            self.fail("An IntegrityError must've been raised")

        identity = {'login': compat.u('rms'), 'password': compat.u('freedom')}
        self.plugin.authenticate(None, identity)
コード例 #3
0
ファイル: test_authenticator.py プロジェクト: mbbui/Jminee
class TestAuthenticatorWithElixir(TestAuthenticator):
    
    def setUp(self):
        databasesetup_elixir.setup_database()
        self.plugin = SQLAlchemyAuthenticatorPlugin(elixir_model.User,
                                            elixir_model.DBSession)
    
    def tearDown(self):
        databasesetup_elixir.teardownDatabase()
    
    def test_rollback(self):
        """The session must be rolled back before use."""
        # Make the transaction invalid by attempting to add an existing user:
        try:
            user = elixir_model.User()
            user.user_name = u"rms"
            user.password = "******"
            elixir_model.DBSession.add(user)
            elixir_model.DBSession.commit()
        except IntegrityError:
            pass
        else:
            self.fail("An IntegrityError must've been raised")
        
        identity = {'login': u'rms', 'password': u'freedom'}
        self.plugin.authenticate(None, identity)
コード例 #4
0
class TestAuthenticatorWithTranslations(unittest.TestCase):
    """Tests for the authenticator function"""
    def setUp(self):
        databasesetup_sa.setup_database_with_translations()

    def tearDown(self):
        databasesetup_sa.teardownDatabase()

    def test_it(self):
        self.plugin = SQLAlchemyAuthenticatorPlugin(sa_model.Member,
                                                    sa_model.DBSession)
        # Updating the translations...
        self.plugin.translations['user_name'] = 'member_name'
        self.plugin.translations['validate_password'] = '******'
        # Testing it...
        identity = {'login': compat.u('rms'), 'password': compat.u('freedom')}
        self.assertEqual(compat.u('rms'),
                         self.plugin.authenticate(None, identity))

    def test_dummy_validate(self):
        self.plugin = SQLAlchemyAuthenticatorPlugin(sa_model.User,
                                                    sa_model.DBSession)
        self.plugin.translations['dummy_validate_password'] = \
            sa_model.dummy_validate
        identity = {
            'login': compat.u('QWERTY'),
            'password': compat.u('freedom')
        }
        self.assertRaises(sa_model.DummyValidateException,
                          self.plugin.authenticate, None, identity)
コード例 #5
0
ファイル: test_authenticator.py プロジェクト: mbbui/Jminee
class TestAuthenticatorWithTranslations(unittest.TestCase):
    """Tests for the authenticator function"""
    
    def setUp(self):
        databasesetup_sa.setup_database_with_translations()
    
    def tearDown(self):
        databasesetup_sa.teardownDatabase()
    
    def test_it(self):
        self.plugin = SQLAlchemyAuthenticatorPlugin(sa_model.Member, 
                                                    sa_model.DBSession)
        # Updating the translations...
        self.plugin.translations['user_name'] = 'member_name'
        self.plugin.translations['validate_password'] = '******'
        # Testing it...
        identity = {'login': u'rms', 'password': u'freedom'}
        self.assertEqual(u'rms', self.plugin.authenticate(None, identity))

    def test_dummy_validate(self):
        self.plugin = SQLAlchemyAuthenticatorPlugin(sa_model.User, 
                                                    sa_model.DBSession)
        self.plugin.translations['dummy_validate_password'] = \
            sa_model.dummy_validate
        identity = {'login': u'QWERTY', 'password': u'freedom'}
        self.assertRaises(sa_model.DummyValidateException,
                          self.plugin.authenticate, None, identity)
コード例 #6
0
class TestAuthenticator(unittest.TestCase):
    """Tests for the authenticator function"""
    def setUp(self):
        databasesetup_sa.setup_database()
        self.plugin = SQLAlchemyAuthenticatorPlugin(sa_model.User,
                                                    sa_model.DBSession)

    def tearDown(self):
        databasesetup_sa.teardownDatabase()

    def test_implements(self):
        verifyClass(IAuthenticator,
                    SQLAlchemyAuthenticatorPlugin,
                    tentative=True)

    def test_no_identity(self):
        identity = {}
        self.assertEqual(None, self.plugin.authenticate(None, identity))

    def test_incomplete_credentials(self):
        identity = {'login': '******'}
        self.assertEqual(None, self.plugin.authenticate(None, identity))
        identity = {'password': '******'}
        self.assertEqual(None, self.plugin.authenticate(None, identity))

    def test_no_match(self):
        identity = {
            'login': compat.u('gustavo'),
            'password': compat.u('narea')
        }
        self.assertEqual(None, self.plugin.authenticate(None, identity))

    def test_match(self):
        identity = {'login': compat.u('rms'), 'password': compat.u('freedom')}
        self.assertEqual(compat.u('rms'),
                         self.plugin.authenticate(None, identity))

    def test_rollback(self):
        """The session must be rolled back before use."""
        # Make the transaction invalid by attempting to add an existing user:
        try:
            user = sa_model.User()
            user.user_name = compat.u("rms")
            user.password = "******"
            sa_model.DBSession.add(user)
            sa_model.DBSession.commit()
        except IntegrityError:
            pass
        else:
            self.fail("An IntegrityError must've been raised")

        identity = {'login': compat.u('rms'), 'password': compat.u('freedom')}
        self.plugin.authenticate(None, identity)
コード例 #7
0
ファイル: test_authenticator.py プロジェクト: mbbui/Jminee
class TestAuthenticator(unittest.TestCase):
    """Tests for the authenticator function"""
    
    def setUp(self):
        databasesetup_sa.setup_database()
        self.plugin = SQLAlchemyAuthenticatorPlugin(sa_model.User, 
                                                    sa_model.DBSession)
    
    def tearDown(self):
        databasesetup_sa.teardownDatabase()

    def test_implements(self):
        verifyClass(IAuthenticator, SQLAlchemyAuthenticatorPlugin, 
                    tentative=True)
        
    def test_no_identity(self):
        identity = {}
        self.assertEqual(None, self.plugin.authenticate(None, identity))
        
    def test_incomplete_credentials(self):
        identity = {'login': '******'}
        self.assertEqual(None, self.plugin.authenticate(None, identity))
        identity = {'password': '******'}
        self.assertEqual(None, self.plugin.authenticate(None, identity))
        
    def test_no_match(self):
        identity = {'login': u'gustavo', 'password': u'narea'}
        self.assertEqual(None, self.plugin.authenticate(None, identity))
        
    def test_match(self):
        identity = {'login': u'rms', 'password': u'freedom'}
        self.assertEqual(u'rms', self.plugin.authenticate(None, identity))
    
    def test_rollback(self):
        """The session must be rolled back before use."""
        # Make the transaction invalid by attempting to add an existing user:
        try:
            user = sa_model.User()
            user.user_name = u"rms"
            user.password = "******"
            sa_model.DBSession.add(user)
            sa_model.DBSession.commit()
        except IntegrityError:
            pass
        else:
            self.fail("An IntegrityError must've been raised")
        
        identity = {'login': u'rms', 'password': u'freedom'}
        self.plugin.authenticate(None, identity)
コード例 #8
0
class TestAuthenticatorWithTranslations(unittest.TestCase):
    """Tests for the authenticator function"""
    def setUp(self):
        databasesetup_sa.setup_database_with_translations()

    def tearDown(self):
        databasesetup_sa.teardownDatabase()

    def test_it(self):
        self.plugin = SQLAlchemyAuthenticatorPlugin(sa_model.Member,
                                                    sa_model.DBSession)
        # Updating the translations...
        self.plugin.translations['user_name'] = 'member_name'
        self.plugin.translations['validate_password'] = '******'
        # Testing it...
        identity = {'login': u'rms', 'password': u'freedom'}
        self.assertEqual(u'rms', self.plugin.authenticate(None, identity))
コード例 #9
0
class TestAuthenticator(unittest.TestCase):
    """Tests for the authenticator function"""
    def setUp(self):
        databasesetup_sa.setup_database()
        self.plugin = SQLAlchemyAuthenticatorPlugin(sa_model.User,
                                                    sa_model.DBSession)

    def tearDown(self):
        databasesetup_sa.teardownDatabase()

    def test_implements(self):
        verifyClass(IAuthenticator,
                    SQLAlchemyAuthenticatorPlugin,
                    tentative=True)

    def test_no_identity(self):
        identity = {}
        self.assertEqual(None, self.plugin.authenticate(None, identity))

    def test_incomplete_credentials(self):
        identity = {'login': '******'}
        self.assertEqual(None, self.plugin.authenticate(None, identity))
        identity = {'password': '******'}
        self.assertEqual(None, self.plugin.authenticate(None, identity))

    def test_no_match(self):
        identity = {'login': u'gustavo', 'password': u'narea'}
        self.assertEqual(None, self.plugin.authenticate(None, identity))

    def test_match(self):
        identity = {'login': u'rms', 'password': u'freedom'}
        self.assertEqual(u'rms', self.plugin.authenticate(None, identity))

    def test_translations(self):
        # Changing the names...
        user = self.plugin.user_class
        user.userid = user.user_name
        user.validator = user.validate_password
        del user.user_name
        del user.validate_password
        # Updating the translations...
        self.plugin.translations['user_name'] = 'userid'
        self.plugin.translations['validate_password'] = '******'
        # Testing it...
        identity = {'login': u'rms', 'password': u'freedom'}
        self.assertEqual(u'rms', self.plugin.authenticate(None, identity))