]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
mgr/dashboard: encode non-ascii string before passing it to exec_cmd()
authorKefu Chai <kchai@redhat.com>
Wed, 31 Mar 2021 11:00:59 +0000 (19:00 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 31 Mar 2021 11:14:14 +0000 (19:14 +0800)
commit6b6eddaa2d438396849e7fb3e043c7b74e6b904c
treefd82206188a3dafd985f72741abae6aabdb471e4
parentae0e711165b2b872a55a85ae053cd415cad12705
mgr/dashboard: encode non-ascii string before passing it to exec_cmd()

because on Python3, tempfile.TemporaryFile() is opened in binary mode by
default, we need to encode non-ascii string before write to it.
otherwise, we have following failure:

self = <dashboard.tests.test_access_control.AccessControlTest testMethod=test_unicode_password>

    def test_unicode_password(self):
        self.test_create_user()
        password = '\u7ae0\u9c7c\u4e0d\u662f\u5bc6\u7801'
        with tempfile.TemporaryFile(mode='w+') as pwd_file:
>           pwd_file.write(password)
E           UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-5: ordinal not in range(256)

tests/test_access_control.py:576: UnicodeEncodeError

this change is not cherry-picked from master, as master has dropped
python2 support.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/pybind/mgr/dashboard/tests/test_access_control.py