mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix: Validate jinja rendered query (#22851)
This commit is contained in:
@@ -736,6 +736,38 @@ class TestSqlLab(SupersetTestCase):
|
||||
"undefined_parameters": ["stat"],
|
||||
}
|
||||
|
||||
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
|
||||
@mock.patch.dict(
|
||||
"superset.extensions.feature_flag_manager._feature_flags",
|
||||
{"ENABLE_TEMPLATE_PROCESSING": True},
|
||||
clear=True,
|
||||
)
|
||||
def test_sql_json_parameter_authorized(self):
|
||||
self.login("admin")
|
||||
|
||||
data = self.run_sql(
|
||||
"SELECT name FROM {{ table }} LIMIT 10",
|
||||
"3",
|
||||
template_params=json.dumps({"table": "birth_names"}),
|
||||
)
|
||||
assert data["status"] == "success"
|
||||
|
||||
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
|
||||
@mock.patch.dict(
|
||||
"superset.extensions.feature_flag_manager._feature_flags",
|
||||
{"ENABLE_TEMPLATE_PROCESSING": True},
|
||||
clear=True,
|
||||
)
|
||||
def test_sql_json_parameter_forbidden(self):
|
||||
self.login("gamma")
|
||||
|
||||
data = self.run_sql(
|
||||
"SELECT name FROM {{ table }} LIMIT 10",
|
||||
"4",
|
||||
template_params=json.dumps({"table": "birth_names"}),
|
||||
)
|
||||
assert data["errors"][0]["error_type"] == "GENERIC_BACKEND_ERROR"
|
||||
|
||||
@mock.patch("superset.sql_lab.get_query")
|
||||
@mock.patch("superset.sql_lab.execute_sql_statement")
|
||||
def test_execute_sql_statements(self, mock_execute_sql_statement, mock_get_query):
|
||||
|
||||
Reference in New Issue
Block a user