fix: add user metadata to the features (#2179)

* fix: add user metadata to the features

* fix: remove user metadata

* fix: add test

* fix: add test
This commit is contained in:
Fabi
2021-08-12 16:10:01 +02:00
committed by GitHub
parent b104011418
commit d1c03fd15c
25 changed files with 402 additions and 10 deletions
+178
View File
@@ -16,6 +16,7 @@ import (
"github.com/caos/zitadel/internal/repository/features"
"github.com/caos/zitadel/internal/repository/iam"
"github.com/caos/zitadel/internal/repository/org"
"github.com/caos/zitadel/internal/repository/user"
"github.com/caos/zitadel/internal/static"
"github.com/caos/zitadel/internal/static/mock"
)
@@ -99,6 +100,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
LabelPolicyPrivateLabel: false,
LabelPolicyWatermark: false,
CustomDomain: false,
MetadataUser: false,
},
},
res: res{
@@ -130,6 +132,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
LabelPolicyPrivateLabel: false,
LabelPolicyWatermark: false,
CustomDomain: false,
MetadataUser: false,
},
},
res: res{
@@ -249,6 +252,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
),
),
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
@@ -278,6 +282,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
CustomDomain: false,
CustomText: false,
PrivacyPolicy: false,
MetadataUser: false,
},
},
res: res{
@@ -420,6 +425,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
),
),
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
@@ -454,6 +460,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
LabelPolicyPrivateLabel: false,
LabelPolicyWatermark: false,
CustomDomain: false,
MetadataUser: false,
},
},
res: res{
@@ -603,6 +610,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
),
),
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
@@ -640,6 +648,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
LabelPolicyPrivateLabel: false,
LabelPolicyWatermark: false,
CustomDomain: false,
MetadataUser: false,
},
},
res: res{
@@ -796,6 +805,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
),
),
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
@@ -836,6 +846,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
LabelPolicyPrivateLabel: false,
LabelPolicyWatermark: false,
CustomDomain: false,
MetadataUser: false,
},
},
res: res{
@@ -1044,6 +1055,7 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
),
),
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(
@@ -1095,6 +1107,171 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
LabelPolicyPrivateLabel: false,
LabelPolicyWatermark: false,
CustomDomain: false,
MetadataUser: false,
},
},
res: res{
want: &domain.ObjectDetails{
ResourceOwner: "org1",
},
},
},
{
name: "set with default policies, usermetadata, ok",
fields: fields{
eventstore: eventstoreExpect(
t,
expectFilter(
eventFromEventPusher(
org.NewOrgAddedEvent(
context.Background(),
&org.NewAggregate("org1", "org1").Aggregate,
"org1",
),
),
),
expectFilter(),
expectFilter(
eventFromEventPusher(
iam.NewLoginPolicyAddedEvent(
context.Background(),
&iam.NewAggregate().Aggregate,
false,
false,
false,
false,
false,
domain.PasswordlessTypeAllowed,
),
),
),
expectFilter(
eventFromEventPusher(
iam.NewPasswordComplexityPolicyAddedEvent(
context.Background(),
&iam.NewAggregate().Aggregate,
8,
false,
false,
false,
false,
),
),
),
expectFilter(
eventFromEventPusher(
iam.NewLabelPolicyAddedEvent(
context.Background(),
&iam.NewAggregate().Aggregate,
"primary",
"secondary",
"warn",
"font",
"primary-dark",
"secondary-dark",
"warn-dark",
"font-dark",
false,
false,
false,
),
),
),
expectFilter(
eventFromEventPusher(
org.NewOrgAddedEvent(
context.Background(),
&org.NewAggregate("org1", "org1").Aggregate,
"org1",
),
),
eventFromEventPusher(
org.NewDomainAddedEvent(
context.Background(),
&org.NewAggregate("org1", "org1").Aggregate,
"org1.iam-domain",
),
),
eventFromEventPusher(
org.NewDomainVerifiedEvent(
context.Background(),
&org.NewAggregate("org1", "org1").Aggregate,
"org1.iam-domain",
),
),
eventFromEventPusher(
org.NewDomainPrimarySetEvent(
context.Background(),
&org.NewAggregate("org1", "org1").Aggregate,
"org1.iam-domain",
),
),
),
expectFilter(
eventFromEventPusher(
iam.NewCustomTextSetEvent(
context.Background(),
&iam.NewAggregate().Aggregate,
domain.InitCodeMessageType,
domain.MessageSubject,
"text",
language.English,
),
),
),
expectFilter(
eventFromEventPusher(
iam.NewPrivacyPolicyAddedEvent(
context.Background(),
&iam.NewAggregate().Aggregate,
"toslink",
"privacylink",
),
),
),
expectFilter(
eventFromEventPusher(
user.NewMetadataSetEvent(
context.Background(),
&user.NewAggregate("user1", "org1").Aggregate,
"key",
[]byte("value"),
),
),
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
user.NewMetadataRemovedAllEvent(context.Background(), &user.NewAggregate("user1", "org1").Aggregate),
),
eventFromEventPusher(
newFeaturesSetEvent(context.Background(), "org1", "Test", domain.FeaturesStateActive, time.Hour),
),
},
),
),
iamDomain: "iam-domain",
},
args: args{
ctx: context.Background(),
resourceOwner: "org1",
features: &domain.Features{
TierName: "Test",
State: domain.FeaturesStateActive,
AuditLogRetention: time.Hour,
LoginPolicyFactors: false,
LoginPolicyIDP: false,
LoginPolicyPasswordless: false,
LoginPolicyRegistration: false,
LoginPolicyUsernameLogin: false,
LoginPolicyPasswordReset: false,
PasswordComplexityPolicy: false,
LabelPolicyPrivateLabel: false,
LabelPolicyWatermark: false,
CustomDomain: false,
CustomText: false,
PrivacyPolicy: false,
MetadataUser: false,
},
},
res: res{
@@ -1285,6 +1462,7 @@ func TestCommandSide_RemoveOrgFeatures(t *testing.T) {
),
),
),
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(