mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-15 02:07:41 +00:00
feat: port reduction (#323)
* move mgmt pkg * begin package restructure * rename auth package to authz * begin start api * move auth * move admin * fix merge * configs and interceptors * interceptor * revert generate-grpc.sh * some cleanups * console * move console * fix tests and merging * js linting * merge * merging and configs * change k8s base to current ports * fixes * cleanup * regenerate proto * remove unnecessary whitespace * missing param * go mod tidy * fix merging * move login pkg * cleanup * move api pkgs again * fix pkg naming * fix generate-static.sh for login * update workflow * fixes * logging * remove duplicate * comment for optional gateway interfaces * regenerate protos * fix proto imports for grpc web * protos * grpc web generate * grpc web generate * fix changes * add translation interceptor * fix merging * regenerate mgmt proto
This commit is contained in:
@@ -2,13 +2,15 @@ package eventsourcing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/caos/zitadel/internal/api/auth"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
||||
"github.com/caos/zitadel/internal/usergrant/model"
|
||||
"github.com/golang/mock/gomock"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUserByID(t *testing.T) {
|
||||
@@ -106,7 +108,7 @@ func TestAddUserGrant(t *testing.T) {
|
||||
name: "add grant, ok",
|
||||
args: args{
|
||||
es: GetMockManipulateUserGrant(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
grant: &model.UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1},
|
||||
ProjectID: "ProjectID",
|
||||
UserID: "UserID",
|
||||
@@ -125,7 +127,7 @@ func TestAddUserGrant(t *testing.T) {
|
||||
name: "invalid grant",
|
||||
args: args{
|
||||
es: GetMockManipulateUserGrant(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
grant: &model.UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}},
|
||||
},
|
||||
res: res{
|
||||
@@ -172,7 +174,7 @@ func TestChangeUserGrant(t *testing.T) {
|
||||
name: "change grant, ok",
|
||||
args: args{
|
||||
es: GetMockManipulateUserGrant(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
grant: &model.UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1},
|
||||
RoleKeys: []string{"KeyChanged"},
|
||||
},
|
||||
@@ -187,7 +189,7 @@ func TestChangeUserGrant(t *testing.T) {
|
||||
name: "invalid grant",
|
||||
args: args{
|
||||
es: GetMockManipulateUserGrant(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
grant: nil,
|
||||
},
|
||||
res: res{
|
||||
@@ -199,7 +201,7 @@ func TestChangeUserGrant(t *testing.T) {
|
||||
name: "existing user not found",
|
||||
args: args{
|
||||
es: GetMockManipulateUserGrantNoEvents(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
grant: &model.UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1},
|
||||
RoleKeys: []string{"KeyChanged"},
|
||||
},
|
||||
@@ -247,7 +249,7 @@ func TestRemoveUserGrant(t *testing.T) {
|
||||
name: "remove grant, ok",
|
||||
args: args{
|
||||
es: GetMockManipulateUserGrant(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
grant: &model.UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}},
|
||||
},
|
||||
},
|
||||
@@ -255,7 +257,7 @@ func TestRemoveUserGrant(t *testing.T) {
|
||||
name: "no grantID",
|
||||
args: args{
|
||||
es: GetMockManipulateUserGrant(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
grant: &model.UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "", Sequence: 1}},
|
||||
},
|
||||
res: res{
|
||||
@@ -267,7 +269,7 @@ func TestRemoveUserGrant(t *testing.T) {
|
||||
name: "existing grant not found",
|
||||
args: args{
|
||||
es: GetMockManipulateUserGrantNoEvents(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
grant: &model.UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}},
|
||||
},
|
||||
res: res{
|
||||
@@ -311,7 +313,7 @@ func TestDeactivateUserGrant(t *testing.T) {
|
||||
name: "deactivate, ok",
|
||||
args: args{
|
||||
es: GetMockManipulateUserGrant(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
grant: &model.UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}},
|
||||
},
|
||||
res: res{
|
||||
@@ -325,7 +327,7 @@ func TestDeactivateUserGrant(t *testing.T) {
|
||||
name: "no grant id",
|
||||
args: args{
|
||||
es: GetMockManipulateUserGrant(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
grant: &model.UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "", Sequence: 1}},
|
||||
},
|
||||
res: res{
|
||||
@@ -337,7 +339,7 @@ func TestDeactivateUserGrant(t *testing.T) {
|
||||
name: "grant not existing",
|
||||
args: args{
|
||||
es: GetMockManipulateUserGrantNoEvents(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
grant: &model.UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "ID", Sequence: 1}},
|
||||
},
|
||||
res: res{
|
||||
@@ -387,7 +389,7 @@ func TestReactivateUserGrant(t *testing.T) {
|
||||
name: "reactivate, ok",
|
||||
args: args{
|
||||
es: GetMockManipulateUserGrantInactive(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
grant: &model.UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}},
|
||||
},
|
||||
res: res{
|
||||
@@ -400,7 +402,7 @@ func TestReactivateUserGrant(t *testing.T) {
|
||||
name: "no grant id",
|
||||
args: args{
|
||||
es: GetMockManipulateUserGrant(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
grant: &model.UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "", Sequence: 1}},
|
||||
},
|
||||
res: res{
|
||||
@@ -412,7 +414,7 @@ func TestReactivateUserGrant(t *testing.T) {
|
||||
name: "grant not existing",
|
||||
args: args{
|
||||
es: GetMockManipulateUserGrantNoEvents(ctrl),
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
grant: &model.UserGrant{ObjectRoot: es_models.ObjectRoot{AggregateID: "AggregateID", Sequence: 1}},
|
||||
},
|
||||
res: res{
|
||||
|
@@ -3,7 +3,7 @@ package eventsourcing
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/auth"
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
||||
org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
||||
@@ -50,9 +50,9 @@ func UserGrantAddedAggregate(ctx context.Context, aggCreator *es_models.Aggregat
|
||||
}
|
||||
validationQuery := es_models.NewSearchQuery().
|
||||
AggregateTypeFilter(usr_model.UserAggregate, org_es_model.OrgAggregate, proj_es_model.ProjectAggregate).
|
||||
AggregateIDsFilter(grant.UserID, auth.GetCtxData(ctx).OrgID, grant.ProjectID)
|
||||
AggregateIDsFilter(grant.UserID, authz.GetCtxData(ctx).OrgID, grant.ProjectID)
|
||||
|
||||
validation := addUserGrantValidation(auth.GetCtxData(ctx).OrgID, grant)
|
||||
validation := addUserGrantValidation(authz.GetCtxData(ctx).OrgID, grant)
|
||||
agg, err = agg.SetPrecondition(validationQuery, validation).AppendEvent(model.UserGrantAdded, grant)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -69,7 +69,7 @@ func UserGrantAddedAggregate(ctx context.Context, aggCreator *es_models.Aggregat
|
||||
}
|
||||
|
||||
func reservedUniqueUserGrantAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, grant *model.UserGrant) (*es_models.Aggregate, error) {
|
||||
grantID := auth.GetCtxData(ctx).OrgID + grant.ProjectID + grant.UserID
|
||||
grantID := authz.GetCtxData(ctx).OrgID + grant.ProjectID + grant.UserID
|
||||
aggregate, err := aggCreator.NewAggregate(ctx, grantID, model.UserGrantUniqueAggregate, model.UserGrantVersion, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -79,7 +79,7 @@ func reservedUniqueUserGrantAggregate(ctx context.Context, aggCreator *es_models
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return aggregate.SetPrecondition(UserGrantUniqueQuery(auth.GetCtxData(ctx).OrgID, grant.ProjectID, grant.UserID), isEventValidation(aggregate, model.UserGrantReserved)), nil
|
||||
return aggregate.SetPrecondition(UserGrantUniqueQuery(authz.GetCtxData(ctx).OrgID, grant.ProjectID, grant.UserID), isEventValidation(aggregate, model.UserGrantReserved)), nil
|
||||
}
|
||||
|
||||
func releasedUniqueUserGrantAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, grant *model.UserGrant) (aggregate *es_models.Aggregate, err error) {
|
||||
|
@@ -2,11 +2,12 @@ package eventsourcing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/caos/zitadel/internal/api/auth"
|
||||
"testing"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/models"
|
||||
"github.com/caos/zitadel/internal/usergrant/repository/eventsourcing/model"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUserGrantAddedAggregate(t *testing.T) {
|
||||
@@ -28,7 +29,7 @@ func TestUserGrantAddedAggregate(t *testing.T) {
|
||||
{
|
||||
name: "usergrant added ok",
|
||||
args: args{
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
grant: &model.UserGrant{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}, UserID: "UserID", ProjectID: "ProjectID"},
|
||||
aggCreator: models.NewAggregateCreator("Test"),
|
||||
},
|
||||
@@ -40,7 +41,7 @@ func TestUserGrantAddedAggregate(t *testing.T) {
|
||||
{
|
||||
name: "grant nil",
|
||||
args: args{
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
grant: nil,
|
||||
aggCreator: models.NewAggregateCreator("Test"),
|
||||
},
|
||||
@@ -90,7 +91,7 @@ func TestUserGrantChangedAggregate(t *testing.T) {
|
||||
{
|
||||
name: "change project grant",
|
||||
args: args{
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.UserGrant{
|
||||
ObjectRoot: models.ObjectRoot{AggregateID: "ID"},
|
||||
UserID: "UserID",
|
||||
@@ -112,7 +113,7 @@ func TestUserGrantChangedAggregate(t *testing.T) {
|
||||
{
|
||||
name: "change project grant cascade",
|
||||
args: args{
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.UserGrant{
|
||||
ObjectRoot: models.ObjectRoot{AggregateID: "ID"},
|
||||
UserID: "UserID",
|
||||
@@ -135,7 +136,7 @@ func TestUserGrantChangedAggregate(t *testing.T) {
|
||||
{
|
||||
name: "existing grant nil",
|
||||
args: args{
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: nil,
|
||||
new: &model.UserGrant{
|
||||
ObjectRoot: models.ObjectRoot{AggregateID: "ID"},
|
||||
@@ -151,7 +152,7 @@ func TestUserGrantChangedAggregate(t *testing.T) {
|
||||
{
|
||||
name: "grant nil",
|
||||
args: args{
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.UserGrant{
|
||||
ObjectRoot: models.ObjectRoot{AggregateID: "ID"},
|
||||
UserID: "UserID",
|
||||
@@ -209,7 +210,7 @@ func TestUserGrantRemovedAggregate(t *testing.T) {
|
||||
{
|
||||
name: "remove app",
|
||||
args: args{
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.UserGrant{
|
||||
ObjectRoot: models.ObjectRoot{AggregateID: "ID"},
|
||||
UserID: "UserID",
|
||||
@@ -228,7 +229,7 @@ func TestUserGrantRemovedAggregate(t *testing.T) {
|
||||
{
|
||||
name: "remove app cascade",
|
||||
args: args{
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.UserGrant{
|
||||
ObjectRoot: models.ObjectRoot{AggregateID: "ID"},
|
||||
UserID: "UserID",
|
||||
@@ -248,7 +249,7 @@ func TestUserGrantRemovedAggregate(t *testing.T) {
|
||||
{
|
||||
name: "existing project nil",
|
||||
args: args{
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: nil,
|
||||
aggCreator: models.NewAggregateCreator("Test"),
|
||||
},
|
||||
@@ -259,7 +260,7 @@ func TestUserGrantRemovedAggregate(t *testing.T) {
|
||||
{
|
||||
name: "grant nil",
|
||||
args: args{
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.UserGrant{
|
||||
ObjectRoot: models.ObjectRoot{AggregateID: "ID"},
|
||||
UserID: "UserID",
|
||||
@@ -313,7 +314,7 @@ func TestUserGrantDeactivatedAggregate(t *testing.T) {
|
||||
{
|
||||
name: "deactivate project grant",
|
||||
args: args{
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.UserGrant{
|
||||
ObjectRoot: models.ObjectRoot{AggregateID: "ID"},
|
||||
},
|
||||
@@ -330,7 +331,7 @@ func TestUserGrantDeactivatedAggregate(t *testing.T) {
|
||||
{
|
||||
name: "existing grant nil",
|
||||
args: args{
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: nil,
|
||||
aggCreator: models.NewAggregateCreator("Test"),
|
||||
},
|
||||
@@ -341,7 +342,7 @@ func TestUserGrantDeactivatedAggregate(t *testing.T) {
|
||||
{
|
||||
name: "grant nil",
|
||||
args: args{
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.UserGrant{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}},
|
||||
new: nil,
|
||||
aggCreator: models.NewAggregateCreator("Test"),
|
||||
@@ -391,7 +392,7 @@ func TestUserGrantReactivatedAggregate(t *testing.T) {
|
||||
{
|
||||
name: "reactivate project grant",
|
||||
args: args{
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.UserGrant{
|
||||
ObjectRoot: models.ObjectRoot{AggregateID: "ID"},
|
||||
},
|
||||
@@ -408,7 +409,7 @@ func TestUserGrantReactivatedAggregate(t *testing.T) {
|
||||
{
|
||||
name: "existing grant nil",
|
||||
args: args{
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: nil,
|
||||
aggCreator: models.NewAggregateCreator("Test"),
|
||||
},
|
||||
@@ -419,7 +420,7 @@ func TestUserGrantReactivatedAggregate(t *testing.T) {
|
||||
{
|
||||
name: "grant nil",
|
||||
args: args{
|
||||
ctx: auth.NewMockContext("orgID", "userID"),
|
||||
ctx: authz.NewMockContext("orgID", "userID"),
|
||||
existing: &model.UserGrant{ObjectRoot: models.ObjectRoot{AggregateID: "ID"}},
|
||||
new: nil,
|
||||
aggCreator: models.NewAggregateCreator("Test"),
|
||||
|
Reference in New Issue
Block a user