mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
chore: enforce more ruff rules (#31447)
Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
This commit is contained in:
committed by
GitHub
parent
9da65d6bfd
commit
e51b95ffa8
@@ -30,37 +30,37 @@ from superset.security.analytics_db_safety import check_sqlalchemy_uri
|
||||
(
|
||||
"sqlite:///home/superset/bad.db",
|
||||
True,
|
||||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.",
|
||||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.", # noqa: E501
|
||||
),
|
||||
(
|
||||
"sqlite+pysqlite:///home/superset/bad.db",
|
||||
True,
|
||||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.",
|
||||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.", # noqa: E501
|
||||
),
|
||||
(
|
||||
"sqlite+aiosqlite:///home/superset/bad.db",
|
||||
True,
|
||||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.",
|
||||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.", # noqa: E501
|
||||
),
|
||||
(
|
||||
"sqlite+pysqlcipher:///home/superset/bad.db",
|
||||
True,
|
||||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.",
|
||||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.", # noqa: E501
|
||||
),
|
||||
(
|
||||
"sqlite+:///home/superset/bad.db",
|
||||
True,
|
||||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.",
|
||||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.", # noqa: E501
|
||||
),
|
||||
(
|
||||
"sqlite+new+driver:///home/superset/bad.db",
|
||||
True,
|
||||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.",
|
||||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.", # noqa: E501
|
||||
),
|
||||
(
|
||||
"sqlite+new+:///home/superset/bad.db",
|
||||
True,
|
||||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.",
|
||||
"SQLiteDialect_pysqlite cannot be used as a data source for security reasons.", # noqa: E501
|
||||
),
|
||||
(
|
||||
"shillelagh:///home/superset/bad.db",
|
||||
@@ -84,7 +84,7 @@ def test_check_sqlalchemy_uri(
|
||||
sqlalchemy_uri: str, error: bool, error_message: Optional[str]
|
||||
):
|
||||
if error:
|
||||
with pytest.raises(SupersetSecurityException) as excinfo:
|
||||
with pytest.raises(SupersetSecurityException) as excinfo: # noqa: PT012
|
||||
check_sqlalchemy_uri(make_url(sqlalchemy_uri))
|
||||
assert str(excinfo.value) == error_message
|
||||
else:
|
||||
|
||||
@@ -190,7 +190,7 @@ class TestGuestUserDashboardAccess(SupersetTestCase):
|
||||
def test_raise_for_access_dashboard_as_unauthorized_guest(self):
|
||||
g.user = self.unauthorized_guest
|
||||
|
||||
with self.assertRaises(SupersetSecurityException):
|
||||
with self.assertRaises(SupersetSecurityException): # noqa: PT027
|
||||
security_manager.raise_for_access(dashboard=self.dash)
|
||||
|
||||
def test_raise_for_access_dashboard_as_guest_no_rbac(self):
|
||||
@@ -214,7 +214,7 @@ class TestGuestUserDashboardAccess(SupersetTestCase):
|
||||
db.session.add(dash)
|
||||
db.session.commit()
|
||||
|
||||
with self.assertRaises(SupersetSecurityException):
|
||||
with self.assertRaises(SupersetSecurityException): # noqa: PT027
|
||||
security_manager.raise_for_access(dashboard=dash)
|
||||
|
||||
db.session.delete(dash)
|
||||
@@ -345,7 +345,7 @@ class TestGuestUserDatasourceAccess(SupersetTestCase):
|
||||
def test_raise_for_access__no_dashboard_in_form_data(self):
|
||||
g.user = self.authorized_guest
|
||||
for kwarg in ["viz", "query_context"]:
|
||||
with self.assertRaises(SupersetSecurityException):
|
||||
with self.assertRaises(SupersetSecurityException): # noqa: PT027
|
||||
security_manager.raise_for_access(
|
||||
**{
|
||||
kwarg: Mock(
|
||||
@@ -360,7 +360,7 @@ class TestGuestUserDatasourceAccess(SupersetTestCase):
|
||||
def test_raise_for_access__no_chart_in_form_data(self):
|
||||
g.user = self.authorized_guest
|
||||
for kwarg in ["viz", "query_context"]:
|
||||
with self.assertRaises(SupersetSecurityException):
|
||||
with self.assertRaises(SupersetSecurityException): # noqa: PT027
|
||||
security_manager.raise_for_access(
|
||||
**{
|
||||
kwarg: Mock(
|
||||
@@ -375,7 +375,7 @@ class TestGuestUserDatasourceAccess(SupersetTestCase):
|
||||
def test_raise_for_access__chart_not_on_dashboard(self):
|
||||
g.user = self.authorized_guest
|
||||
for kwarg in ["viz", "query_context"]:
|
||||
with self.assertRaises(SupersetSecurityException):
|
||||
with self.assertRaises(SupersetSecurityException): # noqa: PT027
|
||||
security_manager.raise_for_access(
|
||||
**{
|
||||
kwarg: Mock(
|
||||
@@ -391,7 +391,7 @@ class TestGuestUserDatasourceAccess(SupersetTestCase):
|
||||
def test_raise_for_access__chart_doesnt_belong_to_datasource(self):
|
||||
g.user = self.authorized_guest
|
||||
for kwarg in ["viz", "query_context"]:
|
||||
with self.assertRaises(SupersetSecurityException):
|
||||
with self.assertRaises(SupersetSecurityException): # noqa: PT027
|
||||
security_manager.raise_for_access(
|
||||
**{
|
||||
kwarg: Mock(
|
||||
@@ -407,7 +407,7 @@ class TestGuestUserDatasourceAccess(SupersetTestCase):
|
||||
def test_raise_for_access__native_filter_no_id_in_form_data(self):
|
||||
g.user = self.authorized_guest
|
||||
for kwarg in ["viz", "query_context"]:
|
||||
with self.assertRaises(SupersetSecurityException):
|
||||
with self.assertRaises(SupersetSecurityException): # noqa: PT027
|
||||
security_manager.raise_for_access(
|
||||
**{
|
||||
kwarg: Mock(
|
||||
@@ -427,7 +427,7 @@ class TestGuestUserDatasourceAccess(SupersetTestCase):
|
||||
def test_raise_for_access__native_filter_datasource_not_associated(self):
|
||||
g.user = self.authorized_guest
|
||||
for kwarg in ["viz", "query_context"]:
|
||||
with self.assertRaises(SupersetSecurityException):
|
||||
with self.assertRaises(SupersetSecurityException): # noqa: PT027
|
||||
security_manager.raise_for_access(
|
||||
**{
|
||||
kwarg: Mock(
|
||||
@@ -452,7 +452,7 @@ class TestGuestUserDatasourceAccess(SupersetTestCase):
|
||||
def test_raise_for_access__embedded_feature_flag_off(self):
|
||||
g.user = self.authorized_guest
|
||||
for kwarg in ["viz", "query_context"]:
|
||||
with self.assertRaises(SupersetSecurityException):
|
||||
with self.assertRaises(SupersetSecurityException): # noqa: PT027
|
||||
security_manager.raise_for_access(
|
||||
**{
|
||||
kwarg: Mock(
|
||||
@@ -468,7 +468,7 @@ class TestGuestUserDatasourceAccess(SupersetTestCase):
|
||||
def test_raise_for_access__unauthorized_guest_user(self):
|
||||
g.user = self.unauthorized_guest
|
||||
for kwarg in ["viz", "query_context"]:
|
||||
with self.assertRaises(SupersetSecurityException):
|
||||
with self.assertRaises(SupersetSecurityException): # noqa: PT027
|
||||
security_manager.raise_for_access(
|
||||
**{
|
||||
kwarg: Mock(
|
||||
|
||||
@@ -40,7 +40,7 @@ logger = logging.getLogger(__name__)
|
||||
def create_old_role(pvm_map: PvmMigrationMapType, external_pvms):
|
||||
with app.app_context():
|
||||
pvms = []
|
||||
for old_pvm, new_pvms in pvm_map.items():
|
||||
for old_pvm, new_pvms in pvm_map.items(): # noqa: B007
|
||||
pvms.append(
|
||||
security_manager.add_permission_view_menu(
|
||||
old_pvm.permission, old_pvm.view
|
||||
|
||||
@@ -56,7 +56,7 @@ class TestRowLevelSecurity(SupersetTestCase):
|
||||
"""
|
||||
|
||||
rls_entry = None
|
||||
query_obj: dict[str, Any] = dict(
|
||||
query_obj: dict[str, Any] = dict( # noqa: C408
|
||||
groupby=[],
|
||||
metrics=None,
|
||||
filter=[],
|
||||
@@ -153,7 +153,7 @@ class TestRowLevelSecurity(SupersetTestCase):
|
||||
db.session.delete(self.get_user("NoRlsRoleUser"))
|
||||
db.session.commit()
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def create_dataset(self):
|
||||
with self.create_app().app_context():
|
||||
dataset = SqlaTable(database_id=1, schema=None, table_name="table1")
|
||||
@@ -268,7 +268,7 @@ class TestRowLevelSecurity(SupersetTestCase):
|
||||
# establish that the filters are grouped together correctly with
|
||||
# ANDs, ORs and parens in the correct place
|
||||
assert (
|
||||
"WHERE ((name like 'A%' or name like 'B%') OR (name like 'Q%')) AND (gender = 'boy');"
|
||||
"WHERE ((name like 'A%' or name like 'B%') OR (name like 'Q%')) AND (gender = 'boy');" # noqa: E501
|
||||
in sql
|
||||
)
|
||||
|
||||
@@ -622,7 +622,7 @@ RLS_GENDER_REGEX = re.compile(r"AND \([\s\n]*gender = 'girl'[\s\n]*\)")
|
||||
EMBEDDED_SUPERSET=True,
|
||||
)
|
||||
class GuestTokenRowLevelSecurityTests(SupersetTestCase):
|
||||
query_obj: dict[str, Any] = dict(
|
||||
query_obj: dict[str, Any] = dict( # noqa: C408
|
||||
groupby=[],
|
||||
metrics=None,
|
||||
filter=[],
|
||||
|
||||
Reference in New Issue
Block a user