Exemplo n.º 1
0
 def test_basic(self):
     dc = PlainContainer('abc', 'text/plain')
     
     self.assertEqual('abc', str(dc))
     self.assertNotIn('abc', dc)
     self.assertEqual(dc.content_type_header_value, 'text/plain')
     self.assertEqual(dc.get_headers(), [('content-type', 'text/plain')])
Exemplo n.º 2
0
    def test_basic(self):
        dc = PlainContainer('abc', 'text/plain')

        self.assertEqual('abc', str(dc))
        self.assertNotIn('abc', dc)
        self.assertEqual(dc.content_type_header_value, 'text/plain')
        self.assertEqual(dc.get_headers(), [('content-type', 'text/plain')])
Exemplo n.º 3
0
def dc_from_hdrs_post(headers, post_data):
    """
    :param headers: HTTP request headers, most importantly containing the
                    content-type info.
    :param post_data: The HTTP request post-data as a string
    :return: The best-match from POST_DATA_CONTAINERS to hold the information
             in self._post_data @ FuzzableRequest
    """
    if headers is None:
        headers = Headers()

    for pdc_klass in POST_DATA_CONTAINERS:
        try:
            return pdc_klass.from_postdata(headers, post_data)
        except (ValueError, TypeError) as e:
            pass
    else:
        content_type, _ = headers.iget('content-type', 'None')
        msg = 'Unknown post-data. Content-type: "%s" and/or post-data "%s"'
        om.out.debug(msg % (content_type, post_data[:50]))

        # These lines are for debugging
        # import traceback
        # traceback.print_stack()

        return PlainContainer.from_postdata(headers, post_data)
Exemplo n.º 4
0
Arquivo: factory.py Projeto: EnDe/w3af
def dc_from_hdrs_post(headers, post_data):
    """
    :param headers: HTTP request headers, most importantly containing the
                    content-type info.
    :param post_data: The HTTP request post-data as a string
    :return: The best-match from POST_DATA_CONTAINERS to hold the information
             in self._post_data @ FuzzableRequest
    """
    if headers is None:
        headers = Headers()

    for pdc_klass in POST_DATA_CONTAINERS:
        try:
            return pdc_klass.from_postdata(headers, post_data)
        except (ValueError, TypeError) as e:
            pass
    else:
        content_type, _ = headers.iget("content-type", "None")
        msg = 'Unknown post-data. Content-type: "%s" and/or post-data "%s"'
        om.out.debug(msg % (content_type, post_data[:50]))

        # These lines are for debugging
        # import traceback
        # traceback.print_stack()

        return PlainContainer.from_postdata(headers, post_data)
Exemplo n.º 5
0
    def test_get_headers_none(self):
        dc = PlainContainer('abc')

        self.assertEqual(dc.get_headers(), [])
Exemplo n.º 6
0
    def test_is_variant_diff_headers(self):
        dc1 = PlainContainer('abc', 'text/plain')
        dc2 = PlainContainer('abc', 'text/xml')

        self.assertFalse(dc1.is_variant_of(dc2))
Exemplo n.º 7
0
    def test_is_variant_all_equal(self):
        dc1 = PlainContainer('abc', 'text/plain')
        dc2 = PlainContainer('abc', 'text/plain')

        self.assertTrue(dc1.is_variant_of(dc2))
Exemplo n.º 8
0
    def test_iter_setters(self):
        dc = PlainContainer('abc', 'text/plain')
        tokens = [t for t in dc.iter_setters()]

        self.assertEqual(tokens, [])
Exemplo n.º 9
0
    def test_get_headers_none(self):
        dc = PlainContainer('abc')

        self.assertEqual(dc.get_headers(), [])
Exemplo n.º 10
0
    def test_is_variant_diff_headers(self):
        dc1 = PlainContainer('abc', 'text/plain')
        dc2 = PlainContainer('abc', 'text/xml')

        self.assertFalse(dc1.is_variant_of(dc2))
Exemplo n.º 11
0
    def test_is_variant_all_equal(self):
        dc1 = PlainContainer('abc', 'text/plain')
        dc2 = PlainContainer('abc', 'text/plain')

        self.assertTrue(dc1.is_variant_of(dc2))
Exemplo n.º 12
0
 def test_set_token(self):
     dc = PlainContainer('abc', 'text/plain')
     # Content is not a token
     self.assertRaises(RuntimeError, dc.set_token, 'abc')
Exemplo n.º 13
0
    def test_iter_setters(self):
        dc = PlainContainer('abc', 'text/plain')
        tokens = [t for t in dc.iter_setters()]

        self.assertEqual(tokens, [])