Skip to content

Commit

Permalink
change httpbin service used in a few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brondsem committed Sep 11, 2024
1 parent 4dda5dd commit a5a3d96
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 8 additions & 5 deletions Allura/allura/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
from alluratest.controller import setup_basic_test
import six

# httpbin.org should work, but lately has been unreliable
# httpbin.io does not allow /redirect-to to localhost
httpbin_domain = 'httpbin.dev'

def setup_module():
setup_basic_test()
Expand Down Expand Up @@ -480,17 +483,17 @@ class TestUrlOpen:
'http://localhost/',
'https://localhost/',
'http://localhost:8080',
'https://httpbin.org/redirect-to?url=http://localhost',
'https://httpbin.org/redirect-to?url=https://localhost',
f'https://{httpbin_domain}/redirect-to?url=http://localhost',
f'https://{httpbin_domain}/redirect-to?url=https://localhost',
])
def test_internal_invalid(self, url):
with pytest.raises(fev.Invalid):
h.urlopen(url)

@pytest.mark.parametrize('url', [
'http://httpbin.org/status/200',
'https://httpbin.org/status/200',
'http://httpbin.org:80/status/200',
f'http://{httpbin_domain}/status/200',
f'https://{httpbin_domain}/status/200',
f'http://{httpbin_domain}:80/status/200',
])
def test_ok(self, url):
h.urlopen(url)
Expand Down
5 changes: 3 additions & 2 deletions ForgeImporters/forgeimporters/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from tg import expose, config
from webob.exc import HTTPUnauthorized

from allura.tests.test_helpers import httpbin_domain
from alluratest.controller import TestController, setup_basic_test
from allura.tests import decorators as td
from allura.lib import helpers as h
Expand Down Expand Up @@ -58,11 +59,11 @@ def test_urlopen_internal_blocked(self):
base.ProjectExtractor.urlopen('http://localhost:1234/blah', data=b'foo')

# redirect to external site ok
base.ProjectExtractor.urlopen('https://httpbin.org/redirect-to?url=http%3A%2F%2Fexample.com%2F')
base.ProjectExtractor.urlopen(f'https://{httpbin_domain}/redirect-to?url=http%3A%2F%2Fexample.com%2F')

# redirect to internal is blocked
with pytest.raises(Invalid):
base.ProjectExtractor.urlopen('https://httpbin.org/redirect-to?url=http%3A%2F%2Flocalhost%2F')
base.ProjectExtractor.urlopen(f'https://{httpbin_domain}/redirect-to?url=http%3A%2F%2Flocalhost%2F')

@mock.patch('forgeimporters.base.h.urlopen')
@mock.patch('urllib.request.Request')
Expand Down

0 comments on commit a5a3d96

Please sign in to comment.