Przeglądaj źródła

AMBARI-3018. ambari-server setup-ldap continues to prompt for the password for the truststore after showing the error that the specified file does not exist. (Myroslav Papirkovskyy via swagle)

Siddharth Wagle 11 lat temu
rodzic
commit
01b1b682e2

+ 5 - 2
ambari-server/src/main/python/ambari-server.py

@@ -2518,13 +2518,16 @@ def setup_ldap():
         SSL_TRUSTSTORE_TYPE_DEFAULT,
         SSL_TRUSTSTORE_TYPE_DEFAULT,
         "^(jks|jceks|pkcs12)?$", "Wrong type", False)
         "^(jks|jceks|pkcs12)?$", "Wrong type", False)
       ts_path = None
       ts_path = None
-      while not ts_path:
+      while True:
         ts_path = get_validated_string_input(
         ts_path = get_validated_string_input(
           "Path to TrustStore file {0}:".format(get_prompt_default(SSL_TRUSTSTORE_PATH_DEFAULT)),
           "Path to TrustStore file {0}:".format(get_prompt_default(SSL_TRUSTSTORE_PATH_DEFAULT)),
           SSL_TRUSTSTORE_PATH_DEFAULT,
           SSL_TRUSTSTORE_PATH_DEFAULT,
           ".*", False, False)
           ".*", False, False)
-        if not os.path.exists(ts_path):
+        if os.path.exists(ts_path):
+          break
+        else:
           print 'File not found.'
           print 'File not found.'
+
       ts_password = read_password("", ".*", "Password for TrustStore:", "Invalid characters in password")
       ts_password = read_password("", ".*", "Password for TrustStore:", "Invalid characters in password")
 
 
       ldap_property_value_map[SSL_TRUSTSTORE_TYPE_PROPERTY] = ts_type
       ldap_property_value_map[SSL_TRUSTSTORE_TYPE_PROPERTY] = ts_type

+ 66 - 1
ambari-server/src/test/python/TestAmbaryServer.py

@@ -3595,7 +3595,9 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
   @patch.object(ambari_server, 'search_file')
   @patch.object(ambari_server, 'search_file')
   @patch.object(ambari_server, 'get_ambari_properties')
   @patch.object(ambari_server, 'get_ambari_properties')
   @patch.object(ambari_server, 'is_root')
   @patch.object(ambari_server, 'is_root')
-  def test_setup_ldap(self, is_root_method, get_ambari_properties_method,
+  @patch.object(ambari_server, 'read_password')
+  @patch("os.path.exists")
+  def test_setup_ldap(self, exists_method, read_password_method, is_root_method, get_ambari_properties_method,
                 search_file_message, setup_master_key_method,
                 search_file_message, setup_master_key_method,
                 get_validated_string_input_method,
                 get_validated_string_input_method,
                 configure_ldap_password_method, update_properties_method,
                 configure_ldap_password_method, update_properties_method,
@@ -3604,6 +3606,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     out = StringIO.StringIO()
     out = StringIO.StringIO()
     sys.stdout = out
     sys.stdout = out
 
 
+
     # Testing call under non-root
     # Testing call under non-root
     is_root_method.return_value = False
     is_root_method.return_value = False
     try:
     try:
@@ -3675,6 +3678,68 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     self.assertTrue(get_validated_string_input_method.called)
     self.assertTrue(get_validated_string_input_method.called)
     self.assertTrue(get_YN_input_method.called)
     self.assertTrue(get_YN_input_method.called)
 
 
+    # truststore not found case
+
+    def os_path_exists(*args, **kwargs):
+      if "bogus" in args[0]:
+        return False
+      else:
+        return True
+      pass
+
+    def input_enable_ssl(*args, **kwargs):
+      if 'Bind anonymously' in args[0]:
+        return 'false'
+      if "SSL" in args[0]:
+        return "true"
+      if "Path to TrustStore file" in args[0]:
+        if input_enable_ssl.path_counter < 2:
+          input_enable_ssl.path_counter += 1
+          return "bogus"
+        else:
+          return "valid"
+      if args[1] == "true" or args[1] == "false":
+        return args[1]
+      else:
+        return "test"
+      pass
+
+    input_enable_ssl.path_counter = 0
+
+
+    exists_method.side_effect = os_path_exists
+    get_validated_string_input_method.side_effect = input_enable_ssl
+    read_password_method.return_value = "password"
+    get_YN_input_method.reset_mock()
+    get_YN_input_method.side_effect = [True, True]
+    update_properties_method.reset_mock()
+
+
+    ambari_server.setup_ldap()
+
+    self.assertTrue(read_password_method.called)
+
+    ldap_properties_map = \
+      {
+        "authentication.ldap.primaryUrl" : "test",
+        "authentication.ldap.secondaryUrl" : "test",
+        "authentication.ldap.useSSL" : "true",
+        "authentication.ldap.usernameAttribute" : "test",
+        "authentication.ldap.baseDn" : "test",
+        "authentication.ldap.bindAnonymously" : "false",
+        "authentication.ldap.managerDn" : "test",
+        "client.security" : "ldap",
+        "ssl.trustStore.type" : "test",
+        "ssl.trustStore.path" : "valid",
+        "ssl.trustStore.password" : "password",
+        ambari_server.LDAP_MGR_PASSWORD_PROPERTY : ambari_server.get_alias_string( \
+          ambari_server.LDAP_MGR_PASSWORD_ALIAS)
+      }
+
+    sorted_x = sorted(ldap_properties_map.iteritems(), key=operator.itemgetter(0))
+    sorted_y = sorted(update_properties_method.call_args[0][1].iteritems(),
+                      key=operator.itemgetter(0))
+
     sys.stdout = sys.__stdout__
     sys.stdout = sys.__stdout__