From 5da6122d83bf9df942b70e1d7cad013a5a984762 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Fri, 15 Feb 2019 10:29:14 -0800 Subject: [PATCH] memento timemap fix: further fix for ukwa/ukwa-pywb#37 - fix timemap in 'redirect-to-exact' mode, (ensure timegate redirect condition applies only to top-frame) - tests: add additional timemap tests, with and without exact redirect --- pywb/apps/rewriterapp.py | 8 ++++---- tests/test_memento.py | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/pywb/apps/rewriterapp.py b/pywb/apps/rewriterapp.py index 75248cfe..aab05e65 100644 --- a/pywb/apps/rewriterapp.py +++ b/pywb/apps/rewriterapp.py @@ -297,14 +297,14 @@ class RewriterApp(object): else: wb_url.mod = pref_mod else: + # don't return top-frame response for timegate with exact redirects + kwargs['is_timegate_redir'] = is_timegate and redirect_to_exact response = self.handle_custom_response(environ, wb_url, full_prefix, host_prefix, kwargs) if response: - # don't return top-frame response for timegate with exact redirects - if not is_timegate or not redirect_to_exact: - return self.format_response(response, wb_url, full_prefix, is_timegate, is_proxy) + return self.format_response(response, wb_url, full_prefix, is_timegate, is_proxy) if is_proxy: environ['pywb_proxy_magic'] = environ['wsgiprox.proxy_host'] @@ -767,7 +767,7 @@ class RewriterApp(object): if wb_url.is_query(): return self.handle_query(environ, wb_url, kwargs, full_prefix) - if self.is_framed_replay(wb_url): + if self.is_framed_replay(wb_url) and not kwargs.get('is_timegate_redir'): extra_params = self.get_top_frame_params(wb_url, kwargs) return self.frame_insert_view.get_top_frame(wb_url, full_prefix, diff --git a/tests/test_memento.py b/tests/test_memento.py index 521947fe..c2b481c0 100644 --- a/tests/test_memento.py +++ b/tests/test_memento.py @@ -192,6 +192,9 @@ class TestMementoRedirectClassic(MementoMixin, BaseConfigTest): def setup_class(cls): super(TestMementoRedirectClassic, cls).setup_class('config_test_redirect_classic.yaml') + def _timemap_get(self, url, **kwargs): + return self.testapp.get(url, extra_environ={'REQUEST_URI': url}, **kwargs) + def test_memento_top_frame_timegate(self, fmod): resp = self.testapp.get('/pywb/http://www.iana.org/') assert resp.status_code == 307 @@ -249,6 +252,26 @@ class TestMementoRedirectClassic(MementoMixin, BaseConfigTest): assert '"20140126200624"' in resp.text assert '"http://www.iana.org/"' in resp.text, resp.text + def test_timemap(self): + """ + Test application/link-format timemap + """ + + resp = self._timemap_get('/pywb/timemap/link/http://example.com?example=1') + assert resp.status_int == 200 + assert resp.content_type == LINK_FORMAT + + resp.charset = 'utf-8' + + exp = """\ +; rel="self"; type="application/link-format"; from="Fri, 03 Jan 2014 03:03:21 GMT", +; rel="timegate", +; rel="original", +; rel="memento"; datetime="Fri, 03 Jan 2014 03:03:21 GMT"; collection="pywb", +; rel="memento"; datetime="Fri, 03 Jan 2014 03:03:41 GMT"; collection="pywb" +""" + assert exp == resp.text + def test_memento_not_time_gate(self, fmod): headers = {'Accept-Datetime': 'Sun, 26 Jan 2014 20:06:24 GMT'} resp = self.testapp.get('/pywb/2/http://www.iana.org/', headers=headers)