Updated Branches: refs/heads/branch-1.2.5 2cb32c5ad -> 62317e95b
AMBARI-2681. setup ldap does not validate secondary url. (smohanty) Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/62317e95 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/62317e95 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/62317e95 Branch: refs/heads/branch-1.2.5 Commit: 62317e95b38ad10f46c817125fa06e9abb9dbc6f Parents: 2cb32c5 Author: Sumit Mohanty <[email protected]> Authored: Wed Jul 17 23:43:13 2013 -0700 Committer: Sumit Mohanty <[email protected]> Committed: Wed Jul 17 23:44:39 2013 -0700 ---------------------------------------------------------------------- ambari-server/src/main/python/ambari-server.py | 4 +- .../src/test/python/TestAmbaryServer.py | 70 ++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/62317e95/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 79ad867..36a6007 100755 --- a/ambari-server/src/main/python/ambari-server.py +++ b/ambari-server/src/main/python/ambari-server.py @@ -2418,7 +2418,7 @@ def setup_ldap(): ldap_properties_map_reqd =\ { ldap_property_list_reqd[0]:(LDAP_PRIMARY_URL_DEFAULT, "Primary URL* {{host:port}} {0}: ".format(get_prompt_default(LDAP_PRIMARY_URL_DEFAULT)), False),\ - ldap_property_list_reqd[1]:(LDAP_SECONDARY_URL_DEFAULT, "Secondary URL {0}: ".format(get_prompt_default(LDAP_SECONDARY_URL_DEFAULT)), True),\ + ldap_property_list_reqd[1]:(LDAP_SECONDARY_URL_DEFAULT, "Secondary URL {{host:port}} {0}: ".format(get_prompt_default(LDAP_SECONDARY_URL_DEFAULT)), True),\ ldap_property_list_reqd[2]:(LDAP_USE_SSL_DEFAULT, "Use SSL* [true/false] {0}: ".format(get_prompt_default(LDAP_USE_SSL_DEFAULT)), False),\ ldap_property_list_reqd[3]:(LDAP_USER_ATT_DEFAULT, "User name attribute* {0}: ".format(get_prompt_default(LDAP_USER_ATT_DEFAULT)), False),\ ldap_property_list_reqd[4]:(LDAP_BASE_DN_DEFAULT, "Base DN* {0}: ".format(get_prompt_default(LDAP_BASE_DN_DEFAULT)), False),\ @@ -2427,7 +2427,7 @@ def setup_ldap(): ldap_property_value_map = {} for idx, key in enumerate(ldap_property_list_reqd): - if idx == 0: + if idx in [0, 1]: pattern = REGEX_HOSTNAME_PORT elif idx in [2, 5]: pattern = REGEX_TRUE_FALSE http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/62317e95/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 3fb38c9..21543f7 100644 --- a/ambari-server/src/test/python/TestAmbaryServer.py +++ b/ambari-server/src/test/python/TestAmbaryServer.py @@ -3352,6 +3352,76 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV key=operator.itemgetter(0)) self.assertEquals(sorted_x, sorted_y) + @patch('__builtin__.raw_input') + @patch.object(ambari_server, 'get_is_secure') + @patch.object(ambari_server, 'get_YN_input') + @patch.object(ambari_server, 'update_properties') + @patch.object(ambari_server, 'search_file') + @patch.object(ambari_server, 'get_ambari_properties') + @patch.object(ambari_server, 'is_root') + def test_setup_ldap_invalid_input(self, is_root_method, get_ambari_properties_method, + search_file_message, + update_properties_method, + get_YN_input_method, + get_is_secure_method, + raw_input_mock): + out = StringIO.StringIO() + sys.stdout = out + is_root_method.return_value = True + search_file_message.return_value = "filepath" + + configs = { ambari_server.SECURITY_MASTER_KEY_LOCATION : "filepath", + ambari_server.SECURITY_KEYS_DIR : tempfile.gettempdir(), + ambari_server.SECURITY_IS_ENCRYPTION_ENABLED : "true" + } + + get_ambari_properties_method.return_value = configs + raw_input_mock.side_effect = ['a:3', 'b:b', 'host', 'b:2', 'false', 'uid', 'base', 'true'] + ambari_server.SILENT = False + get_YN_input_method.return_value = True + + ambari_server.setup_ldap() + + ldap_properties_map = \ + { + "authentication.ldap.primaryUrl" : "a:3", + "authentication.ldap.secondaryUrl" : "b:2", + "authentication.ldap.useSSL" : "false", + "authentication.ldap.usernameAttribute" : "uid", + "authentication.ldap.baseDn" : "base", + "authentication.ldap.bindAnonymously" : "true", + "client.security" : "ldap" + } + + 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)) + self.assertEquals(sorted_x, sorted_y) + self.assertTrue(get_YN_input_method.called) + self.assertTrue(8, raw_input_mock.call_count) + + raw_input_mock.reset_mock() + raw_input_mock.side_effect = ['a:3', '', 'b:2', 'false', 'uid', 'base', 'true'] + + ambari_server.setup_ldap() + + ldap_properties_map = \ + { + "authentication.ldap.primaryUrl" : "a:3", + "authentication.ldap.useSSL" : "false", + "authentication.ldap.usernameAttribute" : "uid", + "authentication.ldap.baseDn" : "base", + "authentication.ldap.bindAnonymously" : "true", + "client.security" : "ldap" + } + + 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)) + self.assertEquals(sorted_x, sorted_y) + self.assertTrue(5, raw_input_mock.call_count) + + sys.stdout = sys.__stdout__ @patch.object(ambari_server, 'get_is_secure') @patch.object(ambari_server, 'encrypt_password')
