]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: delete EOF when reading passwords from file 39438/head
authorAlfonso Martínez <almartin@redhat.com>
Tue, 9 Feb 2021 10:17:52 +0000 (11:17 +0100)
committerAlfonso Martínez <almartin@redhat.com>
Fri, 12 Feb 2021 11:19:24 +0000 (12:19 +0100)
Signed-off-by: Alfonso Martínez <almartin@redhat.com>
(cherry picked from commit caeadf1397db00c6b7ba218b1910508099802e39)

src/pybind/mgr/dashboard/tests/test_access_control.py
src/pybind/mgr/mgr_module.py

index 1a479aa67fdebfddd63f8ef931510562a8d15496..edc36fb5aa66bdb8da8858d49f5d259289b64543 100644 (file)
@@ -556,6 +556,18 @@ class AccessControlTest(unittest.TestCase, CLICommandTestMixin):
                                       'admin@user.com')
         self.assertGreaterEqual(user['lastUpdate'], user_orig['lastUpdate'])
 
+    def test_sanitize_password(self):
+        self.test_create_user()
+        password = 'myPass\\n\\r\\n'
+        with open('/tmp/test_sanitize_password.txt', 'w+') as pwd_file:
+            # Add new line separators (like some text editors when a file is saved).
+            pwd_file.write('{}{}'.format(password, '\n\r\n\n'))
+            pwd_file.seek(0)
+            user = self.exec_cmd('ac-user-set-password', username='admin',
+                                 inbuf=pwd_file.read(), force_password=True)
+            pass_hash = password_hash(password, user['password'])
+            self.assertEqual(user['password'], pass_hash)
+
     def test_set_user_password_nonexistent_user(self):
         with self.assertRaises(CmdException) as ctx:
             self.exec_cmd('ac-user-set-password', username='admin',
index e640f1a6f3626d24cb2d4141c5106c3e8d551fd4..79cbc95036e32f129a5f233245a4af48d12845a1 100644 (file)
@@ -398,8 +398,10 @@ def CLICheckNonemptyFileInput(func):
     def check(*args, **kwargs):
         if not 'inbuf' in kwargs:
             return -errno.EINVAL, '', ERROR_MSG_NO_INPUT_FILE
-        if not kwargs['inbuf'] or (isinstance(kwargs['inbuf'], str)
-                                   and not kwargs['inbuf'].strip('\n')):
+        if isinstance(kwargs['inbuf'], str):
+            # Delete new line separator at EOF (it may have been added by a text editor).
+            kwargs['inbuf'] = kwargs['inbuf'].rstrip('\r\n').rstrip('\n')
+        if not kwargs['inbuf']:
             return -errno.EINVAL, '', ERROR_MSG_EMPTY_INPUT_FILE
         return func(*args, **kwargs)
     return check