mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
* embargo: add support for per-collection date range embargo with embargo options of 'before', 'after', 'newer' and 'older' 'before' and 'after' accept a timestamp 'newer' and 'older' options configured with a dictionary consisting of any combo of 'years', 'months', 'days' add basic test for each embargo option * acl/embargo work: - support acl access value 'allow_ignore_embargo' for overriding embargo - support 'user' in acl setting, matched with value of 'X-Pywb-ACL-User' header - support passing through 'X-Pywb-ACL-User' setting to warcserver - aclmanager: support -u/--user param for adding, removing and matching rules - tests: add test for 'allow_ignore_embargo', user-specific acl rule matching * docs: add docs for new embargo system! * docs: add info on how to configure ACL header with short examples to usage page. sample-deploy: add examples of configuring X-pywb-ACL-user header based on IP for nginx and apache sample deployments * docs: fix access control page header, text tweaks * bump version to 2.6.0b0
90 lines
2.9 KiB
Python
90 lines
2.9 KiB
Python
from .base_config_test import BaseConfigTest, fmod
|
|
|
|
import webtest
|
|
import os
|
|
|
|
from six.moves.urllib.parse import urlencode
|
|
|
|
|
|
# ============================================================================
|
|
class TestACLApp(BaseConfigTest):
|
|
@classmethod
|
|
def setup_class(cls):
|
|
super(TestACLApp, cls).setup_class('config_test_access.yaml')
|
|
|
|
def query(self, url, coll='pywb'):
|
|
params = {}
|
|
params['url'] = url
|
|
return self.testapp.get('/{coll}/cdx?'.format(coll=coll) + urlencode(params, doseq=1))
|
|
|
|
def test_excluded_url(self):
|
|
resp = self.query('http://www.iana.org/domains/root')
|
|
|
|
assert len(resp.text.splitlines()) == 0
|
|
|
|
self.testapp.get('/pywb/mp_/http://www.iana.org/domains/root', status=404)
|
|
|
|
def test_allowed_exact_url(self):
|
|
resp = self.query('http://www.iana.org/')
|
|
|
|
assert len(resp.text.splitlines()) == 3
|
|
|
|
self.testapp.get('/pywb/mp_/http://www.iana.org/', status=200)
|
|
|
|
def test_blocked_url(self):
|
|
resp = self.query('http://www.iana.org/about/')
|
|
|
|
assert len(resp.text.splitlines()) == 1
|
|
|
|
resp = self.testapp.get('/pywb/mp_/http://www.iana.org/about/', status=451)
|
|
|
|
assert 'Access Blocked' in resp.text
|
|
|
|
def test_allow_via_acl_header(self):
|
|
resp = self.query('http://www.iana.org/about/')
|
|
|
|
assert len(resp.text.splitlines()) == 1
|
|
|
|
resp = self.testapp.get('/pywb/mp_/http://www.iana.org/about/', headers={"X-Pywb-Acl-User": "staff"}, status=200)
|
|
|
|
def test_allowed_more_specific(self):
|
|
resp = self.query('http://www.iana.org/_css/2013.1/fonts/opensans-semibold.ttf')
|
|
|
|
assert resp.status_code == 200
|
|
|
|
assert len(resp.text.splitlines()) > 0
|
|
|
|
resp = self.testapp.get('/pywb/mp_/http://www.iana.org/_css/2013.1/fonts/opensans-semibold.ttf', status=200)
|
|
|
|
assert resp.content_type == 'application/octet-stream'
|
|
|
|
def test_default_rule_blocked(self):
|
|
resp = self.query('http://httpbin.org/anything/resource.json')
|
|
|
|
assert len(resp.text.splitlines()) > 0
|
|
|
|
resp = self.testapp.get('/pywb/mp_/http://httpbin.org/anything/resource.json', status=451)
|
|
|
|
assert 'Access Blocked' in resp.text
|
|
|
|
def test_allowed_different_coll_acl_list(self):
|
|
resp = self.query('http://httpbin.org/anything/resource.json', coll='pywb-acl-list')
|
|
|
|
assert len(resp.text.splitlines()) > 0
|
|
|
|
resp = self.testapp.get('/pywb-acl-list/mp_/http://httpbin.org/anything/resource.json')
|
|
|
|
assert '"http://httpbin.org/anything/resource.json"' in resp.text
|
|
|
|
def test_allowed_different_coll_acl_dir(self):
|
|
resp = self.query('http://httpbin.org/anything/resource.json', coll='pywb-acl-dir')
|
|
|
|
assert len(resp.text.splitlines()) > 0
|
|
|
|
resp = self.testapp.get('/pywb-acl-dir/mp_/http://httpbin.org/anything/resource.json')
|
|
|
|
assert '"http://httpbin.org/anything/resource.json"' in resp.text
|
|
|
|
|
|
|