def setUpClass(cls): cls.app = create_app('testing', "") cls.app_context = cls.app.app_context() cls.app_context.push() db.create_all() # Create an admin for tests. create_db_admin(cls.app, "testadmin", "*****@*****.**", "testpw")
def test_03_admin_auth(self): set_privacyidea_config(SYSCONF.SPLITATSIGN, True) # check that the default admin works with self.app.test_request_context('/auth', method='POST', data={"username": "******", "password": "******"}): res = self.app.full_dispatch_request() self.assertEqual(200, res.status_code, res) result = res.json.get("result") self.assertTrue(result.get("status"), result) self.assertIn('token', result.get("value"), result) # role should be 'admin' self.assertEqual('admin', result['value']['role'], result) # add an admin with an '@' in the login name create_db_admin(self.app, 'super@intern', password='******') # as long as the part after the '@' does not resemble an existing realm, # this should work with 'spltAtSign' set to True with self.app.test_request_context('/auth', method='POST', data={"username": "******", "password": "******"}): res = self.app.full_dispatch_request() self.assertEqual(200, res.status_code, res) result = res.json.get("result") self.assertTrue(result.get("status"), result) self.assertIn('token', result.get("value"), result) # role should be 'admin' self.assertEqual('admin', result['value']['role'], result) # both admin logins should also work with 'splitAtSign' set to False set_privacyidea_config(SYSCONF.SPLITATSIGN, False) with self.app.test_request_context('/auth', method='POST', data={"username": "******", "password": "******"}): res = self.app.full_dispatch_request() self.assertEqual(200, res.status_code, res) result = res.json.get("result") self.assertTrue(result.get("status"), result) self.assertIn('token', result.get("value"), result) # role should be 'admin' self.assertEqual('admin', result['value']['role'], result) with self.app.test_request_context('/auth', method='POST', data={"username": "******", "password": "******"}): res = self.app.full_dispatch_request() self.assertEqual(200, res.status_code, res) result = res.json.get("result") self.assertTrue(result.get("status"), result) self.assertIn('token', result.get("value"), result) # role should be 'admin' self.assertEqual('admin', result['value']['role'], result) # reset 'splitAtSign' to default value set_privacyidea_config(SYSCONF.SPLITATSIGN, True)
def test_03_empty_passsword(self): create_db_admin(current_app, "mytestadmin", email="admin@localhost", password="******") r = verify_db_admin("mytestadmin", None) self.assertFalse(r) # Delete the admin delete_db_admin("mytestadmin")
def setUpClass(cls): cls.app = create_app('testing', "") cls.app_context = cls.app.app_context() cls.app_context.push() db.create_all() # save the current timestamp to the database to avoid hanging cached # data save_config_timestamp() db.session.commit() # Create an admin for tests. create_db_admin(cls.app, "testadmin", "*****@*****.**", "testpw")
def test_01_db_admin(self): create_db_admin(current_app, "mytestadmin", email="admin@localhost", password="******") r = verify_db_admin("mytestadmin", "PSTwort") self.assertTrue(r) # This only prints to stdout! list_db_admin() # Delete the admin delete_db_admin("mytestadmin")
def setUpClass(cls): # Modified setup method to use SharedEngineRegistry cls.app = create_app('testing', "") cls.app.config['PI_ENGINE_REGISTRY_CLASS'] = 'shared' cls.app_context = cls.app.app_context() cls.app_context.push() db.create_all() # save the current timestamp to the database to avoid hanging cached # data save_config_timestamp() db.session.commit() # Create an admin for tests. create_db_admin(cls.app, "testadmin", "*****@*****.**", "testpw")
def change(username, email=None, password_prompt=False): """ Change the email address or the password of an existing administrator. """ if password_prompt: password = getpass() password2 = getpass(prompt='Confirm: ') if password != password2: import sys sys.exit('Error: passwords do not match.') else: password = None create_db_admin(app, username, email, password)
def add(username, email, password=None): """ Register a new administrator in the database. """ db.create_all() if not password: password = getpass() password2 = getpass(prompt='Confirm: ') if password != password2: import sys sys.exit('Error: passwords do not match.') create_db_admin(app, username, email, password) print('Admin {0} was registered successfully.'.format(username))
def test_01_db_admin(self): create_db_admin(current_app, "mytestadmin", email="admin@localhost", password="******") r = verify_db_admin("mytestadmin", "PSTwort") self.assertTrue(r) self.assertTrue(db_admin_exist("mytestadmin")) self.assertFalse(db_admin_exist("noKnownUser")) # This only prints to stdout! list_db_admin() # Delete the admin delete_db_admin("mytestadmin")