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)
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)
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)
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))
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)
''' Authentication configuration ''' from repoze.who.plugins.sa import SQLAlchemyAuthenticatorPlugin from repoze.who.plugins.sa import SQLAlchemyUserMDPlugin from repoze.what.plugins.sql import configure_sql_adapters from repoze.what.middleware import AuthorizationMetadata from repoze.what.plugins.pylonshq import booleanize_predicates from pygdv.model import DBSession, User, Group, Permission # # authenticator plugin # authenticator = SQLAlchemyAuthenticatorPlugin(User, DBSession) # users who log in using a regular form use their email address as username authenticator.translations['user_name'] = 'email' # # metadata provider plugins # # # From the documentation in repoze.what.plugins.sql.adapters package # # For developers to be able to use the names they want in their model, both the # groups and permissions source adapters use a "translation table" for the # field and table names involved: # * Group source adapter: # * "section_name" (default: "group_name"): The name of the table field that # contains the primary key in the groups table.
def setUp(self): databasesetup_sa.setup_database() self.plugin = SQLAlchemyAuthenticatorPlugin(sa_model.User, sa_model.DBSession)
def setUp(self): databasesetup_elixir.setup_database() self.plugin = SQLAlchemyAuthenticatorPlugin(elixir_model.User, elixir_model.DBSession)