You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2013/07/18 08:44:06 UTC
git commit: AMBARI-2681. setup ldap does not validate secondary url.
(smohanty)
Updated Branches:
refs/heads/trunk f79e2f5cd -> d5810bd61
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/d5810bd6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/d5810bd6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/d5810bd6
Branch: refs/heads/trunk
Commit: d5810bd615ed989db1184710ef5bad8eccd34dcc
Parents: f79e2f5
Author: Sumit Mohanty <sm...@hortonworks.com>
Authored: Wed Jul 17 23:43:13 2013 -0700
Committer: Sumit Mohanty <sm...@hortonworks.com>
Committed: Wed Jul 17 23:43:13 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/d5810bd6/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 b4a15bc..c769f90 100755
--- a/ambari-server/src/main/python/ambari-server.py
+++ b/ambari-server/src/main/python/ambari-server.py
@@ -2434,7 +2434,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),\
@@ -2443,7 +2443,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/d5810bd6/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 8e5cd2c..cfe1a99 100644
--- a/ambari-server/src/test/python/TestAmbaryServer.py
+++ b/ambari-server/src/test/python/TestAmbaryServer.py
@@ -3402,6 +3402,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')