示例#1
0
    def test_return_all_for_plugin(self):
        i1 = MockInfo()
        i2 = MockInfo()
        i3 = MockInfo()

        kb.append('a', 'b', i1)
        kb.append('a', 'b', i2)
        kb.append('a', 'b', i3)

        self.assertEqual(kb.get('a', 'b'), [i1, i2, i3])
示例#2
0
    def test_append(self):
        i1 = MockInfo()
        i2 = MockInfo()
        i3 = MockInfo()

        kb.append('a', 'b', i1)
        kb.append('a', 'b', i1)
        kb.append('a', 'b', i1)
        kb.append('a', 'b', i2)
        kb.append('a', 'b', i3)

        self.assertEqual(kb.get('a', 'b'), [i1, i1, i1, i2, i3])
示例#3
0
    def test_append_uniq_var_bug_10Dec2012(self):
        i1 = MockInfo()
        i1.set_uri(URL('http://moth/abc.html'))
        i1.set_var('id')

        i2 = MockInfo()
        i2.set_uri(URL('http://moth/abc.html'))
        i2.set_var('id')

        kb.append_uniq('a', 'b', i1)
        kb.append_uniq('a', 'b', i2)
        self.assertEqual(kb.get('a', 'b'), [i1, ])
示例#4
0
    def test_save_append(self):
        '''
        Although calling raw_write and then append is highly discouraged,
        someone would want to use it.
        '''
        i0 = MockInfo()
        self.assertRaises(TypeError, kb.raw_write, 'a', 'b', i0)

        i1 = MockInfo()
        i2 = MockInfo()
        kb.append('a', 'b', i1)
        kb.append('a', 'b', i2)

        self.assertEqual(kb.get('a', 'b'), [i1, i2])
示例#5
0
    def test_get_by_uniq_id_duplicated_ignores_second(self):
        '''
        TODO: Analyze this case, i1 and i2 have both the same ID because they
              have all the same information (this is very very uncommon in a
              real w3af run).
              
              Note that in the get_by_uniq_id call i2 is not returned.
        '''
        i1 = MockInfo()
        i2 = MockInfo()
        kb.append('a', 'b', i1)
        kb.append('a', 'b', i2)

        i1_copy = kb.get_by_uniq_id(i1.get_uniq_id())
        self.assertEqual(i1_copy, i1)
示例#6
0
 def test_get_by_uniq_id_duplicated_ignores_second(self):
     '''
     TODO: Analyze this case, i1 and i2 have both the same ID because they
           have all the same information (this is very very uncommon in a
           real w3af run).
           
           Note that in the get_by_uniq_id call i2 is not returned.
     '''
     i1 = MockInfo()
     i2 = MockInfo()
     kb.append('a', 'b', i1)
     kb.append('a', 'b', i2)
     
     i1_copy = kb.get_by_uniq_id(i1.get_uniq_id())
     self.assertEqual(i1_copy, i1)
示例#7
0
    def test_append_save(self):
        i1 = MockInfo()

        kb.append('a', 'b', i1)
        kb.raw_write('a', 'b', 3)

        self.assertEqual(kb.raw_read('a', 'b'), 3)
示例#8
0
    def test_pickleable_info(self):
        original_info = MockInfo()

        kb.append('a', 'b', original_info)
        unpickled_info = kb.get('a', 'b')[0]

        self.assertEqual(original_info, unpickled_info)
示例#9
0
    def test_types_observer(self):
        observer = Mock()
        info_inst = MockInfo()

        kb.add_types_observer(Info, observer)
        kb.append('a', 'b', info_inst)
        observer.assert_called_once_with('a', 'b', info_inst)
        observer.reset_mock()

        info_inst = MockInfo()
        kb.append('a', 'c', info_inst)
        observer.assert_called_with('a', 'c', info_inst)
        observer.reset_mock()

        # Should NOT call it because it is NOT an Info instance
        some_int = 3
        kb.raw_write('a', 'd', some_int)
        self.assertEqual(observer.call_count, 0)
示例#10
0
    def test_observer_all(self):
        observer = Mock()

        kb.add_observer(None, None, observer)
        kb.raw_write('a', 'b', 1)

        observer.assert_called_once_with('a', 'b', 1)
        observer.reset_mock()

        i = MockInfo()
        kb.append('a', 'c', i)
        observer.assert_called_with('a', 'c', i)
示例#11
0
    def test_observer_location_b(self):
        observer = Mock()

        kb.add_observer('a', 'b', observer)
        kb.raw_write('a', 'b', 1)

        observer.assert_called_once_with('a', 'b', 1)
        observer.reset_mock()

        # Shouldn't call the observer
        kb.raw_write('a', 'xyz', 1)
        self.assertFalse(observer.called)

        i = MockInfo()
        kb.append('a', 'b', i)
        observer.assert_called_with('a', 'b', i)
示例#12
0
    def test_append_uniq_var_default(self):
        i1 = MockInfo()
        i1.set_uri(URL('http://moth/abc.html?id=1'))
        i1.set_dc(QueryString([('id', '1')]))
        i1.set_var('id')

        i2 = MockInfo()
        i2.set_uri(URL('http://moth/abc.html?id=3'))
        i2.set_dc(QueryString([('id', '3')]))
        i2.set_var('id')

        kb.append_uniq('a', 'b', i1)
        kb.append_uniq('a', 'b', i2)
        self.assertEqual(kb.get('a', 'b'), [
            i1,
        ])
示例#13
0
    def test_get_by_uniq_id(self):
        i1 = MockInfo()
        kb.append('a', 'b', i1)

        i1_copy = kb.get_by_uniq_id(i1.get_uniq_id())
        self.assertEqual(i1_copy, i1)
示例#14
0
    def test_append_uniq_var_default(self):
        i1 = MockInfo()
        i1.set_uri(URL('http://moth/abc.html?id=1'))
        i1.set_dc(QueryString([('id', '1')]))
        i1.set_var('id')

        i2 = MockInfo()
        i2.set_uri(URL('http://moth/abc.html?id=3'))
        i2.set_dc(QueryString([('id', '3')]))
        i2.set_var('id')

        kb.append_uniq('a', 'b', i1)
        kb.append_uniq('a', 'b', i2)
        self.assertEqual(kb.get('a', 'b'), [i1, ])
示例#15
0
 def test_raw_read_error(self):
     kb.append('a', 'b', MockInfo())
     kb.append('a', 'b', MockInfo())
     self.assertRaises(RuntimeError, kb.raw_read, 'a', 'b')
示例#16
0
    def test_append_uniq_var_bug_10Dec2012(self):
        i1 = MockInfo()
        i1.set_uri(URL('http://moth/abc.html'))
        i1.set_var('id')

        i2 = MockInfo()
        i2.set_uri(URL('http://moth/abc.html'))
        i2.set_var('id')

        kb.append_uniq('a', 'b', i1)
        kb.append_uniq('a', 'b', i2)
        self.assertEqual(kb.get('a', 'b'), [
            i1,
        ])
示例#17
0
    def test_get_by_uniq_id(self):
        i1 = MockInfo()
        kb.append('a', 'b', i1)

        i1_copy = kb.get_by_uniq_id(i1.get_uniq_id())
        self.assertEqual(i1_copy, i1)
示例#18
0
    def test_append_uniq_url_different(self):
        i1 = MockInfo()
        i1.set_uri(URL('http://moth/abc.html?id=1'))
        i1.set_dc(QueryString([('id', '1')]))
        i1.set_var('id')

        i2 = MockInfo()
        i2.set_uri(URL('http://moth/def.html?id=3'))
        i2.set_dc(QueryString([('id', '3')]))
        i2.set_var('id')

        kb.append_uniq('a', 'b', i1, filter_by='URL')
        kb.append_uniq('a', 'b', i2, filter_by='URL')
        self.assertEqual(kb.get('a', 'b'), [i1, i2])
示例#19
0
    def test_append_uniq_url_different(self):
        i1 = MockInfo()
        i1.set_uri(URL('http://moth/abc.html?id=1'))
        i1.set_dc(QueryString([('id', '1')]))
        i1.set_var('id')

        i2 = MockInfo()
        i2.set_uri(URL('http://moth/def.html?id=3'))
        i2.set_dc(QueryString([('id', '3')]))
        i2.set_var('id')

        kb.append_uniq('a', 'b', i1, filter_by='URL')
        kb.append_uniq('a', 'b', i2, filter_by='URL')
        self.assertEqual(kb.get('a', 'b'), [i1, i2])