Browse Source

Merge "Compare the encoded tag more accurately for huawei driver"

tags/4.0.0.0b1
Jenkins 2 years ago
parent
commit
235cb476b3

+ 1
- 1
manila/share/drivers/huawei/v3/helper.py View File

@@ -190,7 +190,7 @@ class RestHelper(object):
190 190
         need_encode = False
191 191
         for key in ['UserName', 'UserPassword']:
192 192
             node = root.find('Storage/%s' % key)
193
-            if node.text.find(prefix_name) > -1:
193
+            if node.text.startswith(prefix_name):
194 194
                 logininfo[key] = base64.b64decode(
195 195
                     six.b(node.text[4:])).decode()
196 196
             else:

+ 73
- 0
manila/tests/share/drivers/huawei/test_huawei_nas.py View File

@@ -26,6 +26,7 @@ import xml.dom.minidom
26 26
 import ddt
27 27
 import mock
28 28
 from oslo_serialization import jsonutils
29
+from xml.etree import ElementTree as ET
29 30
 
30 31
 from manila.common import constants as common_constants
31 32
 from manila import context
@@ -823,6 +824,45 @@ class FakeHuaweiNasDriver(huawei_nas.HuaweiNasDriver):
823 824
         self.plugin.private_storage = FakePrivateStorage()
824 825
 
825 826
 
827
+class FakeConfigParseTree(object):
828
+    class FakeNode(object):
829
+        def __init__(self, text):
830
+            self._text = text
831
+
832
+        @property
833
+        def text(self):
834
+            return self._text
835
+
836
+        @text.setter
837
+        def text(self, text):
838
+            self._text = text
839
+
840
+    class FakeRoot(object):
841
+        def __init__(self):
842
+            self._node_map = {}
843
+
844
+        def findtext(self, path, default=None):
845
+            if path in self._node_map:
846
+                return self._node_map[path].text
847
+            return default
848
+
849
+        def find(self, path):
850
+            if path in self._node_map:
851
+                return self._node_map[path]
852
+            return None
853
+
854
+    def __init__(self, path_value):
855
+        self.root = self.FakeRoot()
856
+        for k in path_value:
857
+            self.root._node_map[k] = self.FakeNode(path_value[k])
858
+
859
+    def getroot(self):
860
+        return self.root
861
+
862
+    def write(self, filename, format):
863
+        pass
864
+
865
+
826 866
 @ddt.ddt
827 867
 class HuaweiShareDriverTestCase(test.TestCase):
828 868
     """Tests GenericShareDriver."""
@@ -4492,3 +4532,36 @@ class HuaweiShareDriverTestCase(test.TestCase):
4492 4532
             logininfo = self.driver.plugin.helper._get_login_info()
4493 4533
             self.assertEqual('admin', logininfo['UserName'])
4494 4534
             self.assertEqual('Admin@storage', logininfo['UserPassword'])
4535
+
4536
+    @ddt.data({
4537
+        'username': 'abc',
4538
+        'password': '123456',
4539
+        'expect_username': 'abc',
4540
+        'expect_password': '123456',
4541
+    }, {
4542
+        'username': '!$$$YWJj',
4543
+        'password': '!$$$MTIzNDU2',
4544
+        'expect_username': 'abc',
4545
+        'expect_password': '123456',
4546
+    }, {
4547
+        'username': 'ab!$$$c',
4548
+        'password': '123!$$$456',
4549
+        'expect_username': 'ab!$$$c',
4550
+        'expect_password': '123!$$$456',
4551
+    })
4552
+    @ddt.unpack
4553
+    def test__get_login_info(self, username, password, expect_username,
4554
+                             expect_password):
4555
+        configs = {
4556
+            'Storage/RestURL': 'https://123456',
4557
+            'Storage/UserName': username,
4558
+            'Storage/UserPassword': password,
4559
+        }
4560
+        self.mock_object(
4561
+            ET, 'parse',
4562
+            mock.Mock(return_value=FakeConfigParseTree(configs)))
4563
+
4564
+        result = self.driver.plugin.helper._get_login_info()
4565
+        self.assertEqual(expect_username, result['UserName'])
4566
+        self.assertEqual(expect_password, result['UserPassword'])
4567
+        ET.parse.assert_called_once_with(self.fake_conf_file)

Loading…
Cancel
Save