def test_no_cache(self):
        url = URL("http://www.w3af.org")
        request = HTTPRequest(url, cache=False)

        cache = CacheHandler()
        self.assertEqual(cache.default_open(request), None)

        response = FakeHttplibHTTPResponse(200, "OK", "spameggs", Headers(), url.url_string)
        cache.http_response(request, response)
        self.assertEqual(cache.default_open(request), None)
    def test_basic(self):
        url = URL("http://www.w3af.org")
        request = HTTPRequest(url, cache=True)

        cache = CacheHandler()
        self.assertEqual(cache.default_open(request), None)

        response = FakeHttplibHTTPResponse(200, "OK", "spameggs", Headers(), url.url_string)
        cache.http_response(request, response)

        cached_response = cache.default_open(request)

        self.assertIsInstance(cached_response, SQLCachedResponse)

        self.assertEqual(cached_response.code, response.code)
        self.assertEqual(cached_response.msg, response.msg)
        self.assertEqual(cached_response.read(), response.read())
        self.assertEqual(Headers(cached_response.info().items()), response.info())
        self.assertEqual(cached_response.geturl(), response.geturl())
Пример #3
0
    def test_basic(self):
        url = URL('http://www.w3af.org')
        request = HTTPRequest(url, cache=True)
        
        cache = CacheHandler()
        self.assertEqual(cache.default_open(request), None)
        
        response = FakeHttplibHTTPResponse(200, 'OK', 'spameggs', Headers(),
                                           url.url_string)

        with patch('w3af.core.data.url.handlers.cache.CacheClass') as cc_mock:
            store_in_cache = Mock()
            cc_mock.attach_mock(store_in_cache, 'store_in_cache')

            # This stores the response
            cache.http_response(request, response)

            # Make sure the right call was made
            _call = _Call(('store_in_cache', (request, response)))
            self.assertEqual(cc_mock.mock_calls, [_call])
            cc_mock.reset_mock()

            exists_in_cache = Mock()
            cc_mock.return_value = response
            cc_mock.attach_mock(exists_in_cache, 'exists_in_cache')

            # This retrieves the response from the "cache"
            cached_response = cache.default_open(request)

            # Make sure the right call was made
            _exists_call = _Call(('exists_in_cache', (request,)))
            _retrieve_call = _Call(((request,), {}))
            self.assertEqual(cc_mock.mock_calls, [_exists_call, _retrieve_call])

        self.assertIsNotNone(cached_response)
        
        self.assertEqual(cached_response.code, response.code)
        self.assertEqual(cached_response.msg, response.msg)
        self.assertEqual(cached_response.read(), response.read())
        self.assertEqual(Headers(cached_response.info().items()), response.info())
        self.assertEqual(cached_response.geturl(), response.geturl())
Пример #4
0
    def test_no_cache(self):
        url = URL('http://www.w3af.org')
        request = HTTPRequest(url, cache=False)

        cache = CacheHandler()
        self.assertEqual(cache.default_open(request), None)

        response = FakeHttplibHTTPResponse(200, 'OK', 'spameggs', Headers(),
                                           url.url_string)
        cache.http_response(request, response)
        self.assertEqual(cache.default_open(request), None)
Пример #5
0
    def test_basic(self):
        url = URL('http://www.w3af.org')
        request = HTTPRequest(url, cache=True)

        cache = CacheHandler()
        self.assertEqual(cache.default_open(request), None)

        response = FakeHttplibHTTPResponse(200, 'OK', 'spameggs', Headers(),
                                           url.url_string)

        with patch('w3af.core.data.url.handlers.cache.CacheClass') as cc_mock:
            store_in_cache = Mock()
            cc_mock.attach_mock(store_in_cache, 'store_in_cache')

            # This stores the response
            cache.http_response(request, response)

            # Make sure the right call was made
            _call = _Call(('store_in_cache', (request, response)))
            self.assertEqual(cc_mock.mock_calls, [_call])
            cc_mock.reset_mock()

            exists_in_cache = Mock()
            cc_mock.return_value = response
            cc_mock.attach_mock(exists_in_cache, 'exists_in_cache')

            # This retrieves the response from the "cache"
            cached_response = cache.default_open(request)

            # Make sure the right call was made
            _exists_call = _Call(('exists_in_cache', (request, )))
            _retrieve_call = _Call(((request, ), {}))
            self.assertEqual(cc_mock.mock_calls,
                             [_exists_call, _retrieve_call])

        self.assertIsNotNone(cached_response)

        self.assertEqual(cached_response.code, response.code)
        self.assertEqual(cached_response.msg, response.msg)
        self.assertEqual(cached_response.read(), response.read())
        self.assertEqual(Headers(cached_response.info().items()),
                         response.info())
        self.assertEqual(cached_response.geturl(), response.geturl())
Пример #6
0
    def test_basic(self):
        url = URL('http://www.w3af.org')
        request = HTTPRequest(url, cache=True)

        cache = CacheHandler()
        self.assertEqual(cache.default_open(request), None)

        response = FakeHttplibHTTPResponse(200, 'OK', 'spameggs', Headers(),
                                           url.url_string)
        cache.http_response(request, response)

        cached_response = cache.default_open(request)

        self.assertIsInstance(cached_response, SQLCachedResponse)

        self.assertEqual(cached_response.code, response.code)
        self.assertEqual(cached_response.msg, response.msg)
        self.assertEqual(cached_response.read(), response.read())
        self.assertEqual(Headers(cached_response.info().items()),
                         response.info())
        self.assertEqual(cached_response.geturl(), response.geturl())
Пример #7
0
 def tearDown(self):
     CacheHandler().clear()