Skip to content

Commit

Permalink
Test(acl): Add a test case to verify identical name for group and use…
Browse files Browse the repository at this point in the history
…r work with acl (#8454)

## Description
Adds a test case for the fix implemented in
#7978.

For the test case we need to create a user and the group with the same
name. Dgraph stores ACL information in the predicate `dgraph.xid` which
is shared between group and user information. The test prevents a
regression in the case where the names of the group and user are
identical.

## Test
`TestQueriesWithUserAndGroupOfSameName`
  • Loading branch information
all-seeing-code authored Nov 29, 2022
1 parent 141944a commit 38f2829
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions ee/acl/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ func getGrootAndGuardiansUid(t *testing.T, dg *dgo.Dgraph) (string, string) {
}

const defaultTimeToSleep = 500 * time.Millisecond

const timeout = 5 * time.Second

const expireJwtSleep = 21 * time.Second

func testAuthorization(t *testing.T, dg *dgo.Dgraph) {
Expand Down Expand Up @@ -2270,6 +2273,60 @@ 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)
// Creates a user -- alice
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
}
}
`

dc := testutil.DgClientWithLogin(t, userid, userpassword, x.GalaxyNamespace)
testutil.PollTillPassOrTimeout(t, dc, query, `{"q":[{"name":"RandomGuy"},{"name":"RandomGuy2"}]}`, timeout)
}

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 38f2829

Please sign in to comment.