fix: check if org exists when setting features (#1813)

* fix: check if org exists when setting features

* fix tests
This commit is contained in:
Livio Amstutz 2021-06-04 15:44:45 +02:00 committed by GitHub
parent 73d37459bb
commit 9ffc9d9330
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 82 additions and 1 deletions

View File

@ -13,8 +13,12 @@ func (c *Commands) SetOrgFeatures(ctx context.Context, resourceOwner string, fea
if resourceOwner == "" {
return nil, caos_errs.ThrowInvalidArgument(nil, "Features-G5tg", "Errors.ResourceOwnerMissing")
}
err := c.checkOrgExists(ctx, resourceOwner)
if err != nil {
return nil, err
}
existingFeatures := NewOrgFeaturesWriteModel(resourceOwner)
err := c.eventstore.FilterToQueryReducer(ctx, existingFeatures)
err = c.eventstore.FilterToQueryReducer(ctx, existingFeatures)
if err != nil {
return nil, err
}

View File

@ -104,11 +104,51 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
err: caos_errs.IsPreconditionFailed,
},
},
{
name: "org does not exist, error",
fields: fields{
eventstore: eventstoreExpect(
t,
expectFilter(),
),
},
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,
},
},
res: res{
err: caos_errs.IsPreconditionFailed,
},
},
{
name: "set with default policies, ok",
fields: fields{
eventstore: eventstoreExpect(
t,
expectFilter(
eventFromEventPusher(
org.NewOrgAddedEvent(
context.Background(),
&org.NewAggregate("org1", "org1").Aggregate,
"org1",
),
),
),
expectFilter(),
expectFilter(
eventFromEventPusher(
@ -226,6 +266,15 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
fields: fields{
eventstore: eventstoreExpect(
t,
expectFilter(
eventFromEventPusher(
org.NewOrgAddedEvent(
context.Background(),
&org.NewAggregate("org1", "org1").Aggregate,
"org1",
),
),
),
expectFilter(),
expectFilter(
eventFromEventPusher(
@ -371,6 +420,15 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
fields: fields{
eventstore: eventstoreExpect(
t,
expectFilter(
eventFromEventPusher(
org.NewOrgAddedEvent(
context.Background(),
&org.NewAggregate("org1", "org1").Aggregate,
"org1",
),
),
),
expectFilter(),
expectFilter(
eventFromEventPusher(
@ -526,6 +584,15 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
fields: fields{
eventstore: eventstoreExpect(
t,
expectFilter(
eventFromEventPusher(
org.NewOrgAddedEvent(
context.Background(),
&org.NewAggregate("org1", "org1").Aggregate,
"org1",
),
),
),
expectFilter(),
expectFilter(
eventFromEventPusher(
@ -691,6 +758,16 @@ func TestCommandSide_SetOrgFeatures(t *testing.T) {
fields: fields{
eventstore: eventstoreExpect(
t,
//checkOrgExists
expectFilter(
eventFromEventPusher(
org.NewOrgAddedEvent(
context.Background(),
&org.NewAggregate("org1", "org1").Aggregate,
"org1",
),
),
),
//NewOrgFeaturesWriteModel
expectFilter(),
//begin ensureOrgSettingsToFeatures