Skip to content

Commit acc5d72

Browse files
committed
Loosen URL matching
This allows a non-localhost to work, e.g., java-httpbin. References gaul/java-httpbin#4.
1 parent 9a3dd89 commit acc5d72

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

tests/test_httpbin.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,9 @@ def test_get(self):
146146
self.assertEqual(response.status_code, 200)
147147
data = json.loads(response.data.decode('utf-8'))
148148
self.assertEqual(data['args'], {})
149-
self.assertEqual(data['headers']['Host'], 'localhost')
150149
self.assertEqual(data['headers']['User-Agent'], 'test')
151150
# self.assertEqual(data['origin'], None)
152-
self.assertEqual(data['url'], 'http://localhost/get')
151+
self.assertRegex(data['url'], '^http://[^/]*/get$')
153152
self.assertTrue(response.data.endswith(b'\n'))
154153

155154
def test_anything(self):
@@ -159,8 +158,7 @@ def test_anything(self):
159158
self.assertEqual(response.status_code, 200)
160159
data = json.loads(response.data.decode('utf-8'))
161160
self.assertEqual(data['args'], {})
162-
self.assertEqual(data['headers']['Host'], 'localhost')
163-
self.assertEqual(data['url'], 'http://localhost/anything/foo/bar')
161+
self.assertRegex(data['url'], '^http://[^/]*/anything/foo/bar$')
164162
self.assertEqual(data['method'], 'GET')
165163
self.assertTrue(response.data.endswith(b'\n'))
166164

@@ -581,8 +579,8 @@ def test_redirect_to_post(self):
581579

582580
def test_redirect_absolute_param_n_higher_than_1(self):
583581
response = self.app.get('/redirect/5?absolute=true')
584-
self.assertEqual(
585-
response.headers.get('Location'), 'http://localhost/absolute-redirect/4'
582+
self.assertRegex(
583+
response.headers.get('Location'), '^http://[^/]*/absolute-redirect/4$'
586584
)
587585

588586
def test_redirect_n_equals_to_1(self):
@@ -607,15 +605,15 @@ def test_relative_redirect_n_higher_than_1(self):
607605

608606
def test_absolute_redirect_n_higher_than_1(self):
609607
response = self.app.get('/absolute-redirect/5')
610-
self.assertEqual(
611-
response.headers.get('Location'), 'http://localhost/absolute-redirect/4'
608+
self.assertRegex(
609+
response.headers.get('Location'), '^http://[^/]*/absolute-redirect/4$'
612610
)
613611

614612
def test_absolute_redirect_n_equals_to_1(self):
615613
response = self.app.get('/absolute-redirect/1')
616614
self.assertEqual(response.status_code, 302)
617-
self.assertEqual(
618-
response.headers.get('Location'), 'http://localhost/get'
615+
self.assertRegex(
616+
response.headers.get('Location'), '^http://[^/]*/get$'
619617
)
620618

621619
def test_request_range(self):

0 commit comments

Comments
 (0)