Skip to content

Commit

Permalink
Skip inserting assert_exists on required links inside access policies…
Browse files Browse the repository at this point in the history
… bodies (#4695)

When policies evaluation is suppressed, we don't need to worry about
required links being broken.

The fix was verified manually; the added test is to make sure this
didn't prevent the check from being added *later*, where it *is*
needed.
  • Loading branch information
msullivan committed Nov 18, 2022
1 parent f38977a commit 805f145
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion edb/edgeql/compiler/setgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,8 @@ def needs_rewrite_existence_assertion(
"""

return bool(
ptrcls.get_required(ctx.env.schema)
not ctx.suppress_rewrites
and ptrcls.get_required(ctx.env.schema)
and direction == PtrDir.Outbound
and (target := ptrcls.get_target(ctx.env.schema))
and ctx.env.type_rewrites.get((target, False))
Expand Down
35 changes: 34 additions & 1 deletion tests/test_edgeql_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ async def test_edgeql_policies_04(self):
])
)

async def test_edgeql_policies_05(self):
async def test_edgeql_policies_05a(self):
await self.con.execute('''
CREATE TYPE Tgt {
CREATE REQUIRED PROPERTY b -> bool;
Expand Down Expand Up @@ -308,6 +308,39 @@ async def test_edgeql_policies_05(self):
[],
)

async def test_edgeql_policies_05b(self):
await self.con.execute('''
CREATE TYPE Tgt {
CREATE REQUIRED PROPERTY b -> bool;
CREATE ACCESS POLICY redact
ALLOW SELECT USING (not global filter_owned);
CREATE ACCESS POLICY dml_always
ALLOW UPDATE, INSERT, DELETE;
};
CREATE TYPE Ptr {
CREATE REQUIRED LINK tgt -> Tgt;
CREATE PROPERTY tb := .tgt.b;
CREATE ACCESS POLICY redact
ALLOW SELECT USING (.tgt.b);
CREATE ACCESS POLICY dml_always
ALLOW UPDATE, INSERT, DELETE;
};
''')
await self.con.query('''
insert Ptr { tgt := (insert Tgt { b := True }) };
''')
await self.con.execute('''
set global filter_owned := True;
''')

async with self.assertRaisesRegexTx(
edgedb.CardinalityViolationError,
r"is hidden by access policy"):
await self.con.query('''
select Ptr { tgt }
''')

async def test_edgeql_policies_06(self):
await self.con.execute('''
CREATE TYPE Tgt {
Expand Down

0 comments on commit 805f145

Please sign in to comment.