Skip to content
Myr

Do not enable subdomain matching by default

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Updated tests for new subdomain matching Added a test to validate matching behavior

authored by Armin Ronacher · committed by David Lord · parent 4a7db66 · Browse files · 4 files+52 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+52 added−7 removed

  • tests:+35 added−6 removed
  • other:+17 added−1 removed

4 files+52 added−7 removed

modified:flask/app.py+15 added-1 removed
124 unmodified lines
125126 .. versionadded:: 0.13127 The `host_matching` and `static_host` parameters were added.128129 .. versionadded:: 1.0130 The `subdomain_matching` parameter was added. Subdomain matching131 needs to be enabled manually now. Setting `SERVER_NAME` does not132 implicitly enable it.133134 :param import_name: the name of the application package135 :param static_url_path: can be used to specify a different path for the136 static files on the web. Defaults to the name137 of the `static_folder` folder.
213 unmodified lines
351 static_url_path=None,352 static_folder='static',353 static_host=None,354 host_matching=False,355 subdomain_matching=False,356 template_folder='templates',357 instance_path=None,358 instance_relative_config=False,359 root_path=None
175 unmodified lines
535 #: app.url_map.converters['list'] = ListConverter536 self.url_map = Map()537538 self.url_map.host_matching = host_matching539 self.subdomain_matching = subdomain_matching540541 # tracks internally if the application already handled at least one542 # request.543 self._got_first_request = False
1450 unmodified lines
1994 This can now also be called without a request object when the1995 URL adapter is created for the application context.1996 """1997 if request is not None:1991 return self.url_map.bind_to_environ(request.environ,1998 rv = self.url_map.bind_to_environ(request.environ,1999 server_name=self.config['SERVER_NAME'])2000 # If subdomain matching is not enabled (which is the default2001 # we put back the default subdomain in all cases. This really2002 # should be the default in Werkzeug but it currently does not2003 # have that feature.2004 if not self.subdomain_matching:2005 rv.subdomain = self.url_map.default_subdomain2006 return rv2007 # We need at the very least the server name to be set for this2008 # to work.2009 if self.config['SERVER_NAME'] is not None:2010 return self.url_map.bind(
243 unmodified lines
modified:tests/test_basic.py+29 added-4 removed
1427 unmodified lines
1428 assert repr(flask.g) == '<LocalProxy unbound>'1429 assert not flask.g143014311432def test_test_app_proper_environ(app, client):1432def test_test_app_proper_environ():1433 app = flask.Flask(__name__, subdomain_matching=True)1434 app.config.update(1435 SERVER_NAME='localhost.localdomain:5000'1436 )1437 client = app.test_client()14381439 @app.route('/')1440 def index():1441 return 'Foo'
342 unmodified lines
1784 assert 'foos' not in flask.g1785 assert sorted(flask.g) == ['bar', 'foo']178617871786def test_subdomain_basic_support(app, client):1788def test_subdomain_basic_support():1789 app = flask.Flask(__name__, subdomain_matching=True)1790 app.config['SERVER_NAME'] = 'localhost.localdomain'1791 client = app.test_client()17921793 @app.route('/')1794 def normal_index():1795 return 'normal index'
8 unmodified lines
1804 rv = client.get('/', 'http://test.localhost.localdomain/')1805 assert rv.data == b'test index'180618071804def test_subdomain_matching(app, client):1808def test_subdomain_matching():1809 app = flask.Flask(__name__, subdomain_matching=True)1810 client = app.test_client()1811 app.config['SERVER_NAME'] = 'localhost.localdomain'18121813 @app.route('/', subdomain='<user>')1814 def index(user):
2 unmodified lines
1817 rv = client.get('/', 'http://mitsuhiko.localhost.localdomain/')1818 assert rv.data == b'index for mitsuhiko'181918201815def test_subdomain_matching_with_ports(app, client):1821def test_subdomain_matching_with_ports():1822 app = flask.Flask(__name__, subdomain_matching=True)1823 app.config['SERVER_NAME'] = 'localhost.localdomain:3000'1824 client = app.test_client()18251826 @app.route('/', subdomain='<user>')1827 def index(user):1828 return 'index for %s' % user
1 unmodified line
1830 rv = client.get('/', 'http://mitsuhiko.localhost.localdomain:3000/')1831 assert rv.data == b'index for mitsuhiko'183218331834def test_subdomain_matching_behavior():1835 for matching in False, True:1836 app = flask.Flask(__name__, subdomain_matching=matching)1837 app.config['SERVER_NAME'] = 'localhost.localdomain:3000'1838 client = app.test_client()18391840 @app.route('/')1841 def index():1842 return 'matched without subdomain'18431844 rv = client.get('/', 'http://127.0.0.1:3000/')1845 if matching:1846 assert rv.status_code == 4041847 else:1848 assert rv.data == b'matched without subdomain'184918501851def test_multi_route_rules(app, client):1852 @app.route('/')1853 @app.route('/<test>/')1854 def index(test='a'):
63 unmodified lines
modified:tests/test_testing.py+6 added-2 removed
112 unmodified lines
113 assert eb.script_root == ''114 assert eb.path == '/'115116117def test_blueprint_with_subdomain(app, client):117def test_blueprint_with_subdomain():118 app = flask.Flask(__name__, subdomain_matching=True)119 app.config['SERVER_NAME'] = 'example.com:1234'120 app.config['APPLICATION_ROOT'] = '/foo'121 client = app.test_client()122123 bp = flask.Blueprint('company', __name__, subdomain='xxx')124125 @bp.route('/')
179 unmodified lines
305 assert rv.is_json306 assert rv.get_json() == json_data307308307def test_subdomain(app, client):309def test_subdomain():310 app = flask.Flask(__name__, subdomain_matching=True)311 app.config['SERVER_NAME'] = 'example.com'312 client = app.test_client()313314 @app.route('/', subdomain='<company_id>')315 def view(company_id):316 return company_id
70 unmodified lines
modified:CHANGES.rst+2 added
137 unmodified lines
138- Added :data:`SESSION_COOKIE_SAMESITE` to control the ``SameSite``139 attribute on the session cookie. (`#2607`_)140- Added :meth:`~flask.Flask.test_cli_runner` to create a Click runner141 that can invoke Flask CLI commands for testing. (`#2636`_)142- Subdomain matching is disabled by default now. It can be turned on by143 passing ``subdomain_matching=True`` to the Flask constructor.144145.. _pallets/meta#24: https://github.com/pallets/meta/issues/24146.. _#1421: https://github.com/pallets/flask/issues/1421147.. _#1489: https://github.com/pallets/flask/pull/1489
660 unmodified lines