Browse Source

HUE-1313 [core] Unicode error in check_config

Protect for values not the name or description of the config property
Cleanup TestAboutBase
Romain Rigaux 12 years ago
parent
commit
5d23d3e4cc

+ 1 - 1
apps/about/src/about/templates/admin_wizard.mako

@@ -67,7 +67,7 @@ ${ commonheader(_('Quick Start'), "quickstart", user, "100px") | n,unicode }
           <h5>${ _('Check your current configuration') }</h5>
         </div>
         <div class="widget-content">
-          ${ check_config.content | n,unicode }
+          ${ check_config | n,unicode }
         </div>
       </div>
     </div>

+ 19 - 20
apps/about/src/about/tests.py

@@ -31,7 +31,8 @@ from desktop.models import Settings
 from oozie.tests import OozieBase
 
 
-class TestAboutBase(OozieBase):
+
+class TestAboutBase(object):
   def setUp(self):
     self.client = make_logged_in_client(username="about", is_superuser=False)
     grant_access("about", "about", "about")
@@ -40,10 +41,9 @@ class TestAboutBase(OozieBase):
     grant_access("about_admin", "about_admin", "about")
 
 
-class TestAbout(TestAboutBase):
+class TestAbout(TestAboutBase, OozieBase):
 
   def test_admin_wizard_permissions(self):
-
     response = self.client_admin.get(reverse('about:index'))
     assert_true('Check Configuration' in response.content, response.content)
 
@@ -51,23 +51,22 @@ class TestAbout(TestAboutBase):
     assert_false('Check Configuration' in response.content, response.content)
 
 
-def test_collect_usage():
-  client = make_logged_in_client(username="about", is_superuser=False)
-  grant_access("about", "about", "about")
+class TestAboutWithNoCluster(TestAboutBase):
 
-  collect_usage = Settings.get_settings().collect_usage
+  def test_collect_usage(self):
+    collect_usage = Settings.get_settings().collect_usage
 
-  try:
-    response = client.post(reverse('about:collect_usage'), {'collect_usage': False})
-    data = json.loads(response.content)
-    assert_equal(data['status'], 0)
-    assert_false(data['collect_usage'] == True) # Weird but works
+    try:
+      response = self.client.post(reverse('about:collect_usage'), {'collect_usage': False})
+      data = json.loads(response.content)
+      assert_equal(data['status'], 0)
+      assert_false(data['collect_usage'] == True) # Weird but works
 
-    response = client.post(reverse('about:collect_usage'), {'collect_usage': True})
-    data = json.loads(response.content)
-    assert_equal(data['status'], 0)
-    assert_true(data['collect_usage'])
-  finally:
-    settings = Settings.get_settings()
-    settings.collect_usage = collect_usage
-    settings.save()
+      response = self.client.post(reverse('about:collect_usage'), {'collect_usage': True})
+      data = json.loads(response.content)
+      assert_equal(data['status'], 0)
+      assert_true(data['collect_usage'])
+    finally:
+      settings = Settings.get_settings()
+      settings.collect_usage = collect_usage
+      settings.save()

+ 1 - 1
apps/about/src/about/views.py

@@ -38,7 +38,7 @@ def admin_wizard(request):
 
   return render('admin_wizard.mako', request, {
       'version': settings.HUE_DESKTOP_VERSION,
-      'check_config': check_config(request),
+      'check_config': check_config(request).content,
       'apps': dict([(app.name, app) for app in apps]),
       'app_names': app_names,
       'collect_usage': collect_usage,

+ 3 - 5
desktop/core/src/desktop/templates/dump_config.mako

@@ -142,19 +142,17 @@ ${layout.menubar(section='dump_config')}
                   <td>
              % endif
               % if isinstance(config_obj, BoundContainer):
-                  <p class="dump_config_help"><i>${config_obj.config.help or _('No help available.')}</i></p>            
+                  <p class="dump_config_help"><i>${config_obj.config.help or _('No help available.')}</i></p>
                   ${recurseList(config_obj.get().values(), depth + 1)}
               % else:
-                <p>${str(config_obj.get_raw())}</p>
+                <p>${ str(config_obj.get_raw()).decode('utf-8', 'replace') }</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>
+                <p class="dump_config_default">${_('Default:')} <i>${str(config_obj.config.default).decode('utf-8', 'replace')}</i></p>
               % endif
               </td>
             </tr>
         </%def>
 
-
-
     </div>
 
 ${ commonfooter(messages) | n,unicode }

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

@@ -132,6 +132,14 @@ def test_dump_config():
 
   clear()
 
+  CANARY = '/tmp/spacé.dat'
+  finish = proxy.conf.WHITELIST.set_for_testing(CANARY)
+  try:
+    response = c.get('/dump_config')
+    assert_true(CANARY in response.content, response.content)
+  finally:
+    finish()
+
   # Login as someone else
   client_not_me = make_logged_in_client(username='not_me', is_superuser=False, groupname='test')
   grant_access("not_me", "test", "desktop")
@@ -383,7 +391,7 @@ def test_log_event():
   c.post("/log_frontend_event", {
     "message": "01234567" * 1024})
   assert_equal("INFO", handler.records[-1].levelname)
-  assert_equal("Untrusted log event from user test: " + "01234567"*(1024/8), 
+  assert_equal("Untrusted log event from user test: " + "01234567"*(1024/8),
     handler.records[-1].message)
 
   root.removeHandler(handler)