1818from __future__ import annotations
1919
2020import hashlib
21+ import re
2122import runpy
2223import sys
2324from datetime import timedelta
@@ -86,15 +87,26 @@ def debug_view():
8687 assert b"success" == response .get_data ()
8788 assert response .status_code == 200
8889
89- @conf_vars (
90- {
91- ("webserver" , "base_url" ): "http://localhost:8080/internal-client" ,
92- }
90+ @pytest .mark .parametrize (
91+ "base_url, expected_exception" ,
92+ [
93+ ("http://localhost:8080/internal-client" , None ),
94+ (
95+ "http://localhost:8080/internal-client/" ,
96+ AirflowConfigException ("webserver.base_url conf cannot have a trailing slash." ),
97+ ),
98+ ],
9399 )
94100 @dont_initialize_flask_app_submodules
95- def test_should_respect_base_url_ignore_proxy_headers (self ):
96- app = application .cached_app (testing = True )
97- app .url_map .add (Rule ("/debug" , endpoint = "debug" ))
101+ def test_should_respect_base_url_ignore_proxy_headers (self , base_url , expected_exception ):
102+ with conf_vars ({("webserver" , "base_url" ): base_url }):
103+ if expected_exception :
104+ with pytest .raises (expected_exception .__class__ , match = re .escape (str (expected_exception ))):
105+ app = application .cached_app (testing = True )
106+ app .url_map .add (Rule ("/debug" , endpoint = "debug" ))
107+ return
108+ app = application .cached_app (testing = True )
109+ app .url_map .add (Rule ("/debug" , endpoint = "debug" ))
98110
99111 def debug_view ():
100112 from flask import request
@@ -126,9 +138,18 @@ def debug_view():
126138 assert b"success" == response .get_data ()
127139 assert response .status_code == 200
128140
141+ @pytest .mark .parametrize (
142+ "base_url, expected_exception" ,
143+ [
144+ ("http://localhost:8080/internal-client" , None ),
145+ (
146+ "http://localhost:8080/internal-client/" ,
147+ AirflowConfigException ("webserver.base_url conf cannot have a trailing slash." ),
148+ ),
149+ ],
150+ )
129151 @conf_vars (
130152 {
131- ("webserver" , "base_url" ): "http://localhost:8080/internal-client" ,
132153 ("webserver" , "enable_proxy_fix" ): "True" ,
133154 ("webserver" , "proxy_fix_x_for" ): "1" ,
134155 ("webserver" , "proxy_fix_x_proto" ): "1" ,
@@ -138,9 +159,17 @@ def debug_view():
138159 }
139160 )
140161 @dont_initialize_flask_app_submodules
141- def test_should_respect_base_url_when_proxy_fix_and_base_url_is_set_up_but_headers_missing (self ):
142- app = application .cached_app (testing = True )
143- app .url_map .add (Rule ("/debug" , endpoint = "debug" ))
162+ def test_should_respect_base_url_when_proxy_fix_and_base_url_is_set_up_but_headers_missing (
163+ self , base_url , expected_exception
164+ ):
165+ with conf_vars ({("webserver" , "base_url" ): base_url }):
166+ if expected_exception :
167+ with pytest .raises (expected_exception .__class__ , match = re .escape (str (expected_exception ))):
168+ app = application .cached_app (testing = True )
169+ app .url_map .add (Rule ("/debug" , endpoint = "debug" ))
170+ return
171+ app = application .cached_app (testing = True )
172+ app .url_map .add (Rule ("/debug" , endpoint = "debug" ))
144173
145174 def debug_view ():
146175 from flask import request
0 commit comments