Skip to content

Commit f2a2c86

Browse files
committed
tests: proxy check to ensure content-length header is always present in proxy mode
1 parent e9d04c7 commit f2a2c86

File tree

2 files changed

+38
-42
lines changed

2 files changed

+38
-42
lines changed

tests/test_proxy_http_cookie.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,18 @@ def post_url(self, url, data):
4949
data=data,
5050
proxies=server.proxy_dict)
5151

52+
def _test_basic(self, resp, url):
53+
assert resp.status_code == 200
54+
assert 'Content-Length' in resp.headers
55+
assert resp.url == url
56+
5257
def test_replay_no_coll(self):
5358
resp = self.get_url('http://iana.org/')
54-
assert resp.url == 'http://select.pywb.proxy/http://iana.org/'
55-
assert resp.status_code == 200
59+
self._test_basic(resp, 'http://select.pywb.proxy/http://iana.org/')
5660

5761
def test_replay_set_older_coll(self):
5862
resp = self.get_url('http://older-set.pywb.proxy/http://iana.org/')
59-
assert resp.url == 'http://iana.org/'
60-
assert resp.status_code == 200
63+
self._test_basic(resp, 'http://iana.org/')
6164
assert '20140126200624' in resp.text
6265

6366
sesh1 = self.session.cookies.get('__pywb_proxy_sesh', domain='.pywb.proxy')
@@ -73,15 +76,13 @@ def test_replay_set_older_coll(self):
7376

7477
def test_replay_same_coll(self):
7578
resp = self.get_url('http://iana.org/')
76-
assert resp.url == 'http://iana.org/'
77-
assert resp.status_code == 200
79+
self._test_basic(resp, 'http://iana.org/')
7880
assert 'wbinfo.proxy_magic = "pywb.proxy";' in resp.text
7981
assert '20140126200624' in resp.text
8082

8183
def test_replay_set_change_coll(self):
8284
resp = self.get_url('http://all-set.pywb.proxy/http://iana.org/')
83-
assert resp.url == 'http://iana.org/'
84-
assert resp.status_code == 200
85+
self._test_basic(resp, 'http://iana.org/')
8586
assert '20140127171238' in resp.text
8687

8788
# verify still same session cookie
@@ -91,8 +92,7 @@ def test_replay_set_change_coll(self):
9192

9293
def test_query(self):
9394
resp = self.get_url('http://query.pywb.proxy/*/http://iana.org/')
94-
assert resp.url == 'http://query.pywb.proxy/*/http://iana.org/'
95-
assert resp.status_code == 200
95+
self._test_basic(resp, 'http://query.pywb.proxy/*/http://iana.org/')
9696
assert 'text/html' in resp.headers['content-type']
9797
assert '20140126200624' in resp.text
9898
assert '20140127171238' in resp.text
@@ -101,33 +101,33 @@ def test_query(self):
101101
# testing via http here
102102
def test_change_timestamp(self):
103103
resp = self.get_url('http://query.pywb.proxy/20140126200624/http://iana.org/')
104-
assert resp.url == 'http://iana.org/'
105-
assert resp.status_code == 200
104+
self._test_basic(resp, 'http://iana.org/')
105+
assert 'Content-Length' in resp.headers
106106
assert '20140126200624' in resp.text
107107

108108
def test_change_coll_same_ts(self):
109109
resp = self.get_url('http://all-set.pywb.proxy/iana.org/')
110-
assert resp.url == 'http://iana.org/'
111-
assert resp.status_code == 200
110+
self._test_basic(resp, 'http://iana.org/')
111+
assert 'Content-Length' in resp.headers
112112
assert '20140126200624' in resp.text
113113

114114
# testing via http here
115115
def test_change_latest_ts(self):
116116
resp = self.get_url('http://query.pywb.proxy/http://iana.org/?_=1234')
117-
assert resp.url == 'http://iana.org/?_=1234'
118-
assert resp.status_code == 200
117+
self._test_basic(resp, 'http://iana.org/?_=1234')
118+
assert 'Content-Length' in resp.headers
119119
assert '20140127171238' in resp.text
120120

121121
def test_diff_url(self):
122122
resp = self.get_url('http://example.com/')
123-
assert resp.url == 'http://example.com/'
123+
self._test_basic(resp, 'http://example.com/')
124+
assert 'Content-Length' in resp.headers
124125
assert '20140127171251' in resp.text
125126

126127
def test_post_replay_all_coll(self):
127128
resp = self.post_url('http://httpbin.org/post', data={'foo': 'bar', 'test': 'abc'})
128-
assert resp.url == 'http://httpbin.org/post'
129+
self._test_basic(resp, 'http://httpbin.org/post')
129130
assert 'application/json' in resp.headers['content-type']
130-
assert resp.status_code == 200
131131

132132
# Bounce back to select.pywb.proxy due to missing session
133133
def test_clear_key(self):

tests/test_proxy_https_cookie.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,18 @@ def post_url(self, url, data):
6565
proxies=server.proxy_dict,
6666
verify=TEST_CA_ROOT)
6767

68+
def _test_basic(self, resp, url):
69+
assert resp.status_code == 200
70+
assert 'Content-Length' in resp.headers
71+
assert resp.url == url
72+
6873
def test_replay_no_coll(self):
6974
resp = self.get_url('https://iana.org/')
70-
assert resp.url == 'https://select.pywb.proxy/https://iana.org/'
71-
assert resp.status_code == 200
75+
self._test_basic(resp, 'https://select.pywb.proxy/https://iana.org/')
7276

