Return-Path: X-Original-To: apmail-incubator-ambari-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-ambari-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AC2B2101FF for ; Fri, 23 Aug 2013 20:59:06 +0000 (UTC) Received: (qmail 6669 invoked by uid 500); 23 Aug 2013 20:59:06 -0000 Delivered-To: apmail-incubator-ambari-commits-archive@incubator.apache.org Received: (qmail 6648 invoked by uid 500); 23 Aug 2013 20:59:06 -0000 Mailing-List: contact ambari-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@incubator.apache.org Delivered-To: mailing list ambari-commits@incubator.apache.org Received: (qmail 6641 invoked by uid 99); 23 Aug 2013 20:59:06 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Aug 2013 20:59:06 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 617498C3FD7; Fri, 23 Aug 2013 20:59:06 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: swagle@apache.org To: ambari-commits@incubator.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer 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 +0000 (UTC) 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 Authored: Fri Aug 23 13:58:47 2013 -0700 Committer: Siddharth Wagle 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__