Browse Source

AMBARI-9250 - LDAP Group sync truncates whitespace in group name (tbeerbower)

tbeerbower 10 năm trước cách đây
mục cha
commit
603775cfef

+ 1 - 1
ambari-server/src/main/python/ambari-server.py

@@ -2901,7 +2901,7 @@ def get_ldap_event_spec_names(file, specs, new_specs):
       new_spec = new_specs[0]
       with open(file, 'r') as names_file:
         names = names_file.read()
-        new_spec['names'] = ''.join(names.split())
+        new_spec['names'] = names.replace('\n', '').replace('\t', '')
         names_file.close()
         specs += new_specs
     else:

+ 21 - 0
ambari-server/src/test/python/TestAmbariServer.py

@@ -5187,6 +5187,27 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
       self.assertTrue("not configured" in fe.reason)
       pass
 
+  @patch("__builtin__.open")
+  @patch("os.path.exists")
+  def test_get_ldap_event_spec_names(self, os_path_exists_mock, open_mock):
+    os_path_exists_mock.return_value = 1
+    f = MagicMock()
+    f.__enter__().read.return_value = "\n\n\t some group, \tanother group, \n\t\tgrp, \ngroup*\n\n\n\n"
+
+    open_mock.return_value = f
+
+    bodies = [{"Event":{"specs":[]}}]
+    body = bodies[0]
+    events = body['Event']
+    specs = events['specs']
+
+    new_specs = [{"principal_type":"groups","sync_type":"specific","names":""}]
+
+    _ambari_server_.get_ldap_event_spec_names("groups.txt", specs, new_specs)
+
+    self.assertEquals("[{'Event': {'specs': [{'principal_type': 'groups', 'sync_type': 'specific', 'names': ' some group, another group, grp, group*'}]}}]", str(bodies))
+    pass
+
   @patch.object(_ambari_server_, "read_password")
   def test_configure_ldap_password(self, read_password_method):
     out = StringIO.StringIO()