7377
def test_replay_set_older_coll(self):
7478
resp = self.get_url('https://older-set.pywb.proxy/https://iana.org/')
75-
assert resp.url == 'https://iana.org/'
76-
assert resp.status_code == 200
79+
self._test_basic(resp, 'https://iana.org/')
7780
assert '20140126200624' in resp.text
7881

7982
sesh1 = self.session.cookies.get('__pywb_proxy_sesh', domain='.pywb.proxy')
@@ -89,15 +92,13 @@ def test_replay_set_older_coll(self):
8992

9093
def test_replay_same_coll(self):
9194
resp = self.get_url('https://iana.org/')
92-
assert resp.url == 'https://iana.org/'
93-
assert resp.status_code == 200
95+
self._test_basic(resp, 'https://iana.org/')
9496
assert 'wbinfo.proxy_magic = "pywb.proxy";' in resp.text
9597
assert '20140126200624' in resp.text
9698

9799
def test_replay_set_change_coll(self):
98100
resp = self.get_url('https://all-set.pywb.proxy/https://iana.org/')
99-
assert resp.url == 'https://iana.org/'
100-
assert resp.status_code == 200
101+
self._test_basic(resp, 'https://iana.org/')
101102
assert '20140127171238' in resp.text
102103

103104
# verify still same session cookie
@@ -107,8 +108,7 @@ def test_replay_set_change_coll(self):
107108

108109
def test_query(self):
109110
resp = self.get_url('https://query.pywb.proxy/*/https://iana.org/')
110-
assert resp.url == 'https://query.pywb.proxy/*/https://iana.org/'
111-
assert resp.status_code == 200
111+
self._test_basic(resp, 'https://query.pywb.proxy/*/https://iana.org/')
112112
assert 'text/html' in resp.headers['content-type']
113113
assert '20140126200624' in resp.text
114114
assert '20140127171238' in resp.text
@@ -117,35 +117,31 @@ def test_query(self):
117117
# testing via http here
118118
def test_change_timestamp(self):
119119
resp = self.get_url('http://query.pywb.proxy/20140126200624/http://iana.org/')
120-
assert resp.url == 'http://iana.org/'
121-
assert resp.status_code == 200
120+
self._test_basic(resp, 'http://iana.org/')
122121
assert '20140126200624' in resp.text
123122

124123
def test_change_coll_same_ts(self):
125124
resp = self.get_url('https://all-set.pywb.proxy/iana.org/')
126-
assert resp.url == 'https://iana.org/'
127-
assert resp.status_code == 200
125+
self._test_basic(resp, 'https://iana.org/')
128126
assert '20140126200624' in resp.text
129127

130128
# testing via http here
131129
def test_change_latest_ts(self):
132130
resp = self.get_url('http://query.pywb.proxy/http://iana.org/?_=1234')
133-
assert resp.url == 'http://iana.org/?_=1234'
134-
assert resp.status_code == 200
131+
self._test_basic(resp, 'http://iana.org/?_=1234')
135132
assert '20140127171238' in resp.text
136133

137134
def test_diff_url(self):
138135
resp = self.get_url('https://example.com/')
139-
assert resp.url == 'https://example.com/'
136+
self._test_basic(resp, 'https://example.com/')
140137
assert '20140127171251' in resp.text
141138

142139
@pytest.mark.skipif(sys.version_info < (2,7),
143140
reason="doesn't work in 2.6")
144141
def test_post_replay_all_coll(self):
145142
resp = self.post_url('https://httpbin.org/post', data={'foo': 'bar', 'test': 'abc'})
146-
assert resp.url == 'https://httpbin.org/post'
143+
self._test_basic(resp, 'https://httpbin.org/post')
147144
assert 'application/json' in resp.headers['content-type']
148-
assert resp.status_code == 200
149145

150146
# Bounce back to select.pywb.proxy due to missing session
151147
def test_clear_key(self):
@@ -155,19 +151,19 @@ def test_clear_key(self):
155151

156152
def test_no_sesh_latest_bounce(self):
157153
resp = self.get_url('https://query.pywb.proxy/https://iana.org/')
158-
assert resp.url == 'https://select.pywb.proxy/https://iana.org/'
154+
self._test_basic(resp, 'https://select.pywb.proxy/https://iana.org/')
159155

160156
def test_no_sesh_coll_change_bounce(self):
161157
resp = self.get_url('https://auto.pywb.proxy/https://iana.org/')
162-
assert resp.url == 'https://select.pywb.proxy/https://iana.org/'
158+
self._test_basic(resp, 'https://select.pywb.proxy/https://iana.org/')
163159

164160
def test_no_sesh_ts_bounce(self):
165161
resp = self.get_url('https://query.pywb.proxy/20140126200624/https://iana.org/')
166-
assert resp.url == 'https://select.pywb.proxy/20140126200624/https://iana.org/'
162+
self._test_basic(resp, 'https://select.pywb.proxy/20140126200624/https://iana.org/')
167163

168164
def test_no_sesh_query_bounce(self):
169165
resp = self.get_url('https://query.pywb.proxy/*/https://iana.org/')
170-
assert resp.url == 'https://select.pywb.proxy/https://query.pywb.proxy/*/https://iana.org/'
166+
self._test_basic(resp, 'https://select.pywb.proxy/https://query.pywb.proxy/*/https://iana.org/')
171167

172168
# static replay
173169
def test_replay_static(self):

0 commit comments

Comments
 (0)