def url_matches(self, request_uri): """ :param request_uri: The http request URI sent by the plugin :return: True if the request_uri matches this mock_response """ if isinstance(self.url, basestring): request_uri = URL(request_uri) response_uri = URL(self.url) request_path = request_uri.get_path_qs() request_domain = request_uri.get_domain() response_path = response_uri.get_path_qs() response_domain = response_uri.get_domain() if response_domain != request_domain: return False if request_path != response_path: return False return True elif isinstance(self.url, RE_COMPILE_TYPE): if self.url.match(request_uri): return True return False
def test_get_path_qs_string(self): u = URL('https://domain/konto/insättning?amount=1&method=abc') self.assertEqual(smart_str(u.get_path_qs()), '/konto/insättning?amount=1&method=abc') u = URL('https://domain/konto/insättning;x=1?amount=1&method=abc') self.assertEqual(smart_str(u.get_path_qs()), '/konto/insättning;x=1?amount=1&method=abc') u = URL('https://domain/konto/insättning;insättning=1?amount=1&method=abc') self.assertEqual(smart_str(u.get_path_qs()), '/konto/insättning;insättning=1?amount=1&method=abc')
def test_get_path_qs_unicode(self): u = URL(u'https://domain/konto/insättning?amount=1&method=abc') self.assertEqual(u.get_path_qs(), u'/konto/insättning?amount=1&method=abc') u = URL(u'https://domain/konto/insättning;x=1?amount=1&method=abc') self.assertEqual(u.get_path_qs(), u'/konto/insättning;x=1?amount=1&method=abc') u = URL(u'https://domain/konto/insättning;insättning=1?amount=1&method=abc') self.assertEqual(u.get_path_qs(), u'/konto/insättning;insättning=1?amount=1&method=abc')
def test_get_path_qs(self): u = URL(u'https://w3af.com:443/xyz/123/456/789/') self.assertEqual(u.get_path(), u'/xyz/123/456/789/') u = URL(u'https://w3af.com:443/xyz/123/456/789/') self.assertEqual(u.get_path_qs(), u'/xyz/123/456/789/') u = URL(u'https://w3af.com:443/xyz/file.asp') self.assertEqual(u.get_path_qs(), u'/xyz/file.asp') u = URL(u'https://w3af.com:443/xyz/file.asp?id=1') self.assertEqual(u.get_path_qs(), u'/xyz/file.asp?id=1')
def test_set_params(self): u = URL('http://w3af.com/;id=1') u.set_param('file=2') self.assertEqual(u.get_params_string(), 'file=2') u = URL('http://w3af.com/xyz.txt;id=1?file=2') u.set_param('file=3') self.assertEqual(u.get_params_string(), 'file=3') self.assertEqual(u.get_path_qs(), '/xyz.txt;file=3?file=2')