mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-11 21:32:12 +00:00
* fix: user grant command side * fix: user grant command side * fix: user grant command side check permissions * fix: unique constraint on user grants * fix: add usergrant * fix: add usergrant * fix: add usergrant * fix: user grant remove * Update internal/v2/command/auth_checks.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/v2/command/auth_checks.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/v2/command/project.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/v2/command/user_grant.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix: project events Co-authored-by: Livio Amstutz <livio.a@gmail.com>
62 lines
2.2 KiB
Go
62 lines
2.2 KiB
Go
package model
|
|
|
|
import (
|
|
"testing"
|
|
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
"github.com/caos/zitadel/internal/usergrant/model"
|
|
)
|
|
|
|
func TestAppendGrantStateEvent(t *testing.T) {
|
|
type args struct {
|
|
grant *UserGrant
|
|
grantID *UserGrantID
|
|
event *es_models.Event
|
|
state model.UserGrantState
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
result *UserGrant
|
|
}{
|
|
{
|
|
name: "append deactivate grant event",
|
|
args: args{
|
|
grant: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}},
|
|
grantID: &UserGrantID{GrantID: "ProjectGrantID"},
|
|
event: &es_models.Event{},
|
|
state: model.UserGrantStateInactive,
|
|
},
|
|
result: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}, State: int32(model.UserGrantStateInactive)},
|
|
},
|
|
{
|
|
name: "append reactivate grant event",
|
|
args: args{
|
|
grant: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}},
|
|
grantID: &UserGrantID{GrantID: "ProjectGrantID"},
|
|
event: &es_models.Event{},
|
|
state: model.UserGrantStateActive,
|
|
},
|
|
result: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}, State: int32(model.UserGrantStateActive)},
|
|
},
|
|
{
|
|
name: "append remove grant event",
|
|
args: args{
|
|
grant: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}},
|
|
grantID: &UserGrantID{GrantID: "ProjectGrantID"},
|
|
event: &es_models.Event{},
|
|
state: model.UserGrantStateRemoved,
|
|
},
|
|
result: &UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID", RoleKeys: []string{"Key"}, State: int32(model.UserGrantStateRemoved)},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
tt.args.grant.appendGrantStateEvent(tt.args.state)
|
|
if tt.args.grant.State != tt.result.State {
|
|
t.Errorf("got wrong result: actual: %v, expected: %v ", tt.result.State, tt.args.grant.State)
|
|
}
|
|
})
|
|
}
|
|
}
|