示例#1
0
文件: requests.py 项目: zsdlove/w3af
    def get_data_container(self, headers):
        """
        Query the spec / operation and return the data container which
        will be used to perform the fuzzing operation.

        This method translates the operation parameters into a data container
        which can be sent in HTTP request body. Also updates the headers
        in order to include the proper Content-Type.

        :param headers: The open API specified headers
        :return: A string which can be sent in HTTP request body
        """
        content_type = headers.get('Content-Type')
        parameters = self._get_filled_parameters()

        # We only send in the body the parameters that belong there
        for param_name, param_def in self.operation.params.iteritems():
            if param_def.location != 'body':
                parameters.pop(param_name)

        # If there are no parameters, we don't create an empty data container,
        # we just send an empty string in the HTTP request body
        if not parameters:
            return None

        # Create the data container
        dc = dc_from_content_type_and_raw_params(content_type, parameters)
        if dc is None:
            om.out.error("No data container for content type '%s'" %
                         content_type)
            return None

        dc.set_header('Content-Type', content_type)

        return dc
示例#2
0
    def test_urlencoded_form(self):
        params = {'hello': 'world', 'bye': 'bye'}
        dc = dc_from_content_type_and_raw_params('application/x-www-form-urlencoded', params)

        self.assertIsInstance(dc, URLEncodedForm)
        self.assertEqual(dc['hello'], ['world'])
        self.assertEqual(dc['bye'], ['bye'])
示例#3
0
    def test_multipart_with_files(self):
        params = {'hello': 'world', 'file': smart_fill_file('image', 'cat.png')}
        dc = dc_from_content_type_and_raw_params('multipart/form-data', params)

        self.assertIsInstance(dc, MultipartContainer)
        self.assertEqual(dc['hello'], ['world'])
        self.assertIn('file', dc.get_file_vars())
示例#4
0
    def test_multipart_no_files(self):
        params = {'hello': 'world', 'bye': 'bye'}
        dc = dc_from_content_type_and_raw_params('multipart/form-data', params)

        self.assertIsInstance(dc, MultipartContainer)
        self.assertEqual(dc['hello'], ['world'])
        self.assertEqual(dc['bye'], ['bye'])
示例#5
0
    def get_data_container(self, headers):
        """
        Query the spec / operation and return the data container which
        will be used to perform the fuzzing operation.

        This method translates the operation parameters into a data container
        which can be sent in HTTP request body. Also updates the headers
        in order to include the proper Content-Type.

        :param headers: The open API specified headers
        :return: A string which can be sent in HTTP request body
        """
        content_type = headers.get('Content-Type')
        parameters = self._get_filled_parameters()

        # We only send in the body the parameters that belong there
        for param_name, param_def in self.operation.params.iteritems():
            if param_def.location != 'body':
                parameters.pop(param_name)

        # If there are no parameters, we don't create an empty data container,
        # we just send an empty string in the HTTP request body
        if not parameters:
            return None

        # Create the data container
        dc = dc_from_content_type_and_raw_params(content_type, parameters)
        if dc is None:
            om.out.error("No data container for content type '%s'" % content_type)
            return None

        dc.set_header('Content-Type', content_type)

        return dc
示例#6
0
    def test_json_simple(self):
        params = {'hello': 'world', 'bye': 0}
        dc = dc_from_content_type_and_raw_params('application/json', params)

        self.assertIsInstance(dc, JSONContainer)
        self.assertEqual(str(dc), json.dumps(params))