incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject git commit: 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)
Date Fri, 23 Aug 2013 20:59:06 GMT
Updated Branches:
  refs/heads/trunk 8d822cb69 -> 01b1b682e


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)


Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/01b1b682
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/01b1b682
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/01b1b682

Branch: refs/heads/trunk
Commit: 01b1b682e2ea7b61df00caa3e2b248fa9a9feec8
Parents: 8d822cb
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Fri Aug 23 13:58:47 2013 -0700
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Fri Aug 23 13:58:47 2013 -0700

----------------------------------------------------------------------
 ambari-server/src/main/python/ambari-server.py  |  7 +-
 .../src/test/python/TestAmbaryServer.py         | 67 +++++++++++++++++++-
 2 files changed, 71 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/01b1b682/ambari-server/src/main/python/ambari-server.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari-server.py b/ambari-server/src/main/python/ambari-server.py
index afbe501..4a8af1b 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -2518,13 +2518,16 @@ def setup_ldap():
         SSL_TRUSTSTORE_TYPE_DEFAULT,
         "^(jks|jceks|pkcs12)?$", "Wrong type", False)
       ts_path = None
-      while not ts_path:
+      while True:
         ts_path = get_validated_string_input(
           "Path to TrustStore file {0}:".format(get_prompt_default(SSL_TRUSTSTORE_PATH_DEFAULT)),
           SSL_TRUSTSTORE_PATH_DEFAULT,
           ".*", False, False)
-        if not os.path.exists(ts_path):
+        if os.path.exists(ts_path):
+          break
+        else:
           print 'File not found.'
+
       ts_password = read_password("", ".*", "Password for TrustStore:", "Invalid characters
in password")
 
       ldap_property_value_map[SSL_TRUSTSTORE_TYPE_PROPERTY] = ts_type

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/01b1b682/ambari-server/src/test/python/TestAmbaryServer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestAmbaryServer.py b/ambari-server/src/test/python/TestAmbaryServer.py
index a671123..f20f878 100644
--- a/ambari-server/src/test/python/TestAmbaryServer.py
+++ b/ambari-server/src/test/python/TestAmbaryServer.py
@@ -3595,7 +3595,9 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
   @patch.object(ambari_server, 'search_file')
   @patch.object(ambari_server, 'get_ambari_properties')
   @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,
                 get_validated_string_input_method,
                 configure_ldap_password_method, update_properties_method,
@@ -3604,6 +3606,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     out = StringIO.StringIO()
     sys.stdout = out
 
+
     # Testing call under non-root
     is_root_method.return_value = False
     try:
@@ -3675,6 +3678,68 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     self.assertTrue(get_validated_string_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__
 
 


Mime
View raw message