1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

replay top-frame redirect: add fast redirect check to top-frame, instead of waiting for check in wombat.js, closes #305

tests: ensure redirect check only added in framed mode, ensure added for banner only mode, but not for proxy mode
This commit is contained in:
Ilya Kreymer 2018-02-27 18:13:07 -08:00
parent 84723c9d7d
commit e928f8a7e6
3 changed files with 29 additions and 4 deletions

View File

@ -1,14 +1,25 @@
<!-- WB Insert -->
<script>
{% set urlsplit = cdx.url | urlsplit %}
{% set urlsplit = cdx.url | urlsplit %}
wbinfo = {}
wbinfo.top_url = "{{ top_url }}";
{% if is_framed == 'true' %}
// Fast Top-Frame Redirect
if (window == window.top && wbinfo.top_url) {
var loc = window.location.href.replace(window.location.hash, "");
loc = decodeURI(loc);
if (loc != decodeURI(wbinfo.top_url)) {
window.location.href = wbinfo.top_url + window.location.hash;
}
}
{% endif %}
wbinfo.url = "{{ cdx.url }}";
wbinfo.timestamp = "{{ cdx.timestamp }}";
wbinfo.request_ts = "{{ wb_url.timestamp }}";
wbinfo.prefix = decodeURI("{{ wb_prefix }}");
wbinfo.mod = "{{ wb_url.mod }}";
wbinfo.top_url = "{{ top_url }}";
wbinfo.is_framed = {{ is_framed }};
wbinfo.is_framed = {{ is_framed }};
wbinfo.is_live = {{ is_live }};
wbinfo.coll = "{{ coll }}";
wbinfo.proxy_magic = "{{ env.pywb_proxy_magic }}";

View File

@ -90,7 +90,12 @@ class TestWbIntegration(BaseConfigTest):
assert 'new _WBWombat' in resp.text, resp.text
assert '/pywb/20140127171238{0}/http://www.iana.org/time-zones"'.format(fmod) in resp.text
assert ('wbinfo.is_framed = ' + ('true' if fmod else 'false')) in resp.text
if fmod == 'mp_':
assert 'window == window.top' in resp.text
assert 'wbinfo.is_framed = true' in resp.text
else:
assert 'window == window.top' not in resp.text
assert 'wbinfo.is_framed = false' in resp.text
csp = "default-src 'unsafe-eval' 'unsafe-inline' 'self' data: blob: mediastream: ws: wss: ; form-action 'self'"
assert resp.headers['Content-Security-Policy'] == csp
@ -169,6 +174,9 @@ class TestWbIntegration(BaseConfigTest):
# no wombat present
assert '_WBWombat' not in resp.text
# top-frame redirect check
assert 'window == window.top' in resp.text
# url not rewritten
#assert '"http://www.iana.org/domains/example"' in resp.text
assert '"/_css/2013.1/screen.css"' in resp.text

View File

@ -63,6 +63,9 @@ class TestProxy(BaseTestProxy):
# no wombat.js
assert 'wombat.js' not in res.text
# no redirect check
assert 'window == window.top' not in res.text
assert res.headers['Link'] == '<http://example.com>; rel="memento"; datetime="Mon, 27 Jan 2014 17:12:51 GMT"; collection="pywb"'
assert res.headers['Memento-Datetime'] == 'Mon, 27 Jan 2014 17:12:51 GMT'
@ -79,6 +82,9 @@ class TestProxy(BaseTestProxy):
# no wombat.js
assert 'wombat.js' not in res.text
# no redirect check
assert 'window == window.top' not in res.text
assert res.headers['Link'] == '<http://test@example.com/>; rel="memento"; datetime="Mon, 29 Jul 2013 19:51:51 GMT"; collection="pywb"'
assert res.headers['Memento-Datetime'] == 'Mon, 29 Jul 2013 19:51:51 GMT'