def test_info_set_keep_uniq_id(self):
        #
        # Create a new InfoSet, load it from the KB, confirm that it has
        # the same uniq_id
        #
        vuln = MockVuln(name='Foos')

        info_set_a, created = kb.append_uniq_group('a', 'b', vuln,
                                                   group_klass=MockInfoSetNames)

        self.assertTrue(created)

        info_set_b = kb.get('a', 'b')[0]

        self.assertEqual(info_set_a.get_uniq_id(),
                         info_set_b.get_uniq_id())

        #
        # Change the InfoSet a little bit by adding a new Info. That should
        # change the uniq_id
        #
        vuln = MockVuln(name='Foos')
        _, created = kb.append_uniq_group('a', 'b', vuln,
                                          group_klass=MockInfoSetNames)

        self.assertFalse(created)

        info_set_b = kb.get('a', 'b')[0]

        self.assertNotEqual(info_set_a.get_uniq_id(),
                            info_set_b.get_uniq_id())
Exemple #2
0
    def test_info_set_keep_uniq_id(self):
        #
        # Create a new InfoSet, load it from the KB, confirm that it has
        # the same uniq_id
        #
        vuln = MockVuln(name='Foos')

        info_set_a, created = kb.append_uniq_group(
            'a', 'b', vuln, group_klass=MockInfoSetNames)

        self.assertTrue(created)

        info_set_b = kb.get('a', 'b')[0]

        self.assertEqual(info_set_a.get_uniq_id(), info_set_b.get_uniq_id())

        #
        # Change the InfoSet a little bit by adding a new Info. That should
        # change the uniq_id
        #
        vuln = MockVuln(name='Foos')
        _, created = kb.append_uniq_group('a',
                                          'b',
                                          vuln,
                                          group_klass=MockInfoSetNames)

        self.assertFalse(created)

        info_set_b = kb.get('a', 'b')[0]

        self.assertNotEqual(info_set_a.get_uniq_id(), info_set_b.get_uniq_id())
    def test_append_uniq_group_match_filter_func(self):
        vuln = MockVuln()
        kb.append_uniq_group('a', 'b', vuln, group_klass=MockInfoSetTrue)
        info_set, created = kb.append_uniq_group('a', 'b', vuln,
                                                 group_klass=MockInfoSetTrue)

        self.assertFalse(created)
        self.assertIsInstance(info_set, InfoSet)
        self.assertEqual(len(info_set.infos), 2)
Exemple #4
0
    def test_append_uniq_group_match_filter_func(self):
        vuln = MockVuln()
        kb.append_uniq_group('a', 'b', vuln, group_klass=MockInfoSetTrue)
        info_set, created = kb.append_uniq_group('a', 'b', vuln,
                                                 group_klass=MockInfoSetTrue)

        self.assertFalse(created)
        self.assertIsInstance(info_set, InfoSet)
        self.assertEqual(len(info_set.infos), 2)
        def multi_append():
            for i in xrange(InfoSet.MAX_INFO_INSTANCES * 2):
                vuln = MockVuln()
                kb.append_uniq_group('a', 'b', vuln, group_klass=MockInfoSetTrue)

            info_set_list = kb.get('a', 'b')

            self.assertEqual(len(info_set_list), 1)

            info_set = info_set_list[0]
            self.assertEqual(len(info_set.infos), InfoSet.MAX_INFO_INSTANCES)
            return True
        def multi_append():
            for i in xrange(InfoSet.MAX_INFO_INSTANCES * 2):
                vuln = MockVuln()
                kb.append_uniq_group('a', 'b', vuln, group_klass=MockInfoSetTrue)

            info_set_list = kb.get('a', 'b')

            self.assertEqual(len(info_set_list), 1)

            info_set = info_set_list[0]
            self.assertEqual(len(info_set.infos), InfoSet.MAX_INFO_INSTANCES)
            return True
    def test_append_uniq_group_no_match_filter_func(self):
        vuln1 = MockVuln(name='Foos')
        vuln2 = MockVuln(name='Bars')
        kb.append_uniq_group('a', 'b', vuln1, group_klass=MockInfoSetFalse)
        info_set, created = kb.append_uniq_group('a', 'b', vuln2,
                                                 group_klass=MockInfoSetFalse)

        self.assertIsInstance(info_set, InfoSet)
        self.assertTrue(created)
        self.assertEqual(len(info_set.infos), 1)

        raw_data = kb.get('a', 'b')
        self.assertEqual(len(raw_data), 2)
        self.assertIsInstance(raw_data[0], InfoSet)
        self.assertIsInstance(raw_data[1], InfoSet)

        self.assertEqual(raw_data[0].first_info.get_name(), 'Foos')
        self.assertEqual(raw_data[1].first_info.get_name(), 'Bars')
