Skip to content

Commit

Permalink
fix(acl): filter out the results based on type Add a test case to ver…
Browse files Browse the repository at this point in the history
…ify the fix pushed in (#7978)
  • Loading branch information
all-seeing-code committed Nov 24, 2022
1 parent 409d30c commit 361d634
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions ee/acl/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,70 @@ func TestQueryUserInfo(t *testing.T) {
testutil.CompareJSON(t, `{"getGroup": null}`, string(gqlResp.Data))
}

func TestQueriesWithUserAndGroupOfSameName(t *testing.T) {
ctx, _ := context.WithTimeout(context.Background(), 100*time.Second)

dg, err := testutil.DgraphClientWithGroot(testutil.SockAddr)
require.NoError(t, err)

testutil.DropAll(t, dg)
resetUser(t)

txn := dg.NewTxn()
mutation := &api.Mutation{
SetNquads: []byte(`
_:a <name> "RandomGuy" .
_:a <age> "23" .
_:a <nickname> "RG" .
_:a <dgraph.type> "TypeName" .
_:b <name> "RandomGuy2" .
_:b <age> "25" .
_:b <nickname> "RG2" .
_:b <dgraph.type> "TypeName" .
`),
CommitNow: true,
}
_, err = txn.Mutate(ctx, mutation)
require.NoError(t, err)

token, err := testutil.HttpLogin(&testutil.LoginParams{
Endpoint: adminEndpoint,
UserID: "groot",
Passwd: "password",
Namespace: x.GalaxyNamespace,
})
require.NoError(t, err, "login failed")

createGroup(t, token, "alice")
addToGroup(t, token, userid, "alice")

// add rules to groups
addRulesToGroup(t, token, "alice", []rule{{Predicate: "name", Permission: Read.Code}})

query := `
{
q(func: has(name)) {
name
age
}
}
`

userClient, err := testutil.DgraphClient(testutil.SockAddr)
require.NoError(t, err)
time.Sleep(defaultTimeToSleep)

err = userClient.LoginIntoNamespace(ctx, userid, userpassword, x.GalaxyNamespace)
require.NoError(t, err)

time.Sleep(defaultTimeToSleep)

resp, err := userClient.NewTxn().Query(ctx, query)
require.NoError(t, err)
testutil.CompareJSON(t, `{"q":[{"name":"RandomGuy"},{"name":"RandomGuy2"}]}`, string(resp.Json))

}

func TestQueriesForNonGuardianUserWithoutGroup(t *testing.T) {
// Create a new user without any groups, queryGroup should return an empty result.
resetUser(t)
Expand Down

0 comments on commit 361d634

Please sign in to comment.