浏览代码

HUE-787 [Desktop] Config dump view uses raw values instead of type cased values in template.

BoundConfig object can now return 'raw' config values via 'get_raw' method.
Config object get_value method can return both type cased values and original config values.
Added Test case to test 'WHITELIST', which is regex, and ensure the 'WHITELIST' config is in response as a string.
abec 13 年之前
父节点
当前提交
e2cc325853

+ 3 - 0
.gitignore

@@ -72,3 +72,6 @@ desktop/logs
 
 # Maven's target directory
 target
+
+# Reviewboard config file
+.reviewboardrc

+ 11 - 3
desktop/core/src/desktop/lib/conf.py

@@ -130,7 +130,12 @@ class BoundConfig(object):
   def get(self):
     """Get the data, or its default value."""
     data, present = self._get_data_and_presence()
-    return self.config.get_value(data, present=present, prefix=self.prefix)
+    return self.config.get_value(data, present=present, prefix=self.prefix, coerce_type=True)
+
+  def get_raw(self):
+    """Get raw config value. This maybe a non-string or non-iterable object."""
+    data, present = self._get_data_and_presence()
+    return self.config.get_value(data, present=present, prefix=self.prefix, coerce_type=False)
 
   def set_for_testing(self, data=None, present=True):
     """
@@ -225,7 +230,7 @@ class Config(object):
     """
     return BoundConfig(config=self, bind_to=conf, grab_key=self.key, prefix=prefix)
 
-  def get_value(self, val, present, prefix=None):
+  def get_value(self, val, present, prefix=None, coerce_type=True):
     """
     Return the value for this configuration variable from the
     currently loaded configuration.
@@ -240,7 +245,10 @@ class Config(object):
       raw_val = val
     else:
       raw_val = self.default
-    return self._coerce_type(raw_val, prefix)
+    if coerce_type:
+      return self._coerce_type(raw_val, prefix)
+    else:
+      return raw_val
 
   def validate(self, source):
     """

+ 1 - 1
desktop/core/src/desktop/templates/dump_config.mako

@@ -90,7 +90,7 @@ ${layout.menubar(section='dump_config')}
 			    ${recurse(v, depth + 1)}
 			    % endfor
 			  % else:
-			    <p>${str(config_obj.get())}</p>
+			    <p>${str(config_obj.get_raw())}</p>
 			    <p class="dump_config_help"><i>${config_obj.config.help or _('No help available.')}</i></p>
 			    <p class="dump_config_default">${_('Default:')} <i>${config_obj.config.default}</i></p>
 			  % endif

+ 9 - 0
desktop/core/src/desktop/tests.py

@@ -31,6 +31,7 @@ import logging
 import time
 from desktop.lib.django_util import TruncatingModel, PopupException
 import desktop.views as views
+import proxy.conf
 
 def setup_test_environment():
   """
@@ -93,6 +94,14 @@ def test_dump_config():
 
   clear()
 
+  CANARY = "(localhost|127\.0\.0\.1):(50030|50070|50060|50075)"
+  clear = proxy.conf.WHITELIST.set_for_testing(CANARY)
+
+  response1 = c.get('/dump_config')
+  assert_true(CANARY in response1.content)
+
+  clear()
+
 def test_prefs():
   c = make_logged_in_client()