def test_safebrowsing_analyzer_class(self):
     """Test core functionality of the analyzer class."""
     index_name = "test"
     sketch_id = 1
     analyzer = safebrowsing.SafeBrowsingSketchPlugin(index_name, sketch_id)
     self.assertEqual(analyzer.index_name, index_name)
     self.assertEqual(analyzer.sketch.id, sketch_id)
    def test_do_safebrowsing_lookup(self):
        index_name = "test"
        sketch_id = 1
        analyzer = safebrowsing.SafeBrowsingSketchPlugin(index_name, sketch_id)

        with HTTMock(self.safebrowsing_find_mock):
            EXPECTED_RESULT = {
                "http://A": {
                    "platformType": "ANY_PLATFORM",
                    "threatType": "MALWARE",
                },
                "https://B": {
                    "platformType": "WINDOWS",
                    "threatType": "MALWARE",
                },
            }

            # pylint: disable=protected-access
            actual_result = analyzer._do_safebrowsing_lookup(
                ["http://A", "https://B"],
                [],
                [],
            )

            self.assertEqual(
                OrderedDict(sorted(EXPECTED_RESULT.items(), ), ),
                OrderedDict(sorted(actual_result.items(), ), ),
            )
    def test_helper_functions(self):
        """Tests the helper functions used by the analyzer."""
        index_name = "test"
        sketch_id = 1
        analyzer = safebrowsing.SafeBrowsingSketchPlugin(index_name, sketch_id)

        HELPERS = [
            self.check_sanitize_url,
            self.check_allowlist,
        ]

        for helper in HELPERS:
            helper(analyzer)
Exemple #4
0
    def test_do_safebrowsing_lookup(self):
        index_name = 'test'
        sketch_id = 1
        analyzer = safebrowsing.SafeBrowsingSketchPlugin(index_name, sketch_id)

        with HTTMock(self.safebrowsing_find_mock):
            EXPECTED_RESULT = {
                'http://A': {
                    'platformType': 'ANY_PLATFORM',
                    'threatType': 'MALWARE',
                },
                'https://B': {
                    'platformType': 'WINDOWS',
                    'threatType': 'MALWARE',
                },
            }

            # pylint: disable=protected-access
            actual_result = analyzer._do_safebrowsing_lookup(
                ['http://A', 'https://B'],
                [],
                [],
            )

            self.assertEqual(
                OrderedDict(
                    sorted(
                        EXPECTED_RESULT.items(),
                    ),
                ),
                OrderedDict(
                    sorted(
                        actual_result.items(),
                    ),
                ),
            )