chore: replace selenium user with fixed user (#31844)

This commit is contained in:
Ville Brofeldt
2025-01-22 12:46:06 -08:00
committed by GitHub
parent 1d6423e71f
commit 7482b20f7b
25 changed files with 304 additions and 215 deletions

View File

@@ -23,11 +23,11 @@ from typing import Any, Optional, Union
import pytest
from flask_appbuilder.security.sqla.models import User
from superset.tasks.exceptions import ExecutorNotFoundError
from superset.tasks.types import ExecutorType
from superset.tasks.exceptions import ExecutorNotFoundError, InvalidExecutorError
from superset.tasks.types import Executor, ExecutorType, FixedExecutor
SELENIUM_USER_ID = 1234
SELENIUM_USERNAME = "admin"
FIXED_USER_ID = 1234
FIXED_USERNAME = "admin"
def _get_users(
@@ -54,18 +54,18 @@ class ModelType(int, Enum):
@pytest.mark.parametrize(
"model_type,executor_types,model_config,current_user,expected_result",
"model_type,executors,model_config,current_user,expected_result",
[
(
ModelType.REPORT_SCHEDULE,
[ExecutorType.SELENIUM],
[FixedExecutor(FIXED_USERNAME)],
ModelConfig(
owners=[1, 2],
creator=3,
modifier=4,
),
None,
(ExecutorType.SELENIUM, SELENIUM_USER_ID),
(ExecutorType.FIXED_USER, FIXED_USER_ID),
),
(
ModelType.REPORT_SCHEDULE,
@@ -75,11 +75,11 @@ class ModelType(int, Enum):
ExecutorType.OWNER,
ExecutorType.MODIFIER,
ExecutorType.MODIFIER_OWNER,
ExecutorType.SELENIUM,
FixedExecutor(FIXED_USERNAME),
],
ModelConfig(owners=[]),
None,
(ExecutorType.SELENIUM, SELENIUM_USER_ID),
(ExecutorType.FIXED_USER, FIXED_USER_ID),
),
(
ModelType.REPORT_SCHEDULE,
@@ -89,7 +89,7 @@ class ModelType(int, Enum):
ExecutorType.OWNER,
ExecutorType.MODIFIER,
ExecutorType.MODIFIER_OWNER,
ExecutorType.SELENIUM,
FixedExecutor(FIXED_USERNAME),
],
ModelConfig(owners=[], modifier=1),
None,
@@ -103,7 +103,7 @@ class ModelType(int, Enum):
ExecutorType.OWNER,
ExecutorType.MODIFIER,
ExecutorType.MODIFIER_OWNER,
ExecutorType.SELENIUM,
FixedExecutor(FIXED_USERNAME),
],
ModelConfig(owners=[2], modifier=1),
None,
@@ -117,7 +117,7 @@ class ModelType(int, Enum):
ExecutorType.OWNER,
ExecutorType.MODIFIER,
ExecutorType.MODIFIER_OWNER,
ExecutorType.SELENIUM,
FixedExecutor(FIXED_USERNAME),
],
ModelConfig(owners=[2], creator=3, modifier=1),
None,
@@ -198,11 +198,11 @@ class ModelType(int, Enum):
(
ModelType.DASHBOARD,
[
ExecutorType.SELENIUM,
FixedExecutor(FIXED_USERNAME),
],
ModelConfig(owners=[1], creator=2, modifier=3),
4,
(ExecutorType.SELENIUM, SELENIUM_USER_ID),
(ExecutorType.FIXED_USER, FIXED_USER_ID),
),
(
ModelType.DASHBOARD,
@@ -219,11 +219,11 @@ class ModelType(int, Enum):
ExecutorType.CREATOR_OWNER,
ExecutorType.MODIFIER_OWNER,
ExecutorType.CURRENT_USER,
ExecutorType.SELENIUM,
FixedExecutor(FIXED_USERNAME),
],
ModelConfig(owners=[1], creator=2, modifier=3),
None,
(ExecutorType.SELENIUM, SELENIUM_USER_ID),
(ExecutorType.FIXED_USER, FIXED_USER_ID),
),
(
ModelType.CHART,
@@ -237,11 +237,11 @@ class ModelType(int, Enum):
(
ModelType.CHART,
[
ExecutorType.SELENIUM,
FixedExecutor(FIXED_USERNAME),
],
ModelConfig(owners=[1], creator=2, modifier=3),
4,
(ExecutorType.SELENIUM, SELENIUM_USER_ID),
(ExecutorType.FIXED_USER, FIXED_USER_ID),
),
(
ModelType.CHART,
@@ -252,26 +252,35 @@ class ModelType(int, Enum):
None,
ExecutorNotFoundError(),
),
(
ModelType.CHART,
[
ExecutorType.FIXED_USER,
],
ModelConfig(owners=[]),
None,
InvalidExecutorError(),
),
(
ModelType.CHART,
[
ExecutorType.CREATOR_OWNER,
ExecutorType.MODIFIER_OWNER,
ExecutorType.CURRENT_USER,
ExecutorType.SELENIUM,
FixedExecutor(FIXED_USERNAME),
],
ModelConfig(owners=[1], creator=2, modifier=3),
None,
(ExecutorType.SELENIUM, SELENIUM_USER_ID),
(ExecutorType.FIXED_USER, FIXED_USER_ID),
),
],
)
def test_get_executor(
model_type: ModelType,
executor_types: list[ExecutorType],
executors: list[Executor],
model_config: ModelConfig,
current_user: Optional[int],
expected_result: tuple[int, ExecutorNotFoundError],
expected_result: tuple[ExecutorType, int] | Exception,
) -> None:
from superset.models.dashboard import Dashboard
from superset.models.slice import Slice
@@ -308,14 +317,14 @@ def test_get_executor(
cm = nullcontext()
expected_executor_type = expected_result[0]
expected_executor = (
SELENIUM_USERNAME
if expected_executor_type == ExecutorType.SELENIUM
FIXED_USERNAME
if expected_executor_type == ExecutorType.FIXED_USER
else str(expected_result[1])
)
with cm:
executor_type, executor = get_executor(
executor_types=executor_types,
executors=executors,
model=obj,
current_user=str(current_user) if current_user else None,
)

View File

@@ -24,8 +24,8 @@ import pytest
from flask_appbuilder.security.sqla.models import User
from superset.connectors.sqla.models import BaseDatasource, SqlaTable
from superset.tasks.exceptions import ExecutorNotFoundError
from superset.tasks.types import ExecutorType
from superset.tasks.exceptions import InvalidExecutorError
from superset.tasks.types import Executor, ExecutorType, FixedExecutor
from superset.utils.core import DatasourceType, override_user
if TYPE_CHECKING:
@@ -81,7 +81,7 @@ def prepare_datasource_mock(
[
(
None,
[ExecutorType.SELENIUM],
[FixedExecutor("admin")],
False,
False,
[],
@@ -214,13 +214,21 @@ def prepare_datasource_mock(
False,
False,
[],
ExecutorNotFoundError(),
None,
),
(
None,
[ExecutorType.FIXED_USER],
False,
False,
[],
InvalidExecutorError(),
),
],
)
def test_dashboard_digest(
dashboard_overrides: dict[str, Any] | None,
execute_as: list[ExecutorType],
execute_as: list[Executor],
has_current_user: bool,
use_custom_digest: bool,
rls_datasources: list[dict[str, Any]],
@@ -255,7 +263,7 @@ def test_dashboard_digest(
patch.dict(
app.config,
{
"THUMBNAIL_EXECUTE_AS": execute_as,
"THUMBNAIL_EXECUTORS": execute_as,
"THUMBNAIL_DASHBOARD_DIGEST_FUNC": func,
},
),
@@ -282,7 +290,7 @@ def test_dashboard_digest(
[
(
None,
[ExecutorType.SELENIUM],
[FixedExecutor("admin")],
False,
False,
None,
@@ -345,13 +353,21 @@ def test_dashboard_digest(
False,
False,
None,
ExecutorNotFoundError(),
None,
),
(
None,
[ExecutorType.FIXED_USER],
False,
False,
None,
InvalidExecutorError(),
),
],
)
def test_chart_digest(
chart_overrides: dict[str, Any] | None,
execute_as: list[ExecutorType],
execute_as: list[Executor],
has_current_user: bool,
use_custom_digest: bool,
rls_datasource: dict[str, Any] | None,
@@ -383,7 +399,7 @@ def test_chart_digest(
patch.dict(
app.config,
{
"THUMBNAIL_EXECUTE_AS": execute_as,
"THUMBNAIL_EXECUTORS": execute_as,
"THUMBNAIL_CHART_DIGEST_FUNC": func,
},
),