Exemple #8
0
    def test_append_uniq_group_no_match_filter_func(self):
        vuln1 = MockVuln(name='Foos')
        vuln2 = MockVuln(name='Bars')
        kb.append_uniq_group('a', 'b', vuln1, group_klass=MockInfoSetFalse)
        info_set, created = kb.append_uniq_group('a', 'b', vuln2,
                                                 group_klass=MockInfoSetFalse)

        self.assertIsInstance(info_set, InfoSet)
        self.assertTrue(created)
        self.assertEqual(len(info_set.infos), 1)

        raw_data = kb.get('a', 'b')
        self.assertEqual(len(raw_data), 2)
        self.assertIsInstance(raw_data[0], InfoSet)
        self.assertIsInstance(raw_data[1], InfoSet)

        self.assertEqual(raw_data[0].first_info.get_name(), 'Foos')
        self.assertEqual(raw_data[1].first_info.get_name(), 'Bars')
    def test_append_uniq_group_empty_address(self):
        vuln = MockVuln()
        info_set, created = kb.append_uniq_group('a', 'b', vuln)

        self.assertIsInstance(info_set, InfoSet)
        self.assertTrue(created)
        self.assertEqual(info_set.get_urls(), [vuln.get_url()])
        self.assertEqual(info_set.get_name(), vuln.get_name())
        self.assertEqual(info_set.get_id(), vuln.get_id())
        self.assertEqual(info_set.get_plugin_name(), vuln.get_plugin_name())
    def test_info_set_keep_uniq_id_after_max_info_instances(self):
        #
        # Create one InfoSet, add MAX_INFO_INSTANCES, assert that the ID is not
        # changed afterwards
        #
        vuln = MockVuln(name='Foos')

        for _ in xrange(MockInfoSetNames.MAX_INFO_INSTANCES + 1):
            kb.append_uniq_group('a', 'b', vuln, group_klass=MockInfoSetNames)

        info_set_before = kb.get('a', 'b')[0]

        # Now some rounds of testing
        for _ in xrange(5):
            info_set_after, _ = kb.append_uniq_group('a', 'b', vuln,
                                                     group_klass=MockInfoSetNames)

            self.assertEqual(info_set_before.get_uniq_id(),
                             info_set_after.get_uniq_id())
Exemple #11
0
    def test_append_uniq_group_empty_address(self):
        vuln = MockVuln()
        info_set, created = kb.append_uniq_group('a', 'b', vuln)

        self.assertIsInstance(info_set, InfoSet)
        self.assertTrue(created)
        self.assertEqual(info_set.get_urls(), [vuln.get_url()])
        self.assertEqual(info_set.get_name(), vuln.get_name())
        self.assertEqual(info_set.get_id(), vuln.get_id())
        self.assertEqual(info_set.get_plugin_name(), vuln.get_plugin_name())
