Răsfoiți Sursa

HUE-8744 [core] Add test for public views access

Romain 6 ani în urmă
părinte
comite
f1444eda7a

+ 3 - 2
desktop/core/src/desktop/lib/django_test_util.py

@@ -27,6 +27,7 @@ from django.contrib.auth.models import User, Group
 
 import nose.tools
 
+
 class Client(django.test.client.Client):
   """
   Extends client to have a get_json method.
@@ -85,12 +86,12 @@ def compact_whitespace(s):
   Also removes leading and trailing whitespce.
   """
   return _MULTI_WHITESPACE.sub(" ", s).strip()
-  
+
 def assert_equal_mod_whitespace(first, second, msg=None):
   """
   Asserts that two strings are equal, ignoring whitespace.
   """
-  nose.tools.assert_equal(compact_whitespace(first), 
+  nose.tools.assert_equal(compact_whitespace(first),
     compact_whitespace(second), msg)
 
 def assert_similar_pages(first, second, ratio=0.9, msg=None):

+ 3 - 1
desktop/core/src/desktop/middleware.py

@@ -70,9 +70,11 @@ MIDDLEWARE_HEADER = "X-Hue-Middleware-Response"
 DJANGO_VIEW_AUTH_WHITELIST = [
   django.views.static.serve,
   desktop.views.is_alive,
-  django_prometheus.exports.ExportToDjangoView
 ]
 
+if desktop.conf.ENABLE_PROMETHEUS.get():
+  DJANGO_VIEW_AUTH_WHITELIST.append(django_prometheus.exports.ExportToDjangoView)
+
 
 class AjaxMiddleware(object):
   """

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

@@ -28,25 +28,25 @@ import uuid
 import proxy.conf
 import tempfile
 
-from nose.plugins.attrib import attr
-from nose.plugins.skip import SkipTest
-from nose.tools import assert_true, assert_false, assert_equal, assert_not_equal, assert_raises, nottest
+from configobj import ConfigObj
+from django.db.models import query, CharField, SmallIntegerField
 from django.core.management import call_command
 from django.core.paginator import Paginator
 from django.conf.urls import url
 from django.contrib.auth.models import User
 from django.db import connection
 from django.urls import reverse
+from django.test.client import Client
+from django.views.static import serve
 from django.http import HttpResponse
-from django.db.models import query, CharField, SmallIntegerField
-
-from configobj import ConfigObj
-
-from settings import DATABASES
+from nose.plugins.attrib import attr
+from nose.plugins.skip import SkipTest
+from nose.tools import assert_true, assert_false, assert_equal, assert_not_equal, assert_raises, nottest
 
 from beeswax.conf import HIVE_SERVER_HOST
 from pig.models import PigScript
 from useradmin.models import GroupPermission
+from settings import DATABASES
 
 import desktop
 import desktop.conf
@@ -54,7 +54,9 @@ import desktop.urls
 import desktop.redaction as redaction
 import desktop.views as views
 
+from desktop.auth.backend import rewrite_user
 from desktop.appmanager import DESKTOP_APPS
+from desktop.middleware import DJANGO_VIEW_AUTH_WHITELIST
 from desktop.lib.django_test_util import make_logged_in_client
 from desktop.lib.conf import validate_path
 from desktop.lib.django_util import TruncatingModel
@@ -67,9 +69,9 @@ from desktop.models import Directory, Document, Document2, get_data_link, _versi
 from desktop.redaction import logfilter
 from desktop.redaction.engine import RedactionPolicy, RedactionRule
 from desktop.views import check_config, home, generate_configspec, load_confs, collect_validation_messages
-from desktop.auth.backend import rewrite_user
 from dashboard.conf import HAS_SQL_ENABLED
 
+
 LOG = logging.getLogger(__name__)
 
 def test_home():
@@ -144,6 +146,17 @@ def test_skip_wizard():
   response = c.get('/', follow=True)
   assert_true(['home.mako' in _template.filename for _template in response.templates], [_template.filename for _template in response.templates])
 
+def test_public_views():
+  c = Client()
+
+  for view in DJANGO_VIEW_AUTH_WHITELIST:
+    if view is serve:
+      url = reverse(view, kwargs={'path': 'desktop/art/favicon.ico'})
+    else:
+      url = reverse(view)
+    response = c.get(url)
+    assert_equal(200, response.status_code)
+
 def test_log_view():
   c = make_logged_in_client()
 

+ 2 - 3
desktop/core/src/desktop/views.py

@@ -35,12 +35,12 @@ from django.shortcuts import render_to_response
 from django.http import HttpResponse
 from django.http.response import StreamingHttpResponse
 from django.urls import reverse
-from wsgiref.util import FileWrapper
 from django.shortcuts import redirect
 from django.utils.translation import ugettext as _
 from django.views.decorators.http import require_POST
 from configobj import ConfigObj, get_extra_values, ConfigObjError
-
+from wsgiref.util import FileWrapper
+from webpack_loader.utils import get_files
 import django.views.debug
 
 import desktop.conf
@@ -62,7 +62,6 @@ from desktop.log.access import access_log_level, access_warn, AccessInfo
 from desktop.log import set_all_debug as _set_all_debug, reset_all_debug as _reset_all_debug, get_all_debug as _get_all_debug
 from desktop.models import Settings, hue_version, _get_apps, UserPreferences
 
-from webpack_loader.utils import get_files
 
 LOG = logging.getLogger(__name__)