'Session expired. You are not '
'authorized to access that resource')
cherrypy.session[Auth.SESSION_KEY_TS] = now
+
+ @staticmethod
+ def set_login_credentials(username, password):
+ Auth._mgr_module_.set_localized_config('username', username)
+ hashed_passwd = Auth.password_hash(password)
+ Auth._mgr_module_.set_localized_config('password', hashed_passwd)
def handle_command(self, cmd):
if cmd['prefix'] == 'dashboard set-login-credentials':
- self.set_localized_config('username', cmd['username'])
- hashed_passwd = Auth.password_hash(cmd['password'])
- self.set_localized_config('password', hashed_passwd)
+ Auth.set_login_credentials(cmd['username'], cmd['password'])
return 0, 'Username and password updated', ''
return (-errno.EINVAL, '', 'Command not found \'{0}\''
cls._mgr_module.set_localized_config('password',
Auth.password_hash('admin'))
+ def setUp(self):
+ self._mgr_module.set_localized_config('session-expire', '2')
+ self._mgr_module.set_localized_config('username', 'admin')
+ self._mgr_module.set_localized_config('password',
+ Auth.password_hash('admin'))
+
+ def test_a_set_login_credentials(self):
+ Auth.set_login_credentials('admin2', 'admin2')
+ user = self._mgr_module.get_localized_config('username')
+ passwd = self._mgr_module.get_localized_config('password')
+ self.assertEqual(user, 'admin2')
+ self.assertEqual(passwd, Auth.password_hash('admin2', passwd))
+
def test_login_valid(self):
sess_mock = RamSession()
with patch('cherrypy.session', sess_mock, create=True):