Exemple #12
0
    def test_info_set_keep_uniq_id_after_max_info_instances(self):
        #
        # Create one InfoSet, add MAX_INFO_INSTANCES, assert that the ID is not
        # changed afterwards
        #
        vuln = MockVuln(name='Foos')

        for _ in xrange(MockInfoSetNames.MAX_INFO_INSTANCES + 1):
            kb.append_uniq_group('a', 'b', vuln, group_klass=MockInfoSetNames)

        info_set_before = kb.get('a', 'b')[0]

        # Now some rounds of testing
        for _ in xrange(5):
            info_set_after, _ = kb.append_uniq_group(
                'a', 'b', vuln, group_klass=MockInfoSetNames)

            self.assertEqual(info_set_before.get_uniq_id(),
                             info_set_after.get_uniq_id())
    def test_append_uniq_group_filter_func_specific(self):
        vuln1 = MockVuln(name='Foos')
        vuln2 = MockVuln(name='Bars')
        vuln3 = MockVuln(name='Foos', _id=42)
        kb.append_uniq_group('a', 'b', vuln1, group_klass=MockInfoSetNames)
        kb.append_uniq_group('a', 'b', vuln2, group_klass=MockInfoSetNames)
        kb.append_uniq_group('a', 'b', vuln3, group_klass=MockInfoSetNames)

        raw_data = kb.get('a', 'b')
        self.assertEqual(len(raw_data), 2)
        self.assertIsInstance(raw_data[0], InfoSet)
        self.assertIsInstance(raw_data[1], InfoSet)

        self.assertEqual(raw_data[0].get_name(), 'Foos')
        self.assertEqual(len(raw_data[0].infos), 2)
        self.assertEqual(raw_data[0].infos[1].get_id(), [42])
        self.assertEqual(raw_data[1].first_info.get_name(), 'Bars')
Exemple #14
0
    def test_append_uniq_group_filter_func_specific(self):
        vuln1 = MockVuln(name='Foos')
        vuln2 = MockVuln(name='Bars')
        vuln3 = MockVuln(name='Foos', _id=42)
        kb.append_uniq_group('a', 'b', vuln1, group_klass=MockInfoSetNames)
        kb.append_uniq_group('a', 'b', vuln2, group_klass=MockInfoSetNames)
        kb.append_uniq_group('a', 'b', vuln3, group_klass=MockInfoSetNames)

        raw_data = kb.get('a', 'b')
        self.assertEqual(len(raw_data), 2)
        self.assertIsInstance(raw_data[0], InfoSet)
        self.assertIsInstance(raw_data[1], InfoSet)

        self.assertEqual(raw_data[0].get_name(), 'Foos')
        self.assertEqual(len(raw_data[0].infos), 2)
        self.assertEqual(raw_data[0].infos[1].get_id(), [42])
        self.assertEqual(raw_data[1].first_info.get_name(), 'Bars')
Exemple #15
0
    def test_append_uniq_group_filter_func_attribute_match(self):
        vuln1 = MockVuln(name='Foos')
        vuln1['tag'] = 'foo'

        vuln2 = MockVuln(name='Bars')
        vuln2['tag'] = 'bar'

        vuln3 = MockVuln(_id=42)
        vuln3['tag'] = 'foo'

        kb.append_uniq_group('a', 'b', vuln1, group_klass=MockInfoSetITag)
        kb.append_uniq_group('a', 'b', vuln2, group_klass=MockInfoSetITag)
        kb.append_uniq_group('a', 'b', vuln3, group_klass=MockInfoSetITag)

        raw_data = kb.get('a', 'b')
        self.assertEqual(len(raw_data), 2)
        self.assertIsInstance(raw_data[0], InfoSet)
        self.assertIsInstance(raw_data[1], InfoSet)

        self.assertEqual(raw_data[0].get_name(), 'Foos')
        self.assertEqual(len(raw_data[0].infos), 2)
        self.assertEqual(raw_data[0].infos[1].get_id(), [42])
        self.assertEqual(raw_data[1].first_info.get_name(), 'Bars')