2018-10-26 15:06:59 -07:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2017-05-03 20:05:07 -07:00
|
|
|
from .base_config_test import BaseConfigTest, fmod_sl
|
2018-04-28 18:20:37 -07:00
|
|
|
from pywb.warcserver.test.testutils import HttpBinLiveTests
|
2018-10-26 15:06:59 -07:00
|
|
|
|
|
|
|
from pywb.utils.geventserver import GeventServer
|
2018-01-30 18:26:53 -08:00
|
|
|
import pytest
|
2018-10-05 14:37:32 -07:00
|
|
|
import sys
|
2018-10-26 15:06:59 -07:00
|
|
|
import six
|
|
|
|
|
|
|
|
|
|
|
|
# ============================================================================
|
|
|
|
def header_test_server(environ, start_response):
|
|
|
|
body = b'body'
|
|
|
|
value = u'⛄'
|
|
|
|
value = value.encode('utf-8')
|
|
|
|
if six.PY3:
|
|
|
|
value = value.decode('latin-1')
|
|
|
|
|
|
|
|
headers = []
|
|
|
|
if environ['PATH_INFO'] == '/unicode':
|
|
|
|
headers = [('Content-Length', str(len(body))),
|
|
|
|
('x-utf-8', value)]
|
|
|
|
|
|
|
|
start_response('200 OK', headers=headers)
|
|
|
|
return [body]
|
2015-06-27 16:11:59 -07:00
|
|
|
|
2015-06-27 20:43:15 -07:00
|
|
|
|
2017-02-27 19:07:51 -08:00
|
|
|
# ============================================================================
|
2018-04-28 18:20:37 -07:00
|
|
|
class TestLiveRewriter(HttpBinLiveTests, BaseConfigTest):
|
2017-02-27 19:07:51 -08:00
|
|
|
@classmethod
|
|
|
|
def setup_class(cls):
|
2018-10-26 15:06:59 -07:00
|
|
|
cls.lint_app = False
|
2017-02-27 19:07:51 -08:00
|
|
|
super(TestLiveRewriter, cls).setup_class('config_test.yaml')
|
2018-10-26 15:06:59 -07:00
|
|
|
cls.test_serv = GeventServer(header_test_server)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def teardown_class(cls):
|
|
|
|
cls.test_serv.stop()
|
|
|
|
super(TestLiveRewriter, cls).teardown_class()
|
2014-04-09 15:46:03 -07:00
|
|
|
|
2017-05-03 20:05:07 -07:00
|
|
|
def test_live_live_1(self, fmod_sl):
|
2015-04-13 13:00:06 -07:00
|
|
|
headers = [('User-Agent', 'python'), ('Referer', 'http://localhost:80/live/other.example.com')]
|
2017-05-03 20:05:07 -07:00
|
|
|
resp = self.get('/live/{0}http://example.com/', fmod_sl, headers=headers)
|
2014-04-09 15:46:03 -07:00
|
|
|
assert resp.status_int == 200
|
|
|
|
|
2017-05-03 20:05:07 -07:00
|
|
|
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)
|
2014-10-29 09:47:32 -07:00
|
|
|
assert resp.status_int == 302
|
2014-04-09 15:46:03 -07:00
|
|
|
|
2017-05-03 20:05:07 -07:00
|
|
|
def test_live_live_post(self, fmod_sl):
|
|
|
|
resp = self.post('/live/{0}httpbin.org/post', fmod_sl, {'foo': 'bar', 'test': 'abc'})
|
2014-08-04 21:59:46 -07:00
|
|
|
assert resp.status_int == 200
|
2016-02-23 13:26:53 -08:00
|
|
|
resp.charset = 'utf-8'
|
|
|
|
assert '"foo": "bar"' in resp.text
|
|
|
|
assert '"test": "abc"' in resp.text
|
2014-08-04 21:59:46 -07:00
|
|
|
assert resp.status_int == 200
|
|
|
|
|
2017-10-24 12:52:15 -07:00
|
|
|
def test_live_anchor_encode(self, fmod_sl):
|
2018-04-28 18:20:37 -07:00
|
|
|
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
|
2017-10-24 12:52:15 -07:00
|
|
|
assert resp.status_int == 200
|
|
|
|
|
2018-01-29 16:34:25 -08:00
|
|
|
def test_live_head(self, fmod_sl):
|
2018-04-28 18:20:37 -07:00
|
|
|
resp = self.head('/live/{0}httpbin.org/get?foo=bar', fmod_sl)
|
2018-01-29 16:34:25 -08:00
|
|
|
assert resp.status_int == 200
|
|
|
|
|
2018-10-05 14:37:32 -07:00
|
|
|
@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'
|
|
|
|
|
2018-10-26 15:06:59 -07:00
|
|
|
def test_custom_unicode_header(self, fmod_sl):
|
|
|
|
value = u'⛄'
|
|
|
|
value = value.encode('utf-8')
|
|
|
|
if six.PY3:
|
|
|
|
value = value.decode('latin-1')
|
|
|
|
|
|
|
|
resp = self.get('/live/{0}http://localhost:%s/unicode' % self.test_serv.port, fmod_sl)
|
|
|
|
assert resp.headers['x-utf-8'] == value
|
|
|
|
|
2015-04-13 13:00:06 -07:00
|
|
|
def test_live_live_frame(self):
|
|
|
|
resp = self.testapp.get('/live/http://example.com/')
|
2014-04-09 15:46:03 -07:00
|
|
|
assert resp.status_int == 200
|
2016-07-31 12:56:00 -04:00
|
|
|
resp.charset = 'utf-8'
|
Frame insert refactor (#246)
refactor frame/head insert templates:
ContentFrame:
- content iframe inited with new ContentFrame() which creates iframe
- wb_frame.js: contains ContentFrame system for initing, updating, closing content frame for replayed content.
- wb_frame.js: supports 'app_prefix' and 'content_prefix' or default 'prefix' for replay content
- window.location.hash passed added to init url.
- frame insert and head insert: simplify, remove 'wbrequest'
- frame insert: global wbinfo object no longer needed in top frame, each ContentFrame self-contained.
- wombat.js: next_parent() check does not assume wbinfo is present in top frame
- vidrw.js: only init if wbinfo is present
Banner:
- wb.js no longer needed, frame check/redirect folded into wombat.js
- default banner self-contained in default_banner.js/default_banner.css, handles both frame and frameless case
- rename wb.css -> default_banner.css
- banner html passed in as 'banner_html' variable to be optionally included, supports per collection banner html.
- templateview: BaseInsertView can accept an option 'banner view', used by HeadInsertView and TopFrameView
Tests:
- tests: test_auto_colls uses shared app to test dynamic changes, testing both frame and non-frame access, added per-collection banner html check.
2017-09-30 21:09:38 -07:00
|
|
|
#assert '<iframe ' in resp.text
|
|
|
|
assert '"http://localhost:80/live/"' in resp.text, resp.text
|
|
|
|
assert '"http://example.com/"' in resp.text, resp.text
|
2014-04-09 15:46:03 -07:00
|
|
|
|
2017-05-03 20:05:07 -07:00
|
|
|
def test_live_invalid(self, fmod_sl):
|
|
|
|
resp = self.get('/live/{0}http://abcdef', fmod_sl, status=307)
|
2017-04-04 18:10:49 -07:00
|
|
|
resp = resp.follow(status=400)
|
2014-07-21 22:43:34 -07:00
|
|
|
assert resp.status_int == 400
|
|
|
|
|
2017-05-03 20:05:07 -07:00
|
|
|
def test_live_invalid_2(self, fmod_sl):
|
|
|
|
resp = self.get('/live/{0}@#$@#$', fmod_sl, status=307)
|
2017-04-04 18:10:49 -07:00
|
|
|
resp = resp.follow(status=400)
|
2014-07-21 22:43:34 -07:00
|
|
|
assert resp.status_int == 400
|
|
|
|
|
2014-11-01 13:22:54 -07:00
|
|
|
def test_live_video_info(self):
|
2018-02-27 17:49:36 -08:00
|
|
|
pytest.importorskip('youtube_dl')
|
2015-04-13 13:00:06 -07:00
|
|
|
resp = self.testapp.get('/live/vi_/https://www.youtube.com/watch?v=DjFZyFWSt1M')
|
2014-11-01 13:22:54 -07:00
|
|
|
assert resp.status_int == 200
|
2017-02-27 19:07:51 -08:00
|
|
|
assert resp.content_type == 'application/vnd.youtube-dl_formats+json', resp.content_type
|
2015-06-24 13:11:33 -07:00
|
|
|
|
2017-05-03 20:05:07 -07:00
|
|
|
def test_deflate(self, fmod_sl):
|
|
|
|
resp = self.get('/live/{0}http://httpbin.org/deflate', fmod_sl)
|
2016-02-23 13:26:53 -08:00
|
|
|
assert b'"deflated": true' in resp.body
|
2018-05-21 11:57:43 -07:00
|
|
|
|
|
|
|
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'
|
|
|
|
|
|
|
|
|