2014-03-03 19:37:37 -08:00
|
|
|
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
|
|
|
|
|
2016-02-23 13:26:53 -08:00
|
|
|
from .server_mock import make_setup_module, BaseIntegration
|
2014-03-03 19:37:37 -08:00
|
|
|
|
2015-10-14 20:34:46 -07:00
|
|
|
setup_module = make_setup_module('tests/test_config.yaml', create_perms_checker_app)
|
2014-03-03 19:37:37 -08:00
|
|
|
|
2015-10-14 20:34:46 -07:00
|
|
|
class TestPermsApp(BaseIntegration):
|
2014-03-03 19:37:37 -08:00
|
|
|
def test_allow(self):
|
|
|
|
resp = self.testapp.get('/check-access/http://example.com')
|
|
|
|
|
|
|
|
assert resp.content_type == 'application/json'
|
|
|
|
|
2016-02-23 13:26:53 -08:00
|
|
|
assert ALLOW in resp.text
|
2014-03-03 19:37:37 -08:00
|
|
|
|
|
|
|
|
|
|
|
def test_allow_with_timestamp(self):
|
|
|
|
resp = self.testapp.get('/check-access/20131024000102/http://example.com')
|
|
|
|
|
|
|
|
assert resp.content_type == 'application/json'
|
|
|
|
|
2016-02-23 13:26:53 -08:00
|
|
|
assert ALLOW in resp.text
|
2014-03-03 19:37:37 -08:00
|
|
|
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
2016-02-23 13:26:53 -08:00
|
|
|
assert BLOCK in resp.text
|
2014-03-03 19:37:37 -08:00
|
|
|
|
2016-02-23 13:26:53 -08:00
|
|
|
# no longer 'bad' due since surt 0.3b
|
|
|
|
#def test_bad_url(self):
|
|
|
|
# resp = self.testapp.get('/check-access/@#$', expect_errors=True, status = 400)
|
2014-03-03 19:37:37 -08:00
|
|
|
|
2016-02-23 13:26:53 -08:00
|
|
|
# assert resp.status_int == 404
|
2014-03-03 19:37:37 -08:00
|
|
|
|
2016-02-23 13:26:53 -08:00
|
|
|
# assert 'Invalid Url: http://@' in resp.text
|
2014-03-03 19:37:37 -08:00
|
|
|
|
|
|
|
|
|
|
|
def test_not_found(self):
|
|
|
|
resp = self.testapp.get('/check-access/#abc', expect_errors=True, status = 404)
|
|
|
|
|
|
|
|
assert resp.status_int == 404
|