diff --git a/tests/integration_tests/core_tests.py b/tests/integration_tests/core_tests.py index e93bbdc4e49d0..f036f18bf6aa3 100644 --- a/tests/integration_tests/core_tests.py +++ b/tests/integration_tests/core_tests.py @@ -757,36 +757,6 @@ def test_templated_sql_json(self): data = self.run_sql(sql, "fdaklj3ws") self.assertEqual(data["data"][0]["test"], "2") - @pytest.mark.usefixtures("load_birth_names_data") - def test_templated_sql_forbidden(self): - self.login(username="gamma"); - - data = self.run_sql( - """ - SELECT * FROM {{ table_name }} LIMIT 1; - """, - client_id="client_id_1", - database_name="examples", - template_params=json.dumps({"table_name": "birth_names"}), - raise_on_error=True - ) - assert data["errors"][0]["error_type"] == "GENERIC_BACKEND_ERROR" - - @pytest.mark.usefixtures("load_birth_names_data") - def test_templated_sql_success(self): - self.login(username="admin"); - - data = self.run_sql( - """ - SELECT * FROM {{ table_name }} LIMIT 1; - """, - client_id="client_id_1", - database_name="examples", - template_params=json.dumps({"table_name": "birth_names"}), - raise_on_error=True - ) - assert data["status"] == "success" - @mock.patch( "tests.integration_tests.superset_test_custom_template_processors.datetime" ) diff --git a/tests/integration_tests/sqllab_tests.py b/tests/integration_tests/sqllab_tests.py index 19e397e8f6961..aa15308e92be1 100644 --- a/tests/integration_tests/sqllab_tests.py +++ b/tests/integration_tests/sqllab_tests.py @@ -736,6 +736,38 @@ def test_sql_json_parameter_error(self): "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):