]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard_v2: Moved set-login-cred command logic to Auth class
authorRicardo Dias <rdias@suse.com>
Fri, 26 Jan 2018 12:12:16 +0000 (12:12 +0000)
committerRicardo Dias <rdias@suse.com>
Mon, 5 Mar 2018 13:07:01 +0000 (13:07 +0000)
Signed-off-by: Ricardo Dias <rdias@suse.com>
src/pybind/mgr/dashboard_v2/controllers/auth.py
src/pybind/mgr/dashboard_v2/module.py
src/pybind/mgr/dashboard_v2/tests/test_auth.py

index 36ce70be587e82e551efcfbec98e4b906905dc6d..b36353053e86d30e2d62f5dca9e08470c133fe52 100644 (file)
@@ -88,3 +88,9 @@ class Auth(RESTController):
                                          '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)
index a9cca611b38e08b7f6287ed21ddec6822fc1e231..14938534d9f4077ba5401acd4e6afe6155b33c59 100644 (file)
@@ -86,9 +86,7 @@ class Module(MgrModule):
 
     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}\''
index 1d57eba406d65d7ac8be7a280219735d013d568b..8b32805fa7479de13e3803ca655c0608b0544cf4 100644 (file)
@@ -32,6 +32,19 @@ class AuthTest(ControllerTestCase):
         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):