コード例 #1
0
    async def test_add_alternate_url_response_to_knowledge_base(self):
        response = StaticResponse(200, {})
        response.content = "response content"
        self.engine.response = response

        await self.runner.perform_ok(
            self.create_entry("http://example.com/test",
                              response_content="response"))
        await self.runner.perform_ok(
            self.create_entry("http://example.com/123/",
                              response_content="response"))
        await self.runner.perform_ok(
            self.create_entry("http://example.com/.test",
                              response_content="response"))
        await self.runner.perform_ok(
            self.create_entry("http://example.com/123/test.js",
                              response_content="response"))

        raw = ContentHashSampling()._hash(response)
        self.assertEqual(
            self.kb.soft_404_responses["http://example.com/"], {
                "/\l": [
                    ContentSignature(code=200,
                                     content_simhash=ANY,
                                     content_hash=raw,
                                     content_sample=ANY)
                ],
                "/\d/": [
                    ContentSignature(code=200,
                                     content_simhash=ANY,
                                     content_hash=raw,
                                     content_sample=ANY)
                ],
                "/.\l": [
                    ContentSignature(code=200,
                                     content_simhash=ANY,
                                     content_hash=raw,
                                     content_sample=ANY)
                ],
                "/123/\l.js": [
                    ContentSignature(code=200,
                                     content_simhash=ANY,
                                     content_hash=raw,
                                     content_sample=ANY)
                ]
            })
コード例 #2
0
    async def test_add_alternate_url_response_to_knowledge_base(self):
        response = StaticResponse(200, {})
        response.content = "response content"
        self.engine.response = response

        await self.rule.after_response(
            self.create_entry("http://example.com/test",
                              response_content="response"))
        await self.rule.after_response(
            self.create_entry("http://example.com/123/",
                              response_content="response"))
        await self.rule.after_response(
            self.create_entry("http://example.com/.test",
                              response_content="response"))
        await self.rule.after_response(
            self.create_entry("http://example.com/123/test.js",
                              response_content="response"))

        simhash = Simhash(response.content).value
        self.assertEqual(
            self.kb.soft_404_responses["http://example.com/"], {
                "/\l": {
                    "code": 200,
                    "content_simhash": simhash
                },
                "/\d/": {
                    "code": 200,
                    "content_simhash": simhash
                },
                "/.\l": {
                    "code": 200,
                    "content_simhash": simhash
                },
                "/\d/\l.js": {
                    "code": 200,
                    "content_simhash": simhash
                }
            })