def test_require_group_viewable(self): """Test that the current user and group properties are set correctly.""" response = self.app.get('/in_peon_group?' 'user_name=samIam&password=secret&login=Login') user = TG_User.by_user_name("samIam") group_ids = set((TG_Group.by_group_name("peon").id, TG_Group.by_group_name("other").id))
def test_require_group_viewable(self): """Test that a user with proper group membership can see a restricted url.""" testutil.create_request('/in_peon_group?' 'user_name=samIam&password=secret&login=Login') firstline = cherrypy.response.body[0] assert 'in_peon_group' in firstline, firstline user = TG_User.by_user_name("samIam")
def test_create_user(self): """Check that User can be created outside of a running identity provider.""" u = TG_User(user_name='testcase', email_address='*****@*****.**', display_name='Test Me', password='******') assert u.password == 'test', u.password
def test_user_password(self): "Test if we can set a user password (no encryption algorithm)." hub.begin() u = TG_User.by_user_name('samIam') u.password='******' u.sync() assert u.password=='password' hub.rollback() hub.end()
def test_user_password(self): """Test if we can set a user password (no encryption algorithm).""" hub.begin() u = TG_User.by_user_name('samIam') u.password = '******' u.sync() assert u.password == 'password' hub.rollback() hub.end()
def test_user_password_hashed_md5(self): """Test if a md5 hashed password is stored in the database.""" config.update({'identity.soprovider.encryption_algorithm': 'md5'}) self.app.get('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = '******' u.sync() assert u.password =='5f4dcc3b5aa765d61d8327deb882cf99' hub.rollback() hub.end()
def test_user_password_hashed_sha_unicode(self): """Test if a non-ascii sha hashed password is stored in the database.""" config.update({'identity.soprovider.encryption_algorithm': 'sha1'}) self.app.get('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = u'garçon' u.sync() assert u.password == '442edb21c491a6e6f502eb79e98614f3c7edf43e' hub.rollback() hub.end()
def test_user_password_hashed_sha(self): """Test if a sha hashed password is stored in the database.""" config.update({'identity.soprovider.encryption_algorithm': 'sha1'}) self.app.get('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = '******' u.sync() assert u.password =='5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8' hub.rollback() hub.end()
def test_user_password_unicode(self): """Test if we can set a non-ascii user password (no encryption).""" config.update({'identity.soprovider.encryption_algorithm': None}) self.app.get('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = u'garçon' u.sync() assert u.password == u'garçon' hub.rollback() hub.end()
def in_peon_group(self): user = TG_User.by_user_name("samIam") group_ids = set((TG_Group.by_group_name("peon").id, TG_Group.by_group_name("other").id)) assert identity.current.user == user assert identity.current.user_name == user.user_name assert identity.current.user_id == user.id assert identity.current.groups == set(('peon', 'other')) assert identity.current.group_ids == group_ids assert "samIam" == cherrypy.serving.request.identity.user_name return 'in_peon_group'
def test_user_password_hashed_md5_unicode(self): """Test if a non-ascii md5 hashed password is stored in the database.""" config.update({'identity.soprovider.encryption_algorithm': 'md5'}) self.app.get('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = u'garçon' u.sync() assert u.password == 'c295c4bb2672ca8c432effc53b40bb1e' hub.rollback() hub.end()
def test_logout_with_set_identity(self): """Test that logout works even when there is no visit_key (e.g. when testutils.set_identity_user is used).""" request = testutil.DummyRequest() old_user = testutil.test_user user = TG_User.by_user_name("samIam") testutil.set_identity_user(user) testutil.attach_identity(request) testutil.set_identity_user(old_user) testutil.call_with_request(cherrypy.root.logout, request) assert request.identity.anonymous
def test_user_password_raw_unicode(self): """Test that unicode passwords are encrypted correctly""" config.update({'identity.soprovider.encryption_algorithm':'sha1'}) self.app.get('/') hub.begin() u = TG_User.by_user_name('samIam') u.set_password_raw(u'garçon') u.sync() assert u.password == u'garçon' hub.rollback() hub.end()
def test_user_password_raw_unicode(self): config.update({'identity.soprovider.encryption_algorithm':'sha1'}) # force new config values to load startup.startTurboGears() testutil.create_request('/') hub.begin() u = TG_User.by_user_name('samIam') u.set_password_raw(u'garçon') u.sync() self.assertEqual(u.password, u'garçon') hub.rollback() hub.end()
def test_require_group_viewable(self): """Test that the current user and group properties are set correctly.""" testutil.create_request('/in_peon_group?' 'user_name=samIam&password=secret&login=Login') user = TG_User.by_user_name("samIam") group_ids = set((TG_Group.by_group_name("peon").id, TG_Group.by_group_name("other").id)) assert identity.current.user == user assert identity.current.user_name == user.user_name assert identity.current.user_id == user.id assert identity.current.groups == set(('peon', 'other')) assert identity.current.group_ids == group_ids
def test_user_password_raw(self): """Test that we can store raw values in the password field (without being hashed).""" config.update({'identity.soprovider.encryption_algorithm':'sha1'}) self.app.get('/') hub.begin() u = TG_User.by_user_name('samIam') u.set_password_raw('password') u.sync() assert u.password =='password' hub.rollback() hub.end()
def test_user_password_raw_unicode(self): config.update({'identity.soprovider.encryption_algorithm': 'sha1'}) # force new config values to load startup.startTurboGears() testutil.create_request('/') hub.begin() u = TG_User.by_user_name('samIam') u.set_password_raw(u'garçon') u.sync() assert u.password == u'garçon' hub.rollback() hub.end()
def test_user_password_hashed_md5_unicode(self): """Test if a non-ascii md5 hashed password is stored in the database.""" config.update({'identity.soprovider.encryption_algorithm': 'md5'}) # force new config values to load startup.startTurboGears() testutil.create_request('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = u'garçon' u.sync() assert u.password == 'c295c4bb2672ca8c432effc53b40bb1e' hub.rollback() hub.end()
def test_user_password_hashed_md5(self): """Test if a md5 hashed password is stored in the database.""" config.update({'identity.soprovider.encryption_algorithm': 'md5'}) # force new config values to load startup.startTurboGears() testutil.create_request('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = '******' u.sync() assert u.password == '5f4dcc3b5aa765d61d8327deb882cf99' hub.rollback() hub.end()
def test_user_password_hashed_sha_unicode(self): """Test if a non-ascii sha hashed password is stored in the database.""" config.update({'identity.soprovider.encryption_algorithm': 'sha1'}) # force new config values to load startup.startTurboGears() testutil.create_request('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = u'garçon' u.sync() assert u.password == '442edb21c491a6e6f502eb79e98614f3c7edf43e' hub.rollback() hub.end()
def test_user_password_hashed_sha(self): """Test if a sha hashed password is stored in the database.""" config.update({'identity.soprovider.encryption_algorithm': 'sha1'}) # force new config values to load startup.startTurboGears() testutil.create_request('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = '******' u.sync() assert u.password == '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8' hub.rollback() hub.end()
def test_user_password_hashed_custom(self): """Test if a custom hashed password is stored in the database.""" config.update({'identity.soprovider.encryption_algorithm': 'custom', 'identity.custom_encryption': 'identity.tests.test_identity.mycustomencrypt'}) self.app.get('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = '******' u.sync() assert u.password =='password_custom' hub.rollback() hub.end()
def test_user_password_unicode(self): """Test if we can set a non-ascii user password (no encryption).""" config.update({'identity.soprovider.encryption_algorithm': None}) # force new config values to load startup.startTurboGears() testutil.create_request('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = u'garçon' u.sync() assert u.password == u'garçon' hub.rollback() hub.end()
def test_user_password_raw(self): "Test that we can store raw values in the password field (without being hashed)." config.update({'identity.soprovider.encryption_algorithm':'sha1'}) # force new config values to load startup.startTurboGears() testutil.create_request('/') hub.begin() u = TG_User.by_user_name('samIam') u.set_password_raw('password') u.sync() assert u.password =='password' hub.rollback() hub.end()
def test_user_password_hashed_sha(self): "Test if a sha hashed password is stored in the database." config.update({'identity.soprovider.encryption_algorithm':'sha1'}) # force new config values to load startup.startTurboGears() testutil.create_request('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = '******' u.sync() assert u.password =='5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8' hub.rollback() hub.end()
def test_user_password_hashed_md5(self): "Test if a md5 hashed password is stored in the database." config.update({'identity.soprovider.encryption_algorithm':'md5'}) # force new config values to load startup.startTurboGears() testutil.create_request('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = '******' u.sync() assert u.password =='5f4dcc3b5aa765d61d8327deb882cf99' hub.rollback() hub.end()
def test_user_password_hashed_md5_utf8string(self): """Test if a md5 hashed password with unicode characters is stored in the database if the password is entered as str (encoded in UTF-8). This test ensures that the encryption algorithm does handle non-unicode parameters gracefully.""" config.update({'identity.soprovider.encryption_algorithm': 'md5'}) self.app.get('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = u'garçon'.encode('UTF-8') u.sync() assert u.password == 'c295c4bb2672ca8c432effc53b40bb1e' hub.rollback() hub.end()
def test_user_password_raw(self): """Test that we can store raw values in the password field (without being hashed).""" config.update({'identity.soprovider.encryption_algorithm': 'sha1'}) # force new config values to load startup.startTurboGears() testutil.create_request('/') hub.begin() u = TG_User.by_user_name('samIam') u.set_password_raw('password') u.sync() assert u.password == 'password' hub.rollback() hub.end()
def test_user_password_hashed_custom(self): """Test if a custom hashed password is stored in the database.""" config.update({'identity.soprovider.encryption_algorithm': 'custom', 'identity.custom_encryption': 'identity.tests.test_identity.mycustomencrypt'}) # force new config values to load startup.startTurboGears() testutil.create_request('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = '******' u.sync() assert u.password =='password_custom' hub.rollback() hub.end()
def test_user_unicode(self): """Test that we can have non-ascii user names.""" user = TG_User(user_name=u'säm', display_name=u'Sämüel Käsfuß', email_address='*****@*****.**', password='******') testutil.create_request('/logged_in_only?' 'user_name=säm&password=geheim&login=Login') firstline = cherrypy.response.body[0] assert 'logged_in_only' in firstline, firstline credentials = base64.encodestring('säm:geheim')[:-1] testutil.create_request( '/logged_in_only', headers={'Authorization': 'Basic %s' % credentials}) firstline = cherrypy.response.body[0] assert 'logged_in_only' in firstline, firstline
def test_user_password_hashed_md5_utf8string(self): """Test if a md5 hashed password with unicode characters is stored in the database if the password is entered as str (encoded in UTF-8). This test ensures that the encryption algorithm does handle non-unicode parameters gracefully.""" config.update({'identity.soprovider.encryption_algorithm': 'md5'}) # force new config values to load startup.startTurboGears() testutil.create_request('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = u'garçon'.encode('UTF-8') u.sync() assert u.password == 'c295c4bb2672ca8c432effc53b40bb1e' hub.rollback() hub.end()
def test_user_password_hashed_custom(self): """Test if a custom hashed password is stored in the database.""" config.update({ 'identity.soprovider.encryption_algorithm': 'custom', 'identity.custom_encryption': 'identity.tests.test_identity.mycustomencrypt' }) # force new config values to load startup.startTurboGears() testutil.create_request('/') hub.begin() u = TG_User.by_user_name('samIam') u.password = '******' u.sync() assert u.password == 'password_custom' hub.rollback() hub.end()
def init_model(self): if TG_User.select().count() == 0: user = TG_User(user_name='samIam', email_address='*****@*****.**', display_name='Samuel Amicus', password='******') peon_group = TG_Group(group_name="peon", display_name="Regular Peon") admin_group = TG_Group(group_name="admin", display_name="Administrator") other_group = TG_Group(group_name="other", display_name="Another Group") chopper_perm = TG_Permission(permission_name='chops_wood', description="Wood Chopper") boss_perm = TG_Permission(permission_name='bosses_people', description="Benevolent Dictator") peon_group.addTG_Permission(chopper_perm) admin_group.addTG_Permission(boss_perm) user.addTG_Group(peon_group) user.addTG_Group(other_group)
def init_model(self): if TG_User.select().count() == 0: user = TG_User(user_name='samIam', email_address='*****@*****.**', display_name='Samuel Amicus', password='******') admin_group = TG_Group(group_name="admin", display_name="Administrator") peon_group = TG_Group(group_name="peon", display_name="Regular Peon") other_group = TG_Group(group_name="other", display_name="Another Group") chopper_perm = TG_Permission(permission_name='chops_wood', description="Wood Chopper") boss_perm = TG_Permission(permission_name='bosses_people', description="Benevolent Dictator") peon_group.addTG_Permission(chopper_perm) admin_group.addTG_Permission(boss_perm) user.addTG_Group(peon_group) user.addTG_Group(other_group)
def test_user_exists(self): """Test that test user is present in data base.""" u = TG_User.by_user_name('samIam') assert u.email_address == '*****@*****.**'
def test_user_exists(self): u = TG_User.by_user_name('samIam') assert u.email_address == '*****@*****.**'
def test_require_group_viewable(self): """Test that a user with proper group membership can see a restricted url.""" response = self.app.get('/in_peon_group?' 'user_name=samIam&password=secret&login=Login') assert 'in_peon_group' in response, response user = TG_User.by_user_name("samIam")