@@ -29,6 +29,58 @@ var userResourceType = &v2.ResourceType{
2929 Annotations : annotations .New (& v2.SkipEntitlementsAndGrants {}),
3030}
3131
32+ func TestExpandGrants (t * testing.T ) {
33+ ctx , cancel := context .WithCancel (context .Background ())
34+ defer cancel ()
35+
36+ // 2500 * 4 = 10K - used to cause an infinite loop on pagition
37+ usersPerLayer := 2500
38+ groupCount := 5
39+
40+ mc := newMockConnector ()
41+
42+ mc .rtDB = append (mc .rtDB , groupResourceType , userResourceType )
43+ type asdf struct {
44+ r * v2.Resource
45+ e * v2.Entitlement
46+ }
47+ groups := make ([]* asdf , 0 )
48+ for i := 0 ; i < groupCount ; i ++ {
49+ groupId := "group_" + strconv .Itoa (i )
50+ group , groupEnt , err := mc .AddGroup (ctx , groupId )
51+ for _ , g := range groups {
52+ _ = mc .AddGroupMember (ctx , g .r , group , groupEnt )
53+ }
54+ groups = append (groups , & asdf {
55+ r : group ,
56+ e : groupEnt ,
57+ })
58+ require .NoError (t , err )
59+
60+ for j := 0 ; j < usersPerLayer ; j ++ {
61+ pid := fmt .Sprintf ("user_%d_%d_%d" , i , usersPerLayer , j )
62+ principal , err := mc .AddUser (ctx , pid )
63+ require .NoError (t , err )
64+
65+ // This isn't needed because grant expansion will create this grant
66+ // _ = mc.AddGroupMember(ctx, group, principal)
67+ _ = mc .AddGroupMember (ctx , group , principal )
68+ }
69+ }
70+
71+ tempDir , err := os .MkdirTemp ("" , "baton-benchmark-expand-grants" )
72+ require .NoError (t , err )
73+ defer os .RemoveAll (tempDir )
74+ c1zpath := filepath .Join (tempDir , "expand-grants.c1z" )
75+ syncer , err := NewSyncer (ctx , mc , WithC1ZPath (c1zpath ), WithTmpDir (tempDir ))
76+ require .NoError (t , err )
77+ err = syncer .Sync (ctx )
78+ require .NoError (t , err )
79+ err = syncer .Close (ctx )
80+ require .NoError (t , err )
81+ _ = os .Remove (c1zpath )
82+ }
83+
3284func BenchmarkExpandCircle (b * testing.B ) {
3385 ctx , cancel := context .WithCancel (context .Background ())
3486 defer cancel ()
0 commit comments