Przeglądaj źródła

[proxy] Proxy app doesn't work if blacklist is empty

Add better default and change empty strings to not be included.
Abraham Elmahrek 12 lat temu
rodzic
commit
88ae146

+ 2 - 2
apps/proxy/src/proxy/conf.py

@@ -23,10 +23,10 @@ WHITELIST = Config(
   key="whitelist",
   default="(localhost|127\.0\.0\.1):(50030|50070|50060|50075)",
   help="Comma-separated list of regular expressions, which match 'host:port' of requested proxy target.",
-  type=list_of_compiled_res)
+  type=list_of_compiled_res(skip_empty=True))
 
 BLACKLIST = Config(
   key="blacklist",
   default=(),
   help="Comma-separated list of regular expressions, which match any prefix of 'host:port/path' of requested proxy target. This does not support matching GET parameters.",
-  type=list_of_compiled_res)
+  type=list_of_compiled_res(skip_empty=True))

+ 1 - 1
desktop/conf.dist/hue.ini

@@ -500,7 +500,7 @@
   # Comma-separated list of regular expressions,
   # which match any prefix of 'host:port/path' of requested proxy target.
   # This does not support matching GET parameters.
-  ## blacklist=()
+  ## blacklist=
 
 
 ###########################################################################

+ 1 - 1
desktop/conf/pseudo-distributed.ini.tmpl

@@ -541,7 +541,7 @@
   # Comma-separated list of regular expressions,
   # which match any prefix of 'host:port/path' of requested proxy target.
   # This does not support matching GET parameters.
-  ## blacklist=()
+  ## blacklist=
 
 
 ###########################################################################

+ 1 - 1
desktop/core/src/desktop/conf.py

@@ -117,7 +117,7 @@ REDIRECT_WHITELIST = Config(
   help=_("Comma-separated list of regular expressions, which match the redirect URL."
          "For example, to restrict to your local domain and FQDN, the following value can be used:"
          "  ^\/.*$,^http:\/\/www.mydomain.com\/.*$"),
-  type=list_of_compiled_res,
+  type=list_of_compiled_res(skip_empty=True),
   default='')
 
 def is_https_enabled():

+ 7 - 4
desktop/core/src/desktop/lib/conf.py

@@ -628,10 +628,13 @@ def coerce_json_dict(value):
     return value
   raise Exception("Could not coerce %r to json dictionary." % value)
 
-def list_of_compiled_res(list_of_strings):
-  if isinstance(list_of_strings, str):
-    list_of_strings = [ list_of_strings ]
-  return list(re.compile(x) for x in list_of_strings)
+def list_of_compiled_res(skip_empty=False):
+  def fn(list_of_strings):
+    if isinstance(list_of_strings, basestring):
+      list_of_strings = list_of_strings.split(',')
+    list_of_strings = filter(lambda string: string if skip_empty else True, list_of_strings)
+    return list(re.compile(x) for x in list_of_strings)
+  return fn
 
 def validate_path(confvar, is_dir=None, fs=os.path, message='Path does not exist on the filesystem.'):
   """

+ 5 - 2
desktop/core/src/desktop/middleware_test.py

@@ -17,6 +17,7 @@
 
 from desktop.lib.django_test_util import make_logged_in_client
 from desktop.lib.test_utils import add_permission
+from django.conf import settings
 import desktop.conf
 
 from nose.tools import assert_equal
@@ -89,6 +90,7 @@ def test_ensure_safe_method_middleware():
 
 def test_ensure_safe_redirect_middleware():
   done = []
+  settings.MIDDLEWARE_CLASSES.append('desktop.middleware.EnsureSafeRedirectURLMiddleware')
   try:
     # Super user
     c = make_logged_in_client()
@@ -98,7 +100,7 @@ def test_ensure_safe_redirect_middleware():
     assert_equal(200, response.status_code)
 
     # Disallow most redirects
-    done.append(desktop.conf.REDIRECT_WHITELIST.set_for_testing('\d+'))
+    done.append(desktop.conf.REDIRECT_WHITELIST.set_for_testing('^\d+$'))
     response = c.get("")
     assert_equal(403, response.status_code)
 
@@ -111,7 +113,8 @@ def test_ensure_safe_redirect_middleware():
     # should have a logic OR functionality.
     done.append(desktop.conf.REDIRECT_WHITELIST.set_for_testing('\d+,.*'))
     response = c.get("")
-    assert_equal(403, response.status_code)
+    assert_equal(302, response.status_code)
   finally:
+    settings.MIDDLEWARE_CLASSES.pop()
     for finish in done:
       finish()