From 1fbe34e1208a23c56fcbd0e8d569e4be0eb78c6d Mon Sep 17 00:00:00 2001 From: Daniel Mai Date: Mon, 15 Nov 2021 11:45:19 -0800 Subject: [PATCH 1/4] test(acl): Add connects edge. --- ee/acl/acl_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ee/acl/acl_test.go b/ee/acl/acl_test.go index 2ef410bad93..dff2dbebc50 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" . @@ -1742,12 +1745,16 @@ func TestAllPredsPermission(t *testing.T) { q2(func: eq(val(v), "RandomGuy")) { val(v) val(a) + 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}]}]}`, string(resp.GetJson())) // All test cases From d66aa619a500b618f9e7d4cf2a9134e083052bd5 Mon Sep 17 00:00:00 2001 From: Daniel Mai Date: Mon, 15 Nov 2021 13:22:44 -0800 Subject: [PATCH 2/4] test(acl): Test reverse edge access with dgraph.all. --- ee/acl/acl_test.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/ee/acl/acl_test.go b/ee/acl/acl_test.go index dff2dbebc50..d15a4279c00 100644 --- a/ee/acl/acl_test.go +++ b/ee/acl/acl_test.go @@ -1748,24 +1748,28 @@ func TestAllPredsPermission(t *testing.T) { 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,"connects":[{"name":"RandomGuy2","age":25}]}]}`, + 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 }{ { ` @@ -1786,8 +1790,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 name, age, connects, and ~connects", + `{"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}]}]}]}`, }, } @@ -1822,11 +1826,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)) }) } @@ -1835,6 +1839,7 @@ func TestAllPredsPermission(t *testing.T) { SetNquads: []byte(` _:a "RandomGuy" . _:a "23" . + _:a _:b . _:a "TypeName" . `), CommitNow: true, From b8640685c6810860a6909b2cc4e58027b7b76941 Mon Sep 17 00:00:00 2001 From: Daniel Mai Date: Mon, 15 Nov 2021 13:38:53 -0800 Subject: [PATCH 3/4] test(acl): fix query. --- ee/acl/acl_test.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/ee/acl/acl_test.go b/ee/acl/acl_test.go index d15a4279c00..46deac7680b 100644 --- a/ee/acl/acl_test.go +++ b/ee/acl/acl_test.go @@ -1727,7 +1727,7 @@ func TestAllPredsPermission(t *testing.T) { _:a "23" . _:a "RG" . _:a "TypeName" . - _:a _:b . + _:a _:b . _:b "RandomGuy2" . _:b "25" . _:b "RG2" . @@ -1741,18 +1741,18 @@ 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 - } - } + connects { + name + age + ~connects { + name + age + } + } }}` // Test that groot has access to all the predicates @@ -1781,6 +1781,14 @@ func TestAllPredsPermission(t *testing.T) { q2(func: eq(val(n), "RandomGuy")) { val(n) val(a) + connects { + name + age + ~connects { + name + age + } + } } } `, @@ -1790,7 +1798,7 @@ func TestAllPredsPermission(t *testing.T) { `alice has access to name`, `{"q1":[{"name":"RandomGuy"},{"name":"RandomGuy2"}],"q2":[{"val(n)":"RandomGuy"}]}`, - "alice has access to name, age, connects, and ~connects", + "alice has access to all predicates", `{"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}]}]}]}`, }, } From ee8e8d8ebb96a88ab76915bdd95f06de865d2bbd Mon Sep 17 00:00:00 2001 From: Daniel Mai Date: Mon, 15 Nov 2021 13:49:56 -0800 Subject: [PATCH 4/4] test(acl): Fix typo in query response. --- ee/acl/acl_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ee/acl/acl_test.go b/ee/acl/acl_test.go index 46deac7680b..93263f2ace2 100644 --- a/ee/acl/acl_test.go +++ b/ee/acl/acl_test.go @@ -1799,7 +1799,7 @@ func TestAllPredsPermission(t *testing.T) { `{"q1":[{"name":"RandomGuy"},{"name":"RandomGuy2"}],"q2":[{"val(n)":"RandomGuy"}]}`, "alice has access to all predicates", - `{"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}]}]}]}`, + `{"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}]}]}]}`, }, }