Beispiel #1
0
    def test_facted_page_xss(self, client, project):
        query = 'XSS'
        page_search = PageSearch(query=query, user='')
        results = page_search.execute()
        expected = """
        &lt;h3&gt;<span>XSS</span> exploit&lt;&#x2F;h3&gt;
        """.strip()

        hits = results.hits.hits
        assert len(hits) == 1  # there should be only one result

        inner_hits = hits[0]['inner_hits']

        domain_hits = inner_hits['domains']['hits']['hits']
        assert len(
            domain_hits) == 0  # there shouldn't be any results from domains

        section_hits = inner_hits['sections']['hits']['hits']
        assert len(section_hits) == 1

        section_content_highlight = section_hits[0]['highlight'][
            'sections.content']
        assert len(section_content_highlight) == 1

        assert expected in section_content_highlight[0]
Beispiel #2
0
    def test_facted_page_xss(self, all_projects):
        query = '"XSS"'
        page_search = PageSearch(query=query, projects={'docs': 'latest'})
        results = page_search.execute()
        expected = """
        &lt;h3&gt;<span>XSS</span> exploit&lt;&#x2F;h3&gt;
        """.strip()

        hits = results.hits.hits
        assert len(hits) == 1
        assert hits[0]['_source']['version'] == 'latest'

        inner_hits = hits[0]['inner_hits']

        domain_hits = inner_hits['domains']['hits']['hits']
        assert len(
            domain_hits) == 0  # there shouldn't be any results from domains

        section_hits = inner_hits['sections']['hits']['hits']
        assert len(section_hits) == 1

        section_content_highlight = section_hits[0]['highlight'][
            'sections.content']
        assert len(section_content_highlight) == 1

        assert expected in section_content_highlight[0]
Beispiel #3
0
    def test_search_combined_result(self, client, project):
        """Check search result are combined of both `AND` and `OR` operator

        If query is `Foo Bar` then the result should be as following order:

        - Where both `Foo Bar` is present
        - Where `Foo` or `Bar` is present
        """
        query = 'Elasticsearch Query'
        page_search = PageSearch(query=query)
        results = page_search.execute()
        assert len(results) == 6

        result_paths_latest = [
            r.path for r in results if r.version == 'latest'
        ]
        result_paths_stable = [
            r.path for r in results if r.version == 'stable'
        ]
        # ``guides/wipe-environment`` page has both ``Elasticsearch Query`` words
        # ``docker`` page has ``Elasticsearch`` word
        # ``installation`` page has ``Query`` word.
        expected_paths = ['guides/wipe-environment', 'docker', 'installation']

        assert result_paths_latest == expected_paths
        assert result_paths_stable == expected_paths
    def test_search_exact_match(self, client, project, case):
        """Check quoted query match exact phrase with case insensitively

        Making a query with quoted text like ``"foo bar"`` should match
        exactly ``foo bar`` or ``Foo Bar`` etc
        """
        # `Sphinx` word is present both in `kuma` and `docs` files
        # But the phrase `Sphinx uses` is available only in kuma docs.
        # So search with this phrase to check
        query_text = r'"Sphinx uses"'
        cased_query = getattr(query_text, case)
        query = cased_query()

        page_search = PageSearch(query=query)
        results = page_search.execute()

        assert len(results) == 1
        assert results[0]['project'] == 'kuma'
        assert results[0]['path'] == 'testdocumentation'