mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +01:00
cookie_rewriter: ensure cookie paths are always relative
cookie_rewriter tests: add cookie rewriter tests for secure, httponly html_rewriter tests: add <base> rel and abs rewrite tests no cover for waitress as its not used by default
This commit is contained in:
parent
569614da24
commit
466968e974
@ -49,12 +49,12 @@ class BaseCli(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if self.r.server == 'waitress':
|
if self.r.server == 'waitress': #pragma: no cover
|
||||||
self.run_waitress()
|
self.run_waitress()
|
||||||
else:
|
else:
|
||||||
self.run_wsgiref()
|
self.run_wsgiref()
|
||||||
|
|
||||||
def run_waitress(self):
|
def run_waitress(self): #pragma: no cover
|
||||||
from waitress import serve
|
from waitress import serve
|
||||||
print(self.desc)
|
print(self.desc)
|
||||||
serve(self.application, port=self.r.port, threads=self.r.threads)
|
serve(self.application, port=self.r.port, threads=self.r.threads)
|
||||||
|
@ -18,7 +18,14 @@ class WbUrlBaseCookieRewriter(object):
|
|||||||
|
|
||||||
for name, morsel in cookie.iteritems():
|
for name, morsel in cookie.iteritems():
|
||||||
morsel = self.rewrite_cookie(name, morsel)
|
morsel = self.rewrite_cookie(name, morsel)
|
||||||
|
|
||||||
if morsel:
|
if morsel:
|
||||||
|
path = morsel.get('path')
|
||||||
|
if path:
|
||||||
|
inx = path.find(self.url_rewriter.rel_prefix)
|
||||||
|
if inx > 0:
|
||||||
|
morsel['path'] = path[inx:]
|
||||||
|
|
||||||
results.append((header, morsel.OutputString()))
|
results.append((header, morsel.OutputString()))
|
||||||
|
|
||||||
return results
|
return results
|
||||||
@ -78,23 +85,14 @@ class HostScopeCookieRewriter(WbUrlBaseCookieRewriter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def rewrite_cookie(self, name, morsel):
|
def rewrite_cookie(self, name, morsel):
|
||||||
new_path = None
|
|
||||||
|
|
||||||
# if domain set, expand cookie to host prefix
|
# if domain set, expand cookie to host prefix
|
||||||
if morsel.get('domain'):
|
if morsel.get('domain'):
|
||||||
del morsel['domain']
|
del morsel['domain']
|
||||||
new_path = self.url_rewriter.rewrite('/')
|
morsel['path'] = self.url_rewriter.rewrite('/')
|
||||||
|
|
||||||
# set cookie to rewritten path
|
# set cookie to rewritten path
|
||||||
elif morsel.get('path'):
|
elif morsel.get('path'):
|
||||||
new_path = self.url_rewriter.rewrite(morsel['path'])
|
morsel['path'] = self.url_rewriter.rewrite(morsel['path'])
|
||||||
|
|
||||||
if new_path:
|
|
||||||
inx = new_path.find(self.url_rewriter.rel_prefix)
|
|
||||||
if inx > 0:
|
|
||||||
new_path = new_path[inx:]
|
|
||||||
|
|
||||||
morsel['path'] = new_path
|
|
||||||
|
|
||||||
self._remove_age_opts(morsel)
|
self._remove_age_opts(morsel)
|
||||||
return morsel
|
return morsel
|
||||||
|
@ -34,12 +34,15 @@ r"""
|
|||||||
|
|
||||||
|
|
||||||
# HostCookieRewriter -- set path to host
|
# HostCookieRewriter -- set path to host
|
||||||
>>> rewrite_cookie('some=value; Path=/diff/path/;', urlrewriter, 'host')
|
>>> rewrite_cookie('some=value; Path=/diff/path/', urlrewriter, 'host')
|
||||||
[('Set-Cookie', 'some=value; Path=/pywb/20131226101010/http://example.com/diff/path/')]
|
[('Set-Cookie', 'some=value; Path=/pywb/20131226101010/http://example.com/diff/path/')]
|
||||||
|
|
||||||
>>> rewrite_cookie('some=value; Domain=.example.com; Path=/diff/path/; Max-Age=1500', urlrewriter, 'host')
|
>>> rewrite_cookie('some=value; Domain=.example.com; Path=/diff/path/; Max-Age=1500', urlrewriter, 'host')
|
||||||
[('Set-Cookie', 'some=value; Path=/pywb/20131226101010/http://example.com/')]
|
[('Set-Cookie', 'some=value; Path=/pywb/20131226101010/http://example.com/')]
|
||||||
|
|
||||||
|
>>> rewrite_cookie('some=value; Domain=.example.com; Secure; Path=/diff/path/; HttpOnly; Max-Age=1500', urlrewriter, 'host')
|
||||||
|
[('Set-Cookie', 'some=value; httponly; Path=/pywb/20131226101010/http://example.com/')]
|
||||||
|
|
||||||
|
|
||||||
# RootCookieRewriter -- always sets Path=/, removes Domain
|
# RootCookieRewriter -- always sets Path=/, removes Domain
|
||||||
>>> rewrite_cookie('some=value; Path=/diff/path/;', urlrewriter, 'root')
|
>>> rewrite_cookie('some=value; Path=/diff/path/;', urlrewriter, 'root')
|
||||||
@ -62,7 +65,7 @@ r"""
|
|||||||
from pywb.rewrite.cookie_rewriter import MinimalScopeCookieRewriter, get_cookie_rewriter
|
from pywb.rewrite.cookie_rewriter import MinimalScopeCookieRewriter, get_cookie_rewriter
|
||||||
from pywb.rewrite.url_rewriter import UrlRewriter
|
from pywb.rewrite.url_rewriter import UrlRewriter
|
||||||
|
|
||||||
urlrewriter = UrlRewriter('20131226101010/http://example.com/some/path/index.html', '/pywb/')
|
urlrewriter = UrlRewriter('20131226101010/http://example.com/some/path/index.html', 'http://localhost:8080/pywb/', rel_prefix='/pywb/')
|
||||||
|
|
||||||
urlrewriter2 = UrlRewriter('em_/http://example.com/', '/preview/')
|
urlrewriter2 = UrlRewriter('em_/http://example.com/', '/preview/')
|
||||||
|
|
||||||
|
@ -24,6 +24,14 @@ ur"""
|
|||||||
>>> parse('<html><head><base href="http://example.com/diff/path/file.html"/>')
|
>>> parse('<html><head><base href="http://example.com/diff/path/file.html"/>')
|
||||||
<html><head><base href="/web/20131226101010/http://example.com/diff/path/file.html"/>
|
<html><head><base href="/web/20131226101010/http://example.com/diff/path/file.html"/>
|
||||||
|
|
||||||
|
# Full Path
|
||||||
|
>>> parse('<html><head><base href="http://example.com/diff/path/file.html"/>', urlrewriter=full_path_urlrewriter)
|
||||||
|
<html><head><base href="http://localhost:80/web/20131226101010/http://example.com/diff/path/file.html"/>
|
||||||
|
|
||||||
|
# Rel Base
|
||||||
|
>>> parse('<html><head><base href="/other/file.html"/>', urlrewriter=full_path_urlrewriter)
|
||||||
|
<html><head><base href="/web/20131226101010/http://example.com/other/file.html"/>
|
||||||
|
|
||||||
>>> parse('<base href="static/"/><img src="image.gif"/>')
|
>>> parse('<base href="static/"/><img src="image.gif"/>')
|
||||||
<base href="/web/20131226101010/http://example.com/some/path/static/"/><img src="/web/20131226101010im_/http://example.com/some/path/static/image.gif"/>
|
<base href="/web/20131226101010/http://example.com/some/path/static/"/><img src="/web/20131226101010im_/http://example.com/some/path/static/image.gif"/>
|
||||||
|
|
||||||
@ -186,6 +194,10 @@ urlrewriter = UrlRewriter('20131226101010/http://example.com/some/path/index.htm
|
|||||||
'/web/',
|
'/web/',
|
||||||
rewrite_opts=dict(punycode_links=False))
|
rewrite_opts=dict(punycode_links=False))
|
||||||
|
|
||||||
|
full_path_urlrewriter = UrlRewriter('20131226101010/http://example.com/some/path/index.html',
|
||||||
|
'http://localhost:80/web/',
|
||||||
|
rewrite_opts=dict(punycode_links=False))
|
||||||
|
|
||||||
urlrewriter_pencode = UrlRewriter('20131226101010/http://example.com/some/path/index.html',
|
urlrewriter_pencode = UrlRewriter('20131226101010/http://example.com/some/path/index.html',
|
||||||
'/web/',
|
'/web/',
|
||||||
rewrite_opts=dict(punycode_links=True))
|
rewrite_opts=dict(punycode_links=True))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user