sadpandajoe commented on code in PR #44347:
URL: https://github.com/apache/superset/pull/44347#discussion_r4046678492


##########
tests/unit_tests/commands/chart/export_test.py:
##########
@@ -0,0 +1,177 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Unit tests for ExportChartsCommand."""
+
+from __future__ import annotations
+
+from collections.abc import Generator
+
+import pytest
+import yaml
+from pytest_mock import MockerFixture
+from sqlalchemy.orm.session import Session
+
+from superset import db, security_manager
+from superset.commands.chart.export import ExportChartsCommand
+from superset.commands.chart.importers.v1 import ImportChartsCommand
+from superset.connectors.sqla.models import Database, SqlaTable
+from superset.daos.dataset import DatasetDAO
+from superset.models.slice import Slice
+
+
[email protected]
+def chart_on_dataset(session: Session) -> Generator[Slice, None, None]:
+    """A chart backed by a dataset, both alive."""
+    engine = session.get_bind()
+    SqlaTable.metadata.create_all(engine)  # pylint: disable=no-member
+
+    dataset = SqlaTable(
+        table_name="my_table",
+        metrics=[],
+        main_dttm_col=None,
+        database=Database(database_name="my_database", 
sqlalchemy_uri="sqlite://"),
+    )
+    session.add(dataset)
+    session.flush()
+
+    chart = Slice(
+        slice_name="my_chart",
+        viz_type="table",
+        datasource_id=dataset.id,
+        datasource_type="table",
+        datasource_name="my_table",
+        params="{}",
+    )
+    session.add(chart)
+    session.flush()
+
+    yield chart
+    session.rollback()
+
+
[email protected]
+def permissive_security(mocker: MockerFixture) -> None:
+    """Grant every read/write check the export and import paths consult."""
+    mocker.patch.object(
+        security_manager, "can_access_all_datasources", return_value=True

Review Comment:
   All three tests set `can_access_all_datasources=True`, so the permission 
filter is a no-op and a regression in the new visibility-bypass path could 
export an unauthorized dataset without failing them. Could we add a 
chart-export case where the caller can access the chart but is neither a 
dataset editor nor granted dataset access, then soft-delete the dataset and 
assert that the bundle contains neither its `datasets/` YAML nor `dataset_uuid`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to