mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
* rewriting fixes: server side: cookie rewriting: if httponly cookie with mp_/if_ modifier and path ends with '/', add set-cookie for all known modifiers content length parsing: improve content-length parsing to support 'content-length: num,num', parse out the first number (occasionally seen with range requests when range is dropped for upstream) wombat: rewrite_elem: use element.ownerDocument for resolving baseUri for parent paths tests: add tests for cookie all modifier rewrite, bad content-length parsing (skip for py2.7)
107 lines
4.7 KiB
Python
107 lines
4.7 KiB
Python
from .base_config_test import BaseConfigTest, fmod_sl
|
|
from pywb.warcserver.test.testutils import HttpBinLiveTests
|
|
import pytest
|
|
import sys
|
|
|
|
|
|
# ============================================================================
|
|
class TestLiveRewriter(HttpBinLiveTests, BaseConfigTest):
|
|
@classmethod
|
|
def setup_class(cls):
|
|
super(TestLiveRewriter, cls).setup_class('config_test.yaml')
|
|
|
|
def test_live_live_1(self, fmod_sl):
|
|
headers = [('User-Agent', 'python'), ('Referer', 'http://localhost:80/live/other.example.com')]
|
|
resp = self.get('/live/{0}http://example.com/', fmod_sl, headers=headers)
|
|
assert resp.status_int == 200
|
|
|
|
def test_live_live_redirect_2(self, fmod_sl):
|
|
resp = self.get('/live/{0}http://httpbin.org/redirect-to?url=http://example.com/', fmod_sl)
|
|
assert resp.status_int == 302
|
|
|
|
def test_live_live_post(self, fmod_sl):
|
|
resp = self.post('/live/{0}httpbin.org/post', fmod_sl, {'foo': 'bar', 'test': 'abc'})
|
|
assert resp.status_int == 200
|
|
resp.charset = 'utf-8'
|
|
assert '"foo": "bar"' in resp.text
|
|
assert '"test": "abc"' in resp.text
|
|
assert resp.status_int == 200
|
|
|
|
def test_live_anchor_encode(self, fmod_sl):
|
|
resp = self.get('/live/{0}httpbin.org/get?val=abc%23%23xyz', fmod_sl)
|
|
assert 'get?val=abc%23%23xyz"' in resp.text
|
|
assert '"val": "abc##xyz"' in resp.text
|
|
#assert '"http://httpbin.org/anything/abc##xyz"' in resp.text
|
|
assert resp.status_int == 200
|
|
|
|
def test_live_head(self, fmod_sl):
|
|
resp = self.head('/live/{0}httpbin.org/get?foo=bar', fmod_sl)
|
|
assert resp.status_int == 200
|
|
|
|
@pytest.mark.skipif(sys.version_info < (3,0), reason='does not respond in 2.7')
|
|
def test_live_bad_content_length(self, fmod_sl):
|
|
resp = self.get('/live/{0}httpbin.org/response-headers?content-length=149,149', fmod_sl, status=200)
|
|
assert resp.headers['Content-Length'] == '149'
|
|
|
|
resp = self.get('/live/{0}httpbin.org/response-headers?Content-Length=xyz', fmod_sl, status=200)
|
|
assert resp.headers['Content-Length'] == '90'
|
|
|
|
@pytest.mark.skipif(sys.version_info < (3,0), reason='does not respond in 2.7')
|
|
def test_live_bad_content_length_with_range(self, fmod_sl):
|
|
resp = self.get('/live/{0}httpbin.org/response-headers?content-length=149,149', fmod_sl,
|
|
headers={'Range': 'bytes=0-'}, status=206)
|
|
assert resp.headers['Content-Length'] == '149'
|
|
assert resp.headers['Content-Range'] == 'bytes 0-148/149'
|
|
|
|
resp = self.get('/live/{0}httpbin.org/response-headers?Content-Length=xyz', fmod_sl,
|
|
headers={'Range': 'bytes=0-'}, status=206)
|
|
assert resp.headers['Content-Length'] == '90'
|
|
assert resp.headers['Content-Range'] == 'bytes 0-89/90'
|
|
|
|
def test_live_live_frame(self):
|
|
resp = self.testapp.get('/live/http://example.com/')
|
|
assert resp.status_int == 200
|
|
resp.charset = 'utf-8'
|
|
#assert '<iframe ' in resp.text
|
|
assert '"http://localhost:80/live/"' in resp.text, resp.text
|
|
assert '"http://example.com/"' in resp.text, resp.text
|
|
|
|
def test_live_invalid(self, fmod_sl):
|
|
resp = self.get('/live/{0}http://abcdef', fmod_sl, status=307)
|
|
resp = resp.follow(status=400)
|
|
assert resp.status_int == 400
|
|
|
|
def test_live_invalid_2(self, fmod_sl):
|
|
resp = self.get('/live/{0}@#$@#$', fmod_sl, status=307)
|
|
resp = resp.follow(status=400)
|
|
assert resp.status_int == 400
|
|
|
|
def test_live_video_info(self):
|
|
pytest.importorskip('youtube_dl')
|
|
resp = self.testapp.get('/live/vi_/https://www.youtube.com/watch?v=DjFZyFWSt1M')
|
|
assert resp.status_int == 200
|
|
assert resp.content_type == 'application/vnd.youtube-dl_formats+json', resp.content_type
|
|
|
|
def test_deflate(self, fmod_sl):
|
|
resp = self.get('/live/{0}http://httpbin.org/deflate', fmod_sl)
|
|
assert b'"deflated": true' in resp.body
|
|
|
|
def test_live_origin_and_referrer(self, fmod_sl):
|
|
headers = {'Referer': 'http://localhost:80/live/{0}http://example.com/test'.format(fmod_sl),
|
|
'Origin': 'http://localhost:80'
|
|
}
|
|
|
|
resp = self.get('/live/{0}http://httpbin.org/get?test=headers', fmod_sl, headers=headers)
|
|
|
|
assert resp.json['headers']['Referer'] == 'http://example.com/test'
|
|
assert resp.json['headers']['Origin'] == 'http://example.com'
|
|
|
|
def test_live_origin_no_referrer(self, fmod_sl):
|
|
headers = {'Origin': 'http://localhost:80'}
|
|
|
|
resp = self.get('/live/{0}http://httpbin.org/get?test=headers', fmod_sl, headers=headers)
|
|
|
|
assert resp.json['headers']['Origin'] == 'http://httpbin.org'
|
|
|
|
|