@@ -30,6 +30,7 @@ def test_dev() -> None:
3030 "workers" : None ,
3131 "root_path" : "" ,
3232 "proxy_headers" : True ,
33+ "forwarded_allow_ips" : None ,
3334 "log_config" : get_uvicorn_log_config (),
3435 }
3536 assert "Using import string: single_file_app:app" in result .output
@@ -59,6 +60,7 @@ def test_dev_package() -> None:
5960 "workers" : None ,
6061 "root_path" : "" ,
6162 "proxy_headers" : True ,
63+ "forwarded_allow_ips" : None ,
6264 "log_config" : get_uvicorn_log_config (),
6365 }
6466 assert "Using import string: nested_package.package:app" in result .output
@@ -107,6 +109,7 @@ def test_dev_args() -> None:
107109 "workers" : None ,
108110 "root_path" : "/api" ,
109111 "proxy_headers" : False ,
112+ "forwarded_allow_ips" : None ,
110113 "log_config" : get_uvicorn_log_config (),
111114 }
112115 assert "Using import string: single_file_app:api" in result .output
@@ -134,6 +137,33 @@ def test_run() -> None:
134137 "workers" : None ,
135138 "root_path" : "" ,
136139 "proxy_headers" : True ,
140+ "forwarded_allow_ips" : None ,
141+ "log_config" : get_uvicorn_log_config (),
142+ }
143+ assert "Using import string: single_file_app:app" in result .output
144+ assert "Starting production server 🚀" in result .output
145+ assert "Server started at http://0.0.0.0:8000" in result .output
146+ assert "Documentation at http://0.0.0.0:8000/docs" in result .output
147+
148+
149+ def test_run_trust_proxy () -> None :
150+ with changing_dir (assets_path ):
151+ with patch .object (uvicorn , "run" ) as mock_run :
152+ result = runner .invoke (
153+ app , ["run" , "single_file_app.py" , "--forwarded-allow-ips" , "*" ]
154+ )
155+ assert result .exit_code == 0 , result .output
156+ assert mock_run .called
157+ assert mock_run .call_args
158+ assert mock_run .call_args .kwargs == {
159+ "app" : "single_file_app:app" ,
160+ "host" : "0.0.0.0" ,
161+ "port" : 8000 ,
162+ "reload" : False ,
163+ "workers" : None ,
164+ "root_path" : "" ,
165+ "proxy_headers" : True ,
166+ "forwarded_allow_ips" : "*" ,
137167 "log_config" : get_uvicorn_log_config (),
138168 }
139169 assert "Using import string: single_file_app:app" in result .output
@@ -179,6 +209,7 @@ def test_run_args() -> None:
179209 "workers" : 2 ,
180210 "root_path" : "/api" ,
181211 "proxy_headers" : False ,
212+ "forwarded_allow_ips" : None ,
182213 "log_config" : get_uvicorn_log_config (),
183214 }
184215
0 commit comments