示例#1
0
from pytest import raises
import webtest
import base64

from pywb.webapp.pywb_init import create_wb_router
from pywb.framework.wsgi_wrappers import init_app
from pywb.cdx.cdxobject import CDXObject

from urlparse import urlsplit

from server_mock import make_setup_module, BaseIntegration

setup_module = make_setup_module('tests/test_config_proxy_no_banner.yaml')

class TestProxyNoBanner(BaseIntegration):
    def get_url(self, uri, addr='127.0.0.1', server_protocol='HTTP/1.0', headers={}):
        parts = urlsplit(uri)
        env = dict(REQUEST_URI=uri, QUERY_STRING=parts.query, SCRIPT_NAME='',
                   SERVER_PROTOCOL=server_protocol, REMOTE_ADDR=addr)
        # 'Simulating' proxy by settings REQUEST_URI explicitly to full url with empty SCRIPT_NAME
        return self.testapp.get('/x-ignore-this-x', extra_environ=env, headers=headers)

    def test_proxy_chunked(self):
        resp = self.get_url('http://www.iana.org/_img/2013.1/icann-logo.svg', server_protocol='HTTP/1.1')
        assert resp.content_type == 'image/svg+xml'
        assert resp.headers['Transfer-Encoding'] == 'chunked'
        assert int(resp.headers['Content-Length']) == len(resp.body)

    def test_proxy_buffered(self):
        resp = self.get_url('http://www.iana.org/_img/2013.1/icann-logo.svg', server_protocol='HTTP/1.0')
        assert resp.content_type == 'image/svg+xml'
示例#2
0
from pytest import raises
import webtest
import base64

from pywb.webapp.pywb_init import create_wb_router
from pywb.framework.wsgi_wrappers import init_app
from pywb.cdx.cdxobject import CDXObject

from urlparse import urlsplit

from server_mock import make_setup_module, BaseIntegration

setup_module = make_setup_module('tests/test_config_proxy_ip_redis.yaml')

from fakeredis import FakeStrictRedis

import pywb.framework.cache
pywb.framework.cache.StrictRedis = FakeStrictRedis

class TestProxyIPRedisResolver(BaseIntegration):
    def _assert_basic_html(self, resp):
        assert resp.status_int == 200
        assert resp.content_type == 'text/html'
        assert resp.content_length > 0

    def _assert_basic_text(self, resp):
        assert resp.status_int == 200
        assert resp.content_type == 'text/plain'
        assert resp.content_length > 0

    def get_url(self, uri, addr='127.0.0.1'):
示例#3
0
import webtest

from pywb.perms.perms_handler import create_perms_checker_app
from pywb.perms.perms_handler import ALLOW, BLOCK
from pywb.framework.wsgi_wrappers import init_app

from server_mock import make_setup_module, BaseIntegration

setup_module = make_setup_module('tests/test_config.yaml', create_perms_checker_app)

class TestPermsApp(BaseIntegration):
    def test_allow(self):
        resp = self.testapp.get('/check-access/http://example.com')

        assert resp.content_type == 'application/json'

        assert ALLOW in resp.body


    def test_allow_with_timestamp(self):
        resp = self.testapp.get('/check-access/20131024000102/http://example.com')

        assert resp.content_type == 'application/json'

        assert ALLOW in resp.body


    def test_block_with_timestamp(self):
        resp = self.testapp.get('/check-access/20131024000102/http://www.iana.org/_img/bookmark_icon.ico')

        assert resp.content_type == 'application/json'
示例#4
0
from pytest import raises
import webtest
import base64

from pywb.webapp.pywb_init import create_wb_router
from pywb.framework.wsgi_wrappers import init_app
from pywb.cdx.cdxobject import CDXObject

from server_mock import make_setup_module, BaseIntegration

setup_module = make_setup_module('tests/test_config.yaml')


class TestProxyHttpAuth(BaseIntegration):
    def _assert_basic_html(self, resp):
        assert resp.status_int == 200
        assert resp.content_type == 'text/html'
        assert resp.content_length > 0

    def _assert_basic_text(self, resp):
        assert resp.status_int == 200
        assert resp.content_type == 'text/plain'
        assert resp.content_length > 0

        assert 'proxy_magic = ""' in resp.body
        assert 'wb.js' in resp.body

    # 'Simulating' proxy by settings REQUEST_URI explicitly to http:// url and no SCRIPT_NAME
    # would be nice to be able to test proxy more
    def test_proxy_replay(self):
        resp = self.testapp.get('/x-ignore-this-x', extra_environ = dict(REQUEST_URI = 'http://www.iana.org/domains/idn-tables', SCRIPT_NAME = ''))
示例#5
0
import webtest
from pywb.webapp.pywb_init import create_wb_router
from pywb.framework.wsgi_wrappers import init_app

from memento_fixture import *

from server_mock import make_setup_module, BaseIntegration

setup_module = make_setup_module('tests/test_config_frames.yaml')


class TestMementoFrameInverse(MementoMixin, BaseIntegration):
    def test_top_frame_replay(self):
        resp = self.testapp.get('/pywb/20140127171238/http://www.iana.org/')

        # Memento Headers
        # no vary header
        assert VARY not in resp.headers
        assert MEMENTO_DATETIME in resp.headers

        # memento link
        dt = 'Mon, 27 Jan 2014 17:12:38 GMT'

        links = self.get_links(resp)
        assert self.make_memento_link('http://www.iana.org/', '20140127171238mp_', dt) in links

        #timegate link
        assert '<http://localhost:80/pywb/mp_/http://www.iana.org/>; rel="timegate"' in links

        # Body
        assert '<iframe ' in resp.body
示例#6
0
from pywb.webapp.pywb_init import create_wb_router
from pywb.framework.wsgi_wrappers import init_app
from pywb.framework.basehandlers import BaseHandler
from pywb.framework.wbrequestresponse import WbResponse

from server_mock import make_setup_module, BaseIntegration

setup_module = make_setup_module('tests/test_config_root_coll.yaml')


# A custom handler
class RedirHandler(BaseHandler):
    def __call__(self, wbrequest):
        return WbResponse.redir_response(self.redir_path + wbrequest.wb_url_str)


class TestMementoFrameInverse(BaseIntegration):
    def test_timestamp_replay_redir(self):
        resp = self.testapp.get('/http://www.iana.org/')
        assert resp.status_int == 302
        assert resp.headers['Location'].endswith('/20140127171238/http://www.iana.org/')


    def test_replay(self):
        resp = self.testapp.get('/20140127171238/http://www.iana.org/')

        # Body
        assert '"20140127171238"' in resp.body
        assert 'wb.js' in resp.body
        assert 'new _WBWombat' in resp.body, resp.body
        assert '/20140127171238/http://www.iana.org/time-zones"' in resp.body