incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r1499862 - in /incubator/ambari/trunk/ambari-server/src: main/python/ambari-server.py test/python/TestAmbaryServer.py
Date Thu, 04 Jul 2013 20:37:52 GMT
Author: mahadev
Date: Thu Jul  4 20:37:52 2013
New Revision: 1499862

URL: http://svn.apache.org/r1499862
Log:
AMBARI-2568. Setup LDAP does not validate true/false response. (Dmitry L via mahadev)

Modified:
    incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py
    incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py

Modified: incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py?rev=1499862&r1=1499861&r2=1499862&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py (original)
+++ incubator/ambari/trunk/ambari-server/src/main/python/ambari-server.py Thu Jul  4 20:37:52
2013
@@ -262,6 +262,9 @@ DATABASE_DROP_SCRIPTS = ['/var/lib/ambar
 
 REGEX_IP_ADDRESS = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
 REGEX_HOSTNAME = "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$"
+REGEX_HOSTNAME_PORT = "^(.*:[0-9]{1,5}$)"
+REGEX_TRUE_FALSE = "^(true|false)?$"
+REGEX_ANYTHING = ".*"
 
 POSTGRES_EXEC_ARGS = "-h {0} -p {1} -d {2} -U {3} -f {4} -v username='\"{3}\"'"
 ORACLE_EXEC_ARGS = "-S '{0}/{1}@(description=(address=(protocol=TCP)(host={2})(port={3}))(connect_data=(sid={4})))'
@{5} {0}"
@@ -2358,7 +2361,12 @@ def setup_ldap():
 
   ldap_property_value_map = {}
   for idx, key in enumerate(ldap_property_list_reqd):
-    pattern = ".*" if idx != 0 else "^(.*:[0-9]{1,5}$)"
+    if idx == 0:
+      pattern = REGEX_HOSTNAME_PORT
+    elif idx in [2, 5]:
+      pattern = REGEX_TRUE_FALSE
+    else:
+      pattern = REGEX_ANYTHING
     input = get_validated_string_input(ldap_properties_map_reqd[key][1],
       ldap_properties_map_reqd[key][0], pattern,
       "Invalid characters in the input!", False, ldap_properties_map_reqd[key][2])

Modified: incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py?rev=1499862&r1=1499861&r2=1499862&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py (original)
+++ incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py Thu Jul  4 20:37:52
2013
@@ -17,6 +17,7 @@ limitations under the License.
 '''
 
 import StringIO
+import re
 from unittest import TestCase
 import sys
 from mock.mock import patch
@@ -3170,6 +3171,38 @@ class TestAmbariServer(TestCase):
     self.assertTrue(str1 != str2)
 
 
+  def test_regexps(self):
+    res = re.search(ambari_server.REGEX_HOSTNAME_PORT, "")
+    self.assertTrue(res is None)
+    res = re.search(ambari_server.REGEX_HOSTNAME_PORT, "ddd")
+    self.assertTrue(res is None)
+    res = re.search(ambari_server.REGEX_HOSTNAME_PORT, "gg:ff")
+    self.assertTrue(res is None)
+    res = re.search(ambari_server.REGEX_HOSTNAME_PORT, "gg:55444325")
+    self.assertTrue(res is None)
+    res = re.search(ambari_server.REGEX_HOSTNAME_PORT, "gg:555")
+    self.assertTrue(res is not None)
+
+    res = re.search(ambari_server.REGEX_TRUE_FALSE, "")
+    self.assertTrue(res is not None)
+    res = re.search(ambari_server.REGEX_TRUE_FALSE, "t")
+    self.assertTrue(res is None)
+    res = re.search(ambari_server.REGEX_TRUE_FALSE, "trrrr")
+    self.assertTrue(res is None)
+    res = re.search(ambari_server.REGEX_TRUE_FALSE, "true|false")
+    self.assertTrue(res is None)
+    res = re.search(ambari_server.REGEX_TRUE_FALSE, "true")
+    self.assertTrue(res is not None)
+    res = re.search(ambari_server.REGEX_TRUE_FALSE, "false")
+    self.assertTrue(res is not None)
+
+    res = re.search(ambari_server.REGEX_ANYTHING, "")
+    self.assertTrue(res is not None)
+    res = re.search(ambari_server.REGEX_ANYTHING, "t")
+    self.assertTrue(res is not None)
+    res = re.search(ambari_server.REGEX_ANYTHING, "trrrr")
+    self.assertTrue(res is not None)
+
 
   def get_sample(self, sample):
     """



Mime
View raw message