mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
In particular the X-Pywb-ACL-User header must be forwarded in order for it to be able to control CDX-queries
This commit is contained in:
parent
454486bf75
commit
5c427b9ff2
@ -434,7 +434,11 @@ class FrontEndApp(object):
|
|||||||
cdx_url += 'limit=' + str(self.query_limit)
|
cdx_url += 'limit=' + str(self.query_limit)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = requests.get(cdx_url, stream=True)
|
headers = {}
|
||||||
|
for key in environ.keys():
|
||||||
|
if key.startswith("HTTP_X_"):
|
||||||
|
headers[key[5:].replace("_", "-")] = environ[key]
|
||||||
|
res = requests.get(cdx_url, stream=True, headers=headers)
|
||||||
|
|
||||||
status_line = '{} {}'.format(res.status_code, res.reason)
|
status_line = '{} {}'.format(res.status_code, res.reason)
|
||||||
content_type = res.headers.get('Content-Type')
|
content_type = res.headers.get('Content-Type')
|
||||||
|
@ -5,6 +5,8 @@ org,iana)/_css/2013.1/fonts/opensans-semibold.ttf - {"access": "allow"}
|
|||||||
org,iana)/_css - {"access": "exclude"}
|
org,iana)/_css - {"access": "exclude"}
|
||||||
org,iana)/### - {"access": "allow"}
|
org,iana)/### - {"access": "allow"}
|
||||||
org,iana)/ - {"access": "exclude"}
|
org,iana)/ - {"access": "exclude"}
|
||||||
|
com,example)/?example=3 - {"access": "block", "user": "staff"}
|
||||||
|
com,example)/?example=3 - {"access": "exclude", "user": "staff2"}
|
||||||
org,example)/?example=1 - {"access": "block"}
|
org,example)/?example=1 - {"access": "block"}
|
||||||
com,example)/?example=2 - {"access": "allow_ignore_embargo"}
|
com,example)/?example=2 - {"access": "allow_ignore_embargo"}
|
||||||
com,example)/?example=1 - {"access": "allow_ignore_embargo", "user": "staff2"}
|
com,example)/?example=1 - {"access": "allow_ignore_embargo", "user": "staff2"}
|
||||||
|
@ -41,12 +41,23 @@ class TestACLApp(BaseConfigTest):
|
|||||||
assert 'Access Blocked' in resp.text
|
assert 'Access Blocked' in resp.text
|
||||||
|
|
||||||
def test_allow_via_acl_header(self):
|
def test_allow_via_acl_header(self):
|
||||||
resp = self.query('http://www.iana.org/about/')
|
resp = self.testapp.get('/pywb/cdx?url=http://www.iana.org/about/', headers={"X-Pywb-Acl-User": "staff"})
|
||||||
|
|
||||||
assert len(resp.text.splitlines()) == 1
|
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)
|
resp = self.testapp.get('/pywb/mp_/http://www.iana.org/about/', headers={"X-Pywb-Acl-User": "staff"}, status=200)
|
||||||
|
|
||||||
|
def test_block_via_acl_header(self):
|
||||||
|
resp = self.testapp.get('/pywb/cdx?url=http://example.com/?example=3', headers={"X-Pywb-Acl-User": "staff"})
|
||||||
|
assert len(resp.text.splitlines()) > 0
|
||||||
|
|
||||||
|
resp = self.testapp.get('/pywb/mp_/http://example.com/?example=3', headers={"X-Pywb-Acl-User": "staff"}, status=451)
|
||||||
|
|
||||||
|
def test_exclude_via_acl_header(self):
|
||||||
|
resp = self.testapp.get('/pywb/cdx?url=http://example.com/?example=3', headers={"X-Pywb-Acl-User": "staff2"})
|
||||||
|
assert len(resp.text.splitlines()) == 0
|
||||||
|
|
||||||
|
resp = self.testapp.get('/pywb/mp_/http://example.com/?example=3', headers={"X-Pywb-Acl-User": "staff2"}, status=404)
|
||||||
|
|
||||||
def test_allowed_more_specific(self):
|
def test_allowed_more_specific(self):
|
||||||
resp = self.query('http://www.iana.org/_css/2013.1/fonts/opensans-semibold.ttf')
|
resp = self.query('http://www.iana.org/_css/2013.1/fonts/opensans-semibold.ttf')
|
||||||
|
|
||||||
|
@ -46,8 +46,12 @@ class TestEmbargoApp(BaseConfigTest):
|
|||||||
def test_embargo_ignore_acl_with_header_only(self):
|
def test_embargo_ignore_acl_with_header_only(self):
|
||||||
# ignore embargo with custom header only
|
# ignore embargo with custom header only
|
||||||
headers = {"X-Pywb-ACL-User": "staff2"}
|
headers = {"X-Pywb-ACL-User": "staff2"}
|
||||||
resp = self.testapp.get('/pywb-embargo-acl/20140126201054mp_/http://example.com/?example=1', status=200, headers=headers)
|
|
||||||
|
|
||||||
|
resp = self.testapp.get('/pywb-embargo-acl/cdx?url=http://example.com/?example=1', headers=headers)
|
||||||
|
assert len(resp.text.splitlines()) > 0
|
||||||
|
resp = self.testapp.get('/pywb-embargo-acl/20140126201054mp_/http://example.com/?example=1', status=200, headers=headers)
|
||||||
|
resp = self.testapp.get('/pywb-embargo-acl/cdx?url=http://example.com/?example=1')
|
||||||
|
assert len(resp.text.splitlines()) == 0
|
||||||
resp = self.testapp.get('/pywb-embargo-acl/20140126201054mp_/http://example.com/?example=1', status=404)
|
resp = self.testapp.get('/pywb-embargo-acl/20140126201054mp_/http://example.com/?example=1', status=404)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user