diff --git a/ee/acl/acl_test.go b/ee/acl/acl_test.go index 2ef410bad93..93263f2ace2 100644 --- a/ee/acl/acl_test.go +++ b/ee/acl/acl_test.go @@ -1697,10 +1697,12 @@ func TestAllPredsPermission(t *testing.T) { name : string @index(exact) . nickname : string @index(exact) . age : int . + connects : [uid] @reverse . type TypeName { name: string nickname: string age: int + connects: [uid] } `} require.NoError(t, dg.Alter(ctx, &op)) @@ -1725,6 +1727,7 @@ func TestAllPredsPermission(t *testing.T) { _:a "23" . _:a "RG" . _:a "TypeName" . + _:a _:b . _:b "RandomGuy2" . _:b "25" . _:b "RG2" . @@ -1738,27 +1741,35 @@ func TestAllPredsPermission(t *testing.T) { query := `{q1(func: has(name)){ v as name a as age - } - q2(func: eq(val(v), "RandomGuy")) { + } + q2(func: eq(val(v), "RandomGuy")) { val(v) val(a) + connects { + name + age + ~connects { + name + age + } + } }}` // Test that groot has access to all the predicates resp, err := dg.NewReadOnlyTxn().Query(ctx, query) require.NoError(t, err, "Error while querying data") - testutil.CompareJSON(t, `{"q1":[{"name":"RandomGuy","age":23},{"name":"RandomGuy2","age":25}],"q2":[{"val(v)":"RandomGuy","val(a)":23}]}`, + testutil.CompareJSON(t, `{"q1":[{"name":"RandomGuy","age":23},{"name":"RandomGuy2","age":25}],"q2":[{"val(v)":"RandomGuy","val(a)":23,"connects":[{"name":"RandomGuy2","age":25,"~connects":[{"name":"RandomGuy","age":23}]}]}]}`, string(resp.GetJson())) // All test cases tests := []struct { - input string - descriptionNoPerm string - outputNoPerm string - descriptionNamePerm string - outputNamePerm string - descriptionNameAgePerm string - outputNameAgePerm string + input string + descriptionNoPerm string + outputNoPerm string + descriptionNamePerm string + outputNamePerm string + descriptionAllPerm string + outputAllPerm string }{ { ` @@ -1770,6 +1781,14 @@ func TestAllPredsPermission(t *testing.T) { q2(func: eq(val(n), "RandomGuy")) { val(n) val(a) + connects { + name + age + ~connects { + name + age + } + } } } `, @@ -1779,8 +1798,8 @@ func TestAllPredsPermission(t *testing.T) { `alice has access to name`, `{"q1":[{"name":"RandomGuy"},{"name":"RandomGuy2"}],"q2":[{"val(n)":"RandomGuy"}]}`, - "alice has access to name and age", - `{"q1":[{"name":"RandomGuy","age":23},{"name":"RandomGuy2","age":25}],"q2":[{"val(n)":"RandomGuy","val(a)":23}]}`, + "alice has access to all predicates", + `{"q1":[{"name":"RandomGuy","age":23},{"name":"RandomGuy2","age":25}],"q2":[{"val(n)":"RandomGuy","val(a)":23,"connects":[{"name":"RandomGuy2","age":25,"~connects":[{"name":"RandomGuy","age":23}]}]}]}`, }, } @@ -1815,11 +1834,11 @@ func TestAllPredsPermission(t *testing.T) { time.Sleep(defaultTimeToSleep) for _, tc := range tests { - desc := tc.descriptionNameAgePerm + desc := tc.descriptionAllPerm t.Run(desc, func(t *testing.T) { resp, err := userClient.NewTxn().Query(ctx, tc.input) require.NoError(t, err) - testutil.CompareJSON(t, tc.outputNameAgePerm, string(resp.Json)) + testutil.CompareJSON(t, tc.outputAllPerm, string(resp.Json)) }) } @@ -1828,6 +1847,7 @@ func TestAllPredsPermission(t *testing.T) { SetNquads: []byte(` _:a "RandomGuy" . _:a "23" . + _:a _:b . _:a "TypeName" . `), CommitNow: true,