Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[copy] fix: Row Level Security get_rls_filters func SELECT statement #9541

Merged
merged 2 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion superset/security/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ def get_rls_filters(self, table: "BaseDatasource"):
.subquery()
)
filter_roles = (
db.session.query(RLSFilterRoles.c.id)
db.session.query(RLSFilterRoles.c.rls_filter_id)
.filter(RLSFilterRoles.c.role_id.in_(user_roles))
.subquery()
)
Expand Down
9 changes: 5 additions & 4 deletions tests/security_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,10 +833,11 @@ def setUp(self):
self.rls_entry.table = (
session.query(SqlaTable).filter_by(table_name="birth_names").first()
)
self.rls_entry.clause = "gender = 'male'"
self.rls_entry.clause = "gender = 'boy'"
self.rls_entry.roles.append(
security_manager.find_role("Gamma")
) # db.session.query(Role).filter_by(name="Gamma").first())
self.rls_entry.roles.append(security_manager.find_role("Alpha"))
db.session.add(self.rls_entry)

db.session.commit()
Expand All @@ -849,7 +850,7 @@ def tearDown(self):
# Do another test to make sure it doesn't alter another query
def test_rls_filter_alters_query(self):
g.user = self.get_user(
username="gamma"
username="alpha"
) # self.login() doesn't actually set the user
tbl = self.get_table_by_name("birth_names")
query_obj = dict(
Expand All @@ -864,7 +865,7 @@ def test_rls_filter_alters_query(self):
extras={},
)
sql = tbl.get_query_str(query_obj)
self.assertIn("gender = 'male'", sql)
self.assertIn("gender = 'boy'", sql)

def test_rls_filter_doesnt_alter_query(self):
g.user = self.get_user(
Expand All @@ -883,4 +884,4 @@ def test_rls_filter_doesnt_alter_query(self):
extras={},
)
sql = tbl.get_query_str(query_obj)
self.assertNotIn("gender = 'male'", sql)
self.assertNotIn("gender = 'boy'", sql)