def test_unknown_default_form_no_urlencoded(self): headers = self.get_headers('foo/bar') dc = dc_from_hdrs_post(headers, 'a') self.assertIsInstance(dc, PlainContainer) self.assertEqual(headers.items(), dc.get_headers()) self.assertEqual(str(dc), 'a')
def test_unknown_default_form_no_urlencoded(self): headers = self.get_headers('foo/bar') dc = dc_from_hdrs_post(headers, 'a') self.assertIsInstance(dc, PlainContainer) self.assertEqual(headers.items(), dc.get_headers()) self.assertEqual(str(dc), 'a')
def _get_all_parameters(self, request): """ :param request: The HTTP request :yield: All the HTTP request parameters as tuples of (name, value) """ headers = request.get_headers() query_string = request.get_uri().get_querystring() dc = dc_from_hdrs_post(headers, request.get_data()) cookie_str, _ = headers.iget('cookie', '') cookie_dc = Cookie(cookie_str) token_generators = itertools.chain(query_string.iter_tokens(), dc.iter_tokens(), headers.iter_tokens(), cookie_dc.iter_tokens()) for token in token_generators: token_name = token.get_name() token_value = token.get_value() token_value = smart_str_ignore(token_value) yield token_name, token_value # Handle the case where the parameter is base64 encoded is_b64, decoded_data = maybe_decode_base64(token_value) if is_b64: yield token_name, decoded_data
def test_form(self): headers = self.get_headers('application/x-www-form-urlencoded') dc = dc_from_hdrs_post(headers, 'a=3&b=2') self.assertIsInstance(dc, URLEncodedForm) self.assertIn('a', dc) self.assertIn('b', dc) self.assertEqual('a=3&b=2', str(dc))
def test_xmlrpc(self): headers = self.get_headers('text/xml') dc = dc_from_hdrs_post(headers, XML_WITH_FUZZABLE) self.assertIsInstance(dc, XmlRpcContainer) self.assertIn('string', dc) self.assertIn('base64', dc) self.assertEqual(XML_WITH_FUZZABLE, str(dc))
def test_form(self): headers = self.get_headers('application/x-www-form-urlencoded') dc = dc_from_hdrs_post(headers, 'a=3&b=2') self.assertIsInstance(dc, URLEncodedForm) self.assertIn('a', dc) self.assertIn('b', dc) self.assertEqual('a=3&b=2', str(dc))
def test_xmlrpc(self): headers = self.get_headers('text/xml') dc = dc_from_hdrs_post(headers, XML_WITH_FUZZABLE) self.assertIsInstance(dc, XmlRpcContainer) self.assertIn('string', dc) self.assertIn('base64', dc) self.assertEqual(XML_WITH_FUZZABLE, str(dc))
def test_json(self): headers = self.get_headers('application/json') dc = dc_from_hdrs_post(headers, COMPLEX_OBJECT) EXPECTED_PARAMS = [u'object-second_key-list-0-string', u'object-key-string'] self.assertIsInstance(dc, JSONContainer) self.assertEqual(dc.get_param_names(), EXPECTED_PARAMS) self.assertEqual(json.loads(COMPLEX_OBJECT), json.loads(str(dc)))
def test_json(self): headers = self.get_headers('application/json') dc = dc_from_hdrs_post(headers, COMPLEX_OBJECT) EXPECTED_PARAMS = [u'object-second_key-list-0-string', u'object-key-string'] self.assertIsInstance(dc, JSONContainer) self.assertEqual(dc.get_param_names(), EXPECTED_PARAMS) self.assertEqual(json.loads(COMPLEX_OBJECT), json.loads(str(dc)))
def test_multipart(self): boundary, post_data = multipart_encode([('ax', 'bcd'), ], []) multipart_boundary = 'multipart/form-data; boundary=%s' headers = Headers([('content-length', str(len(post_data))), ('content-type', multipart_boundary % boundary)]) dc = dc_from_hdrs_post(headers, post_data) EXPECTED_PARAMS = [u'ax'] self.assertIsInstance(dc, MultipartContainer) self.assertEqual(dc.get_param_names(), EXPECTED_PARAMS)
def test_multipart(self): boundary, post_data = multipart_encode([('ax', 'bcd'), ], []) multipart_boundary = 'multipart/form-data; boundary=%s' headers = Headers([('content-length', str(len(post_data))), ('content-type', multipart_boundary % boundary)]) dc = dc_from_hdrs_post(headers, post_data) EXPECTED_PARAMS = [u'ax'] self.assertIsInstance(dc, MultipartContainer) self.assertEqual(dc.get_param_names(), EXPECTED_PARAMS)
def from_parts(cls, url, method='GET', post_data=None, headers=None): """ :return: An instance of FuzzableRequest from the provided parameters. """ if isinstance(url, basestring): url = URL(url) if post_data == '': post_data = None elif isinstance(post_data, basestring): post_data = dc_from_hdrs_post(headers, post_data) return cls(url, method=method, headers=headers, post_data=post_data)
def from_parts(cls, url, method='GET', post_data=None, headers=None): """ :return: An instance of FuzzableRequest from the provided parameters. """ if isinstance(url, basestring): url = URL(url) if post_data == '': post_data = None elif isinstance(post_data, basestring): post_data = dc_from_hdrs_post(headers, post_data) return cls(url, method=method, headers=headers, post_data=post_data)
def add_req(): url = request.json["url"] method = request.json["method"] post_data = request.json["post_data"] headers = request.json["headers"] cookie_string = request.json['cookie'] headers = Headers(headers.items()) freq = FuzzableRequest(URL(url), method, headers, Cookie(cookie_string), dc_from_hdrs_post(headers, post_data)) urllist.req_queue.put_nowait(freq) print("req size %d" % urllist.req_queue.qsize()) return jsonify({"status": True})