MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / TestAllowUIDAccess

Method TestAllowUIDAccess

acl/acl_test.go:2654–2710  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2652}
2653
2654func (asuite *AclTestSuite) TestAllowUIDAccess() {
2655 t := asuite.T()
2656 ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
2657 defer cancel()
2658
2659 gc, cleanup, err := asuite.dc.Client()
2660 require.NoError(t, err)
2661 defer cleanup()
2662 require.NoError(t, gc.LoginIntoNamespace(ctx, dgraphapi.DefaultUser,
2663 dgraphapi.DefaultPassword, x.RootNamespace))
2664
2665 hc, err := asuite.dc.HTTPClient()
2666 require.NoError(t, err)
2667 require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.RootNamespace))
2668
2669 require.NoError(t, gc.DropAll())
2670 op := api.Operation{Schema: `
2671 name : string @index(exact) .
2672 `}
2673 require.NoError(t, gc.Alter(ctx, &op))
2674
2675 resetUser(t, hc)
2676
2677 createdGroup, err := hc.CreateGroup(devGroup)
2678 require.NoError(t, err)
2679 require.Equal(t, devGroup, createdGroup)
2680 require.NoError(t, hc.AddUserToGroup(userid, devGroup))
2681
2682 require.NoError(t, asuite.dc.AssignUids(gc.Dgraph, 101))
2683 mu := &api.Mutation{SetNquads: []byte(`<100> <name> "100th User" .`), CommitNow: true}
2684 _, err = gc.Mutate(mu)
2685 require.NoError(t, err)
2686
2687 // give read access of <name> to alice
2688 require.NoError(t, hc.AddRulesToGroup(devGroup,
2689 []dgraphapi.AclRule{{Predicate: "name", Permission: Read.Code}}, true))
2690
2691 asuite.Upgrade()
2692
2693 userClient, cleanup, err := asuite.dc.Client()
2694 require.NoError(t, err)
2695 defer cleanup()
2696 time.Sleep(defaultTimeToSleep)
2697
2698 require.NoError(t, userClient.LoginIntoNamespace(ctx, userid, userpassword, x.RootNamespace))
2699
2700 uidQuery := `
2701 {
2702 me(func: uid(100)) {
2703 uid
2704 name
2705 }
2706 }`
2707 resp, err := userClient.Query(uidQuery)
2708 require.NoError(t, err)
2709 require.NoError(t, dgraphapi.CompareJSON(`{"me":[{"name":"100th User", "uid": "0x64"}]}`, string(resp.GetJson())))
2710}
2711

Callers

nothing calls this directly

Calls 15

UpgradeMethod · 0.95
CompareJSONFunction · 0.92
cleanupFunction · 0.85
resetUserFunction · 0.85
LoginIntoNamespaceMethod · 0.80
DropAllMethod · 0.80
AlterMethod · 0.80
CreateGroupMethod · 0.80
AddUserToGroupMethod · 0.80
AddRulesToGroupMethod · 0.80
ClientMethod · 0.65
HTTPClientMethod · 0.65

Tested by

no test coverage detected