gabotorresruiz commented on code in PR #45552:
URL: https://github.com/apache/superset/pull/45552#discussion_r4354775887


##########
tests/integration_tests/security/public_role_tests.py:
##########
@@ -0,0 +1,74 @@
+# 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.
+from contextlib import nullcontext
+
+import pytest
+from flask.ctx import AppContext
+from flask_appbuilder.security.sqla.models import PermissionView
+
+from superset.extensions import db, security_manager
+from tests.integration_tests.fixtures.public_role import _public_role_like
+from tests.integration_tests.test_app import app
+
+
[email protected]("role_name", ["Gamma", "TestRole", "Public"])
[email protected]("test_raises", [False, True])
+def test_public_role_restored_after_commits(
+    app_context: AppContext, role_name: str, test_raises: bool
+) -> None:
+    """Restore custom Public grants after session replacement and test 
failures."""
+    original_value = app.config["PUBLIC_ROLE_LIKE"]
+    original_permission_ids = {
+        permission.id for permission in 
security_manager.get_public_role().permissions
+    }
+    try:
+        # Use a custom set that cannot be restored by re-syncing a built-in 
role.
+        app.config["PUBLIC_ROLE_LIKE"] = None
+        permissions = [
+            security_manager.find_permission_view_menu("can_read", 
"Dashboard"),
+            security_manager.find_permission_view_menu("menu_access", 
"Security"),
+        ]
+        expected_permission_ids = {permission.id for permission in permissions}

Review Comment:
   Confirmed fixed. Creating your own uniquely suffixed permission and 
view-menu rows drops the dependency on `menu_access` on `Security` entirely, so 
the migration tests can keep stripping it. 
`migrations/b4a3f2e1d0c9_fix_security_view_menu_case__tests.py` followed by 
this file now gives `9 passed` where it gave `6 failed, 3 passed`, and the six 
cases still pin the fixture: swapping `_public_role_like`'s restore back for a 
wipe fails all six.
   
   Not a blocker and not yours to fix, but worth saying out loud since this is 
the second shared fixture you have had to repair on a feature PR: the class is 
still live. `_clean_security` deletes the `Security` view menu and its 
permission rows on both setup and teardown and never puts them back, and 
`security_tests.py` depends on that menu existing. That same pairing 
(`migrations/b4a3f2e1d0c9...` then `security_tests.py`) gives `10 failed, 80 
passed, 2 errors`, while `security_tests.py` alone is `88 passed`. The real 
collection order happens to be benign so CI stays green, which is exactly why 
it keeps biting whoever touches these fixtures next. Probably its own PR rather 
than more scope here.



-- 
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