def test_knox_compatibility(self): """Checks that the template files conform to the requirements for compatibility with the Apache Knox service definition.""" # Matches all 'a' links with an 'href' that doesn't start with either '#' (which stays # on the same page an so doesn't need to the hostname) or '{{ __common__.host-url }}' # Note that if we ever need to add a link that doesn't conform to this, we will # probably also have to change the Knox service definition. href_regex = "<(a|link) .*? href=['\"](?!({{ __common__.host-url }})|#)" # Matches all 'script' tags that aren't absoluve urls. script_regex = "<script .*?src=['\"](?!({{ __common__.host-url }})|http)" # Matches all 'form' tags that are not followed by including the hidden inputs. form_regex = "<form [^{]*?>(?!{{>www/form-hidden-inputs.tmpl}})" # Matches XMLHttpRequest.open() in javascript that are not followed with make_url(). javascript_regex = "open\(['\"]GET['\"], (?!make_url)" # Matches urls in json parameters passed to DataTables. datatables_regex = "url: ['\"](?!make_url)" regex = "(%s)|(%s)|(%s)|(%s)|(%s)" % \ (href_regex, script_regex, form_regex, javascript_regex, datatables_regex) results = grep_dir(os.path.join(os.environ['IMPALA_HOME'], "www"), regex, ".*\.tmpl") assert len(results) == 0, \ "All links on the webui must include the webserver host: %s" % results # Check that when Knox integration is not being used, the links are relative, by # checking for the root link from the header. self.get_and_check_status(self.ROOT_URL, "href='/'", self.IMPALAD_TEST_PORT) # Check that if the 'x-forwarded-context' header is present in the request, the links # are written as absolute. self.get_and_check_status(self.ROOT_URL, "href='http://.*:%s/'" % self.IMPALAD_TEST_PORT[0], self.IMPALAD_TEST_PORT, regex=True, headers={'X-Forwarded-Context': '/gateway'})
def test_knox_compatability(self): """Checks that the template files conform to the requirements for compatability with the Apache Knox service definition.""" # Matches all 'a' links with an 'href' that doesn't start with either '#' (which stays # on the same page an so doesn't need to the hostname) or '{{ __common__.host-url }}' # Note that if we ever need to add a link that doesn't conform to this, we will # probably also have to change the Knox service definition. href_regex = "<a .*? href=['\"](?!({{ __common__.host-url }})|#)" # Matches all 'form' tags that are not followed by including the hidden inputs. form_regex = "<form [^{]*?>(?!{{>www/form-hidden-inputs.tmpl}})" regex = "(%s)|(%s)" % (href_regex, form_regex) results = grep_dir("/home/thomas/Impala/www", regex, ".*\.tmpl") assert len(results) == 0, \ "All links on the webui must include the webserver host: %s" % results
def test_knox_compatability(self): """Checks that the template files conform to the requirements for compatability with the Apache Knox service definition.""" # Matches all 'a' links with an 'href' that doesn't start with either '#' (which stays # on the same page an so doesn't need to the hostname) or '{{ __common__.host-url }}' # Note that if we ever need to add a link that doesn't conform to this, we will # probably also have to change the Knox service definition. href_regex = "<a .*? href=['\"](?!({{ __common__.host-url }})|#)" # Matches all 'form' tags that are not followed by including the hidden inputs. form_regex = "<form [^{]*?>(?!{{>www/form-hidden-inputs.tmpl}})" # Matches XMLHttpRequest.open() in javascript that are not followed with make_url(). javascript_regex = "open\(['\"]GET['\"], (?!make_url)" regex = "(%s)|(%s)|(%s)" % (href_regex, form_regex, javascript_regex) results = grep_dir(os.path.join(os.environ['IMPALA_HOME'], "www"), regex, ".*\.tmpl") assert len(results) == 0, \ "All links on the webui must include the webserver host: %s" % results