2014-02-28 01:39:04 +00:00
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
import yaml
|
|
|
|
|
2014-03-03 18:27:04 -08:00
|
|
|
from pywb.perms.perms_filter import AllowAllPerms, AllowAllPermsPolicy
|
2014-02-28 19:47:24 +00:00
|
|
|
|
2014-02-28 01:39:04 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def testconfig():
|
|
|
|
config = yaml.load(open('test_config.yaml'))
|
|
|
|
assert config
|
|
|
|
if 'index_paths' not in config:
|
|
|
|
# !!! assumes this module is in a sub-directory of project root.
|
|
|
|
config['index_paths'] = os.path.join(
|
|
|
|
os.path.dirname(os.path.realpath(__file__)),
|
|
|
|
'../sample_archive/cdx')
|
|
|
|
return config
|
|
|
|
|
|
|
|
#================================================================
|
|
|
|
# Reporter callback for replay view
|
|
|
|
class PrintReporter:
|
|
|
|
"""Reporter callback for replay view.
|
|
|
|
"""
|
|
|
|
def __call__(self, wbrequest, cdx, response):
|
|
|
|
print wbrequest
|
|
|
|
print cdx
|
|
|
|
pass
|
|
|
|
|
|
|
|
#================================================================
|
2014-02-28 19:47:24 +00:00
|
|
|
class TestExclusionPerms(AllowAllPerms):
|
2014-02-28 01:39:04 +00:00
|
|
|
"""
|
2014-03-03 18:27:04 -08:00
|
|
|
Perm Checker fixture to block a single url for testing
|
2014-02-28 01:39:04 +00:00
|
|
|
"""
|
|
|
|
# sample_archive has captures for this URLKEY
|
|
|
|
URLKEY_EXCLUDED = 'org,iana)/_img/bookmark_icon.ico'
|
|
|
|
|
2014-03-03 12:16:07 -08:00
|
|
|
def allow_url_lookup(self, urlkey):
|
2014-02-28 01:39:04 +00:00
|
|
|
"""
|
2014-03-03 18:27:04 -08:00
|
|
|
Return true/false if url (canonicalized url)
|
2014-02-28 01:39:04 +00:00
|
|
|
should be allowed
|
|
|
|
"""
|
|
|
|
if urlkey == self.URLKEY_EXCLUDED:
|
|
|
|
return False
|
|
|
|
|
2014-03-03 12:16:07 -08:00
|
|
|
return super(TestExclusionPerms, self).allow_url_lookup(urlkey)
|
2014-03-03 18:27:04 -08:00
|
|
|
|
|
|
|
|
|
|
|
#================================================================
|
|
|
|
class TestExclusionPermsPolicy(AllowAllPermsPolicy):
|
|
|
|
def create_perms_checker(self, wbrequest):
|
|
|
|
return TestExclusionPerms()
|