Swap id field in grants to ids since that's now standardized (#4250)
* Swap id field in grants to ids since that's now standardized * Fix some tests I missed * Update generated resource table
This commit is contained in:
1 parent
962f9bd638
commit
253d79116c
43 files changed
+392
-392
No files matched your search
@@ -124,7 +124,7 @@ func TestGrantsForUser(t *testing.T) {
|
||||
}
|
||||
for i := 0; i < roleCount; i++ {
|
||||
role := iam.TestRole(t, conn, scopeId, iam.WithName(fmt.Sprintf("testrole%d", i)))
|
||||
iam.TestRoleGrant(t, conn, role.PublicId, "id=*;type=*;actions=*")
|
||||
iam.TestRoleGrant(t, conn, role.PublicId, "ids=*;type=*;actions=*")
|
||||
ret = append(ret, role)
|
||||
}
|
||||
return
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestRepository_AddRoleGrants(t *testing.T) {
|
||||
createGrantsFn := func() []string {
|
||||
results := []string{}
|
||||
for i := 0; i < 5; i++ {
|
||||
g := fmt.Sprintf("id=hc_%d;actions=*", i)
|
||||
g := fmt.Sprintf("ids=hc_%d;actions=*", i)
|
||||
results = append(results, g)
|
||||
}
|
||||
return results
|
||||
@@ -197,7 +197,7 @@ func TestRepository_ListRoleGrants(t *testing.T) {
|
||||
role := TestRole(t, conn, tt.createScopeId)
|
||||
roleGrants := make([]string, 0, tt.createCnt)
|
||||
for i := 0; i < tt.createCnt; i++ {
|
||||
roleGrants = append(roleGrants, fmt.Sprintf("id=h_%d;actions=*", i))
|
||||
roleGrants = append(roleGrants, fmt.Sprintf("ids=h_%d;actions=*", i))
|
||||
}
|
||||
testRoles, err := repo.AddRoleGrants(context.Background(), role.PublicId, role.Version, roleGrants, tt.args.opt...)
|
||||
require.NoError(err)
|
||||
@@ -305,7 +305,7 @@ func TestRepository_DeleteRoleGrants(t *testing.T) {
|
||||
name: "invalid-grant-strings",
|
||||
args: args{
|
||||
role: TestRole(t, conn, org.PublicId),
|
||||
grantStringsOverride: []string{"id=s_87;actions=*"},
|
||||
grantStringsOverride: []string{"ids=s_87;actions=*"},
|
||||
createCnt: 5,
|
||||
deleteCnt: 3,
|
||||
},
|
||||
@@ -341,7 +341,7 @@ func TestRepository_DeleteRoleGrants(t *testing.T) {
|
||||
grants := make([]*RoleGrant, 0, tt.args.createCnt)
|
||||
grantStrings := make([]string, 0, tt.args.createCnt)
|
||||
for i := 0; i < tt.args.createCnt; i++ {
|
||||
g, err := NewRoleGrant(ctx, tt.args.role.PublicId, fmt.Sprintf("actions=*;id=s_%d", i), tt.args.opt...)
|
||||
g, err := NewRoleGrant(ctx, tt.args.role.PublicId, fmt.Sprintf("actions=*;ids=s_%d", i), tt.args.opt...)
|
||||
require.NoError(err)
|
||||
grantStrings = append(grantStrings, g.RawGrant)
|
||||
grants = append(grants, g)
|
||||
@@ -354,7 +354,7 @@ func TestRepository_DeleteRoleGrants(t *testing.T) {
|
||||
deleteGrants := make([]string, 0, tt.args.deleteCnt)
|
||||
for i := 0; i < tt.args.deleteCnt; i++ {
|
||||
deleteCanonicalGrants = append(deleteCanonicalGrants, grants[i].CanonicalGrant)
|
||||
deleteGrants = append(deleteGrants, fmt.Sprintf("id=s_%d;actions=*", i))
|
||||
deleteGrants = append(deleteGrants, fmt.Sprintf("ids=s_%d;actions=*", i))
|
||||
}
|
||||
for i, override := range tt.args.grantStringsOverride {
|
||||
deleteCanonicalGrants = deleteCanonicalGrants[1:]
|
||||
@@ -423,7 +423,7 @@ func TestRepository_SetRoleGrants_Randomize(t *testing.T) {
|
||||
totalCnt := 30
|
||||
grants := make([]*roleGrantWrapper, 0, totalCnt)
|
||||
for i := 0; i < totalCnt; i++ {
|
||||
g, err := NewRoleGrant(ctx, role.PublicId, fmt.Sprintf("id=s_%d;actions=*", i))
|
||||
g, err := NewRoleGrant(ctx, role.PublicId, fmt.Sprintf("ids=s_%d;actions=*", i))
|
||||
require.NoError(err)
|
||||
grants = append(grants, &roleGrantWrapper{
|
||||
grantString: g.RawGrant,
|
||||
@@ -501,7 +501,7 @@ func TestRepository_SetRoleGrants_Parameters(t *testing.T) {
|
||||
args: args{
|
||||
roleId: "",
|
||||
roleVersion: 1,
|
||||
grants: []string{"id=s_1;actions=*"},
|
||||
grants: []string{"ids=s_1;actions=*"},
|
||||
},
|
||||
want: nil,
|
||||
wantAffectedRows: 0,
|
||||
@@ -512,7 +512,7 @@ func TestRepository_SetRoleGrants_Parameters(t *testing.T) {
|
||||
args: args{
|
||||
roleId: "bad-roleid",
|
||||
roleVersion: 1,
|
||||
grants: []string{"id=s_1;actions=*"},
|
||||
grants: []string{"ids=s_1;actions=*"},
|
||||
},
|
||||
want: nil,
|
||||
wantAffectedRows: 0,
|
||||
@@ -534,7 +534,7 @@ func TestRepository_SetRoleGrants_Parameters(t *testing.T) {
|
||||
args: args{
|
||||
roleId: role.PublicId,
|
||||
roleVersion: 0,
|
||||
grants: []string{"id=s_1;actions=*"},
|
||||
grants: []string{"ids=s_1;actions=*"},
|
||||
},
|
||||
want: nil,
|
||||
wantAffectedRows: 0,
|
||||
@@ -545,7 +545,7 @@ func TestRepository_SetRoleGrants_Parameters(t *testing.T) {
|
||||
args: args{
|
||||
roleId: role.PublicId,
|
||||
roleVersion: 1000,
|
||||
grants: []string{"id=s_1;actions=*"},
|
||||
grants: []string{"ids=s_1;actions=*"},
|
||||
},
|
||||
want: nil,
|
||||
wantAffectedRows: 0,
|
||||
|
||||
@@ -393,7 +393,7 @@ func TestRepository_UpdateRole(t *testing.T) {
|
||||
if tt.wantDup {
|
||||
r := TestRole(t, conn, org.PublicId)
|
||||
_ = TestUserRole(t, conn, r.GetPublicId(), u.GetPublicId())
|
||||
_ = TestRoleGrant(t, conn, r.GetPublicId(), "id=*;type=*;actions=*")
|
||||
_ = TestRoleGrant(t, conn, r.GetPublicId(), "ids=*;type=*;actions=*")
|
||||
r.Name = tt.args.name
|
||||
_, _, _, _, err := repo.UpdateRole(context.Background(), r, r.Version, tt.args.fieldMaskPaths, tt.args.opt...)
|
||||
assert.NoError(err)
|
||||
@@ -416,7 +416,7 @@ func TestRepository_UpdateRole(t *testing.T) {
|
||||
princRole.RoleScopeId = tt.newScopeId
|
||||
princRole.ScopedPrincipalId = fmt.Sprintf("%s:%s", org.PublicId, ur.PrincipalId)
|
||||
}
|
||||
rGrant := TestRoleGrant(t, conn, r.GetPublicId(), "id=*;type=*;actions=*")
|
||||
rGrant := TestRoleGrant(t, conn, r.GetPublicId(), "ids=*;type=*;actions=*")
|
||||
|
||||
updateRole := allocRole()
|
||||
updateRole.PublicId = r.PublicId
|
||||
|
||||
@@ -227,7 +227,7 @@ func (r *Repository) CreateScope(ctx context.Context, s *Scope, userId string, o
|
||||
|
||||
msgs = append(msgs, &roleOplogMsg)
|
||||
|
||||
roleGrant, err := NewRoleGrant(ctx, adminRolePublicId, "id=*;type=*;actions=*")
|
||||
roleGrant, err := NewRoleGrant(ctx, adminRolePublicId, "ids=*;type=*;actions=*")
|
||||
if err != nil {
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to create in memory role grant"))
|
||||
}
|
||||
@@ -295,7 +295,7 @@ func (r *Repository) CreateScope(ctx context.Context, s *Scope, userId string, o
|
||||
|
||||
switch s.Type {
|
||||
case scope.Project.String():
|
||||
roleGrant, err := NewRoleGrant(ctx, defaultRolePublicId, "id=*;type=session;actions=list,read:self,cancel:self")
|
||||
roleGrant, err := NewRoleGrant(ctx, defaultRolePublicId, "ids=*;type=session;actions=list,read:self,cancel:self")
|
||||
if err != nil {
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to create in memory role grant"))
|
||||
}
|
||||
@@ -308,25 +308,25 @@ func (r *Repository) CreateScope(ctx context.Context, s *Scope, userId string, o
|
||||
grants = append(grants, roleGrant)
|
||||
|
||||
default:
|
||||
roleGrant, err := NewRoleGrant(ctx, defaultRolePublicId, "id=*;type=scope;actions=list,no-op")
|
||||
roleGrant, err := NewRoleGrant(ctx, defaultRolePublicId, "ids=*;type=scope;actions=list,no-op")
|
||||
if err != nil {
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to create in memory role grant"))
|
||||
}
|
||||
grants = append(grants, roleGrant)
|
||||
|
||||
roleGrant, err = NewRoleGrant(ctx, defaultRolePublicId, "id=*;type=auth-method;actions=authenticate,list")
|
||||
roleGrant, err = NewRoleGrant(ctx, defaultRolePublicId, "ids=*;type=auth-method;actions=authenticate,list")
|
||||
if err != nil {
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to create in memory role grant"))
|
||||
}
|
||||
grants = append(grants, roleGrant)
|
||||
|
||||
roleGrant, err = NewRoleGrant(ctx, defaultRolePublicId, "id={{.Account.Id}};actions=read,change-password")
|
||||
roleGrant, err = NewRoleGrant(ctx, defaultRolePublicId, "ids={{.Account.Id}};actions=read,change-password")
|
||||
if err != nil {
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to create in memory role grant"))
|
||||
}
|
||||
grants = append(grants, roleGrant)
|
||||
|
||||
roleGrant, err = NewRoleGrant(ctx, defaultRolePublicId, "id=*;type=auth-token;actions=list,read:self,delete:self")
|
||||
roleGrant, err = NewRoleGrant(ctx, defaultRolePublicId, "ids=*;type=auth-token;actions=list,read:self,delete:self")
|
||||
if err != nil {
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to create in memory role grant"))
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func TestRoleGrant_Create(t *testing.T) {
|
||||
name: "nil-role",
|
||||
args: args{
|
||||
roleId: "",
|
||||
grant: "id=*;type=*;actions=*",
|
||||
grant: "ids=*;type=*;actions=*",
|
||||
},
|
||||
wantErr: true,
|
||||
wantIsErr: errors.InvalidParameter,
|
||||
@@ -60,13 +60,13 @@ func TestRoleGrant_Create(t *testing.T) {
|
||||
name: "valid",
|
||||
args: args{
|
||||
roleId: projRole.PublicId,
|
||||
grant: "id=*;type=*;actions=*",
|
||||
grant: "ids=*;type=*;actions=*",
|
||||
},
|
||||
want: func() *RoleGrant {
|
||||
g := allocRoleGrant()
|
||||
g.RoleId = projRole.PublicId
|
||||
g.RawGrant = "id=*;type=*;actions=*"
|
||||
g.CanonicalGrant = "id=*;type=*;actions=*"
|
||||
g.RawGrant = "ids=*;type=*;actions=*"
|
||||
g.CanonicalGrant = "ids=*;type=*;actions=*"
|
||||
return &g
|
||||
}(),
|
||||
create: true,
|
||||
@@ -75,13 +75,13 @@ func TestRoleGrant_Create(t *testing.T) {
|
||||
name: "valid-reversed-grant",
|
||||
args: args{
|
||||
roleId: projRole.PublicId,
|
||||
grant: "type=*;actions=*;id=*",
|
||||
grant: "type=*;actions=*;ids=*",
|
||||
},
|
||||
want: func() *RoleGrant {
|
||||
g := allocRoleGrant()
|
||||
g.RoleId = projRole.PublicId
|
||||
g.RawGrant = "type=*;actions=*;id=*"
|
||||
g.CanonicalGrant = "id=*;type=*;actions=*"
|
||||
g.RawGrant = "type=*;actions=*;ids=*"
|
||||
g.CanonicalGrant = "ids=*;type=*;actions=*"
|
||||
return &g
|
||||
}(),
|
||||
create: true,
|
||||
@@ -128,9 +128,9 @@ func TestRoleGrant_Update(t *testing.T) {
|
||||
t.Run("updates not allowed", func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
r := TestRole(t, conn, org.PublicId)
|
||||
roleGrant := TestRoleGrant(t, conn, r.PublicId, "id=*;type=*;actions=*")
|
||||
roleGrant := TestRoleGrant(t, conn, r.PublicId, "ids=*;type=*;actions=*")
|
||||
updateRoleGrant := roleGrant.Clone().(*RoleGrant)
|
||||
updateRoleGrant.RawGrant = "type=*;actions=*;id=*"
|
||||
updateRoleGrant.RawGrant = "type=*;actions=*;ids=*"
|
||||
updatedRows, err := rw.Update(context.Background(), updateRoleGrant, []string{"RawGrant"}, nil)
|
||||
require.Error(err)
|
||||
assert.Equal(0, updatedRows)
|
||||
@@ -163,7 +163,7 @@ func TestRoleGrant_Delete(t *testing.T) {
|
||||
name: "nil-role",
|
||||
args: args{
|
||||
roleId: "",
|
||||
grant: "id=*;type=*;actions=*",
|
||||
grant: "ids=*;type=*;actions=*",
|
||||
},
|
||||
wantErr: true,
|
||||
wantsErrStr: "is not set",
|
||||
@@ -181,14 +181,14 @@ func TestRoleGrant_Delete(t *testing.T) {
|
||||
name: "invalid",
|
||||
args: args{
|
||||
roleId: projRole.PublicId,
|
||||
grant: "id=u_edcb;actions=read,update",
|
||||
grant: "ids=u_edcb;actions=read,update",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "valid",
|
||||
args: args{
|
||||
roleId: projRole.PublicId,
|
||||
grant: "id=u_bcde;actions=read,update",
|
||||
grant: "ids=u_bcde;actions=read,update",
|
||||
},
|
||||
deletedRows: 1,
|
||||
},
|
||||
@@ -198,10 +198,10 @@ func TestRoleGrant_Delete(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
r := allocRoleGrant()
|
||||
db.TestDeleteWhere(t, conn, &r, "1=1")
|
||||
rg, err := NewRoleGrant(ctx, projRole.PublicId, "id=u_bcde;actions=read,update")
|
||||
rg, err := NewRoleGrant(ctx, projRole.PublicId, "ids=u_bcde;actions=read,update")
|
||||
require.NoError(err)
|
||||
require.NoError(rw.Create(context.Background(), rg))
|
||||
rg, err = NewRoleGrant(ctx, projRole.PublicId, "id=u_cdef;actions=read,update")
|
||||
rg, err = NewRoleGrant(ctx, projRole.PublicId, "ids=u_cdef;actions=read,update")
|
||||
require.NoError(err)
|
||||
require.NoError(rw.Create(context.Background(), rg))
|
||||
|
||||
@@ -235,11 +235,11 @@ func TestRoleGrant_Clone(t *testing.T) {
|
||||
s := testOrg(t, repo, "", "")
|
||||
role := TestRole(t, conn, s.PublicId)
|
||||
|
||||
g, err := NewRoleGrant(ctx, role.PublicId, "id=*;type=*;actions=*")
|
||||
g, err := NewRoleGrant(ctx, role.PublicId, "ids=*;type=*;actions=*")
|
||||
assert.NoError(err)
|
||||
assert.NotNil(g)
|
||||
assert.Equal(g.RoleId, role.PublicId)
|
||||
assert.Equal(g.RawGrant, "id=*;type=*;actions=*")
|
||||
assert.Equal(g.RawGrant, "ids=*;type=*;actions=*")
|
||||
|
||||
cp := g.Clone()
|
||||
assert.True(proto.Equal(cp.(*RoleGrant).RoleGrant, g.RoleGrant))
|
||||
@@ -249,17 +249,17 @@ func TestRoleGrant_Clone(t *testing.T) {
|
||||
s := testOrg(t, repo, "", "")
|
||||
role := TestRole(t, conn, s.PublicId)
|
||||
|
||||
g, err := NewRoleGrant(ctx, role.PublicId, "id=*;type=*;actions=*")
|
||||
g, err := NewRoleGrant(ctx, role.PublicId, "ids=*;type=*;actions=*")
|
||||
assert.NoError(err)
|
||||
require.NotNil(g)
|
||||
assert.Equal(g.RoleId, role.PublicId)
|
||||
assert.Equal(g.RawGrant, "id=*;type=*;actions=*")
|
||||
assert.Equal(g.RawGrant, "ids=*;type=*;actions=*")
|
||||
|
||||
g2, err := NewRoleGrant(ctx, role.PublicId, "id=u_foo;actions=read")
|
||||
g2, err := NewRoleGrant(ctx, role.PublicId, "ids=u_foo;actions=read")
|
||||
assert.NoError(err)
|
||||
require.NotNil(g2)
|
||||
assert.Equal(g2.RoleId, role.PublicId)
|
||||
assert.Equal(g2.RawGrant, "id=u_foo;actions=read")
|
||||
assert.Equal(g2.RawGrant, "ids=u_foo;actions=read")
|
||||
|
||||
cp := g.Clone()
|
||||
assert.True(!proto.Equal(cp.(*RoleGrant).RoleGrant, g2.RoleGrant))
|
||||
|
||||
@@ -120,11 +120,11 @@ func Test_TestRoleGrant(t *testing.T) {
|
||||
_, proj := TestScopes(t, repo)
|
||||
projRole := TestRole(t, conn, proj.PublicId)
|
||||
|
||||
grant := TestRoleGrant(t, conn, projRole.PublicId, "type=*;actions=*;id=*")
|
||||
grant := TestRoleGrant(t, conn, projRole.PublicId, "type=*;actions=*;ids=*")
|
||||
require.NotNil(grant)
|
||||
require.Equal(projRole.PublicId, grant.RoleId)
|
||||
require.Equal("type=*;actions=*;id=*", grant.RawGrant)
|
||||
require.Equal("id=*;type=*;actions=*", grant.CanonicalGrant)
|
||||
require.Equal("type=*;actions=*;ids=*", grant.RawGrant)
|
||||
require.Equal("ids=*;type=*;actions=*", grant.CanonicalGrant)
|
||||
}
|
||||
|
||||
func Test_TestUserRole(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user