mirror of
https://github.com/apache/superset.git
synced 2026-07-19 05:05:39 +00:00
fix(swagger): honor request.script_root for reverse-proxy prefixes
Restore FAB's script_root behavior so deployments using ProxyFix / X-Forwarded-Prefix or WSGI SCRIPT_NAME keep a working Swagger UI spec URL, falling back to APPLICATION_ROOT when no script root is present. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -15,9 +15,14 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import pytest
|
||||
from flask import Flask
|
||||
from marshmallow import Schema
|
||||
|
||||
from superset.openapi.manager import normalize_app_root, resolver
|
||||
from superset.openapi.manager import (
|
||||
normalize_app_root,
|
||||
resolve_url_prefix,
|
||||
resolver,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -35,6 +40,29 @@ def test_normalize_app_root(app_root: str | None, expected: str) -> None:
|
||||
assert normalize_app_root(app_root) == expected
|
||||
|
||||
|
||||
def test_resolve_url_prefix_prefers_script_root() -> None:
|
||||
# A reverse-proxy prefix (X-Forwarded-Prefix / SCRIPT_NAME) must win over
|
||||
# APPLICATION_ROOT so FAB's script_root behavior isn't dropped.
|
||||
app = Flask(__name__)
|
||||
app.config["APPLICATION_ROOT"] = "/config-root"
|
||||
with app.test_request_context(environ_overrides={"SCRIPT_NAME": "/proxy-root"}):
|
||||
assert resolve_url_prefix() == "/proxy-root"
|
||||
|
||||
|
||||
def test_resolve_url_prefix_falls_back_to_app_root() -> None:
|
||||
app = Flask(__name__)
|
||||
app.config["APPLICATION_ROOT"] = "/config-root"
|
||||
with app.test_request_context():
|
||||
assert resolve_url_prefix() == "/config-root"
|
||||
|
||||
|
||||
def test_resolve_url_prefix_empty_when_neither_set() -> None:
|
||||
app = Flask(__name__)
|
||||
app.config["APPLICATION_ROOT"] = "/"
|
||||
with app.test_request_context():
|
||||
assert resolve_url_prefix() == ""
|
||||
|
||||
|
||||
def test_resolver_strips_schema_suffix() -> None:
|
||||
class FooSchema(Schema):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user