示例#1
0
    def test_verify_url(self):
        ctarget = w3af_core_target()

        self.assertRaises(w3afException, ctarget._verify_url,
                          URL_KLASS('ftp://www.google.com/'))

        self.assertTrue(
            ctarget._verify_url(URL_KLASS('http://www.google.com/')))
        self.assertTrue(
            ctarget._verify_url(URL_KLASS('http://www.google.com:39/')))
示例#2
0
    def test_verify_file_target(self):
        ctarget = w3af_core_target()

        target_file = '/tmp/moth.target'
        target = 'file://%s' % target_file

        target_file_handler = file(target_file, 'w')
        target_file_handler.write('http://moth/1\n')
        target_file_handler.write('http://moth/2\n')
        target_file_handler.close()

        options = ctarget.get_options()
        options['target'].set_value(target)
        ctarget.set_options(options)

        moth1 = URL_KLASS('http://moth/1')
        moth2 = URL_KLASS('http://moth/2')

        self.assertIn(moth1, cf.cf.get('targets'))
        self.assertIn(moth2, cf.cf.get('targets'))
示例#3
0
    def test_factory_ok(self):
        input_file = os.path.join('core', 'data', 'options', 'tests',
                                  'test.txt')
        output_file = input_file

        data = {
            BOOL: ('true', True),
            INT: ('1', 1),
            FLOAT: ('1.0', 1.0),
            STRING: ('hello world', 'hello world'),
            URL: ('http://moth/', URL_KLASS('http://moth/')),
            URL_LIST:
            ('http://moth/1 , http://moth/2',
             [URL_KLASS('http://moth/1'),
              URL_KLASS('http://moth/2')]),
            IPPORT: ('127.0.0.1:8080', '127.0.0.1:8080'),
            LIST: ('a,b,c', ['a', 'b', 'c']),
            REGEX: ('.*', '.*'),
            COMBO: (['a', 'b', 'c'], 'a'),
            INPUT_FILE: (input_file, input_file),
            OUTPUT_FILE: (output_file, output_file),
            PORT: ('12345', 12345),
            IP: ('127.0.0.1', '127.0.0.1')
        }

        for _type, (user_value, parsed_value) in data.iteritems():
            opt = opt_factory('name', user_value, 'desc', _type, 'help',
                              'tab1')

            self.assertEqual(opt.get_name(), 'name')
            self.assertEqual(opt.get_desc(), 'desc')
            self.assertEqual(opt.get_type(), _type)
            self.assertEqual(opt.get_default_value(), parsed_value)
            self.assertEqual(opt.get_value(), parsed_value)
            self.assertEqual(opt.get_help(), 'help')
            self.assertEqual(opt.get_tabid(), 'tab1')

            self.assertIsInstance(opt.get_name(), basestring)
            self.assertIsInstance(opt.get_desc(), basestring)
            self.assertIsInstance(opt.get_type(), basestring)
            self.assertIsInstance(opt.get_help(), basestring)
示例#4
0
    def test_factory_already_converted_type(self):
        data = {BOOL: (True, True),
                INT: (1, 1),
                FLOAT: (1.0, 1.0),
                STRING: ('hello world', 'hello world'),
                URL: (URL_KLASS('http://moth/'), URL_KLASS('http://moth/')),
                URL_LIST: ([URL_KLASS('http://moth/1'),
                            URL_KLASS('http://moth/2')],
                           [URL_KLASS('http://moth/1'),
                            URL_KLASS('http://moth/2')]),
                LIST: (['a', 'b', 'c'], ['a', 'b', 'c']),
                PORT: (12345, 12345)
                }

        for _type, (user_value, parsed_value) in data.iteritems():
            opt = opt_factory('name', user_value, 'desc', _type)

            self.assertEqual(opt.get_name(), 'name')
            self.assertEqual(opt.get_desc(), 'desc')
            self.assertEqual(opt.get_type(), _type)
            self.assertEqual(opt.get_default_value(), parsed_value)
            self.assertEqual(opt.get_value(), parsed_value)

            self.assertIsInstance(opt.get_name(), basestring)
            self.assertIsInstance(opt.get_desc(), basestring)
            self.assertIsInstance(opt.get_type(), basestring)
            self.assertIsInstance(opt.get_help(), basestring)