Skip to content
Merged
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
48 changes: 34 additions & 14 deletions ee/acl/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -1725,6 +1727,7 @@ func TestAllPredsPermission(t *testing.T) {
_:a <age> "23" .
_:a <nickname> "RG" .
_:a <dgraph.type> "TypeName" .
_:a <connects> _:b .
_:b <name> "RandomGuy2" .
_:b <age> "25" .
_:b <nickname> "RG2" .
Expand All @@ -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
}{
{
`
Expand All @@ -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
}
}
}
}
`,
Expand All @@ -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}]}]}]}`,
},
}

Expand Down Expand Up @@ -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))
})
}

Expand All @@ -1828,6 +1847,7 @@ func TestAllPredsPermission(t *testing.T) {
SetNquads: []byte(`
_:a <name> "RandomGuy" .
_:a <age> "23" .
_:a <connects> _:b .
_:a <dgraph.type> "TypeName" .
`),
CommitNow: true,
Expand Down