feat: enable default smtp config on setup (#3622)

* feat: enable default smtp config on setup

* fix tests

* fix channel order

Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
This commit is contained in:
Livio Amstutz
2022-05-13 14:13:07 +02:00
committed by GitHub
parent 5571db3e1b
commit 024eedc1b5
15 changed files with 261 additions and 159 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/crypto"
"github.com/zitadel/zitadel/internal/domain"
caos_errs "github.com/zitadel/zitadel/internal/errors"
@@ -22,9 +23,8 @@ func TestCommandSide_AddSMTPConfig(t *testing.T) {
alg crypto.EncryptionAlgorithm
}
type args struct {
ctx context.Context
instanceID string
smtp *smtp.EmailConfig
ctx context.Context
smtp *smtp.EmailConfig
}
type res struct {
want *domain.ObjectDetails
@@ -57,10 +57,16 @@ func TestCommandSide_AddSMTPConfig(t *testing.T) {
),
},
args: args{
ctx: context.Background(),
instanceID: "INSTANCE",
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
smtp: &smtp.EmailConfig{
Tls: true,
Tls: true,
From: "from",
FromName: "name",
SMTP: smtp.SMTP{
Host: "host",
User: "user",
Password: "password",
},
},
},
res: res{
@@ -75,21 +81,23 @@ func TestCommandSide_AddSMTPConfig(t *testing.T) {
expectFilter(),
expectPush(
[]*repository.Event{
eventFromEventPusher(instance.NewSMTPConfigAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
"from",
"name",
"host",
"user",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("password"),
},
),
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewSMTPConfigAddedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
true,
"from",
"name",
"host",
"user",
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("password"),
},
),
),
},
),
@@ -97,8 +105,7 @@ func TestCommandSide_AddSMTPConfig(t *testing.T) {
alg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
},
args: args{
ctx: context.Background(),
instanceID: "INSTANCE",
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
smtp: &smtp.EmailConfig{
Tls: true,
From: "from",
@@ -123,7 +130,7 @@ func TestCommandSide_AddSMTPConfig(t *testing.T) {
eventstore: tt.fields.eventstore,
smtpEncryption: tt.fields.alg,
}
got, err := r.AddSMTPConfig(tt.args.ctx, tt.args.instanceID, tt.args.smtp)
got, err := r.AddSMTPConfig(tt.args.ctx, tt.args.smtp)
if tt.res.err == nil {
assert.NoError(t, err)
}
@@ -142,9 +149,8 @@ func TestCommandSide_ChangeSMTPConfig(t *testing.T) {
eventstore *eventstore.Eventstore
}
type args struct {
ctx context.Context
instanceID string
smtp *smtp.EmailConfig
ctx context.Context
smtp *smtp.EmailConfig
}
type res struct {
want *domain.ObjectDetails
@@ -156,6 +162,21 @@ func TestCommandSide_ChangeSMTPConfig(t *testing.T) {
args args
res res
}{
{
name: "empty config, invalid argument error",
fields: fields{
eventstore: eventstoreExpect(
t,
),
},
args: args{
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
smtp: &smtp.EmailConfig{},
},
res: res{
err: caos_errs.IsErrorInvalidArgument,
},
},
{
name: "smtp not existing, not found error",
fields: fields{
@@ -165,14 +186,21 @@ func TestCommandSide_ChangeSMTPConfig(t *testing.T) {
),
},
args: args{
ctx: context.Background(),
smtp: &smtp.EmailConfig{},
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
smtp: &smtp.EmailConfig{
Tls: true,
From: "from",
FromName: "name",
SMTP: smtp.SMTP{
Host: "host",
User: "user",
},
},
},
res: res{
err: caos_errs.IsNotFound,
},
},
{
name: "no changes, precondition error",
fields: fields{
@@ -195,8 +223,7 @@ func TestCommandSide_ChangeSMTPConfig(t *testing.T) {
),
},
args: args{
ctx: context.Background(),
instanceID: "INSTANCE",
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
smtp: &smtp.EmailConfig{
Tls: true,
From: "from",
@@ -232,7 +259,8 @@ func TestCommandSide_ChangeSMTPConfig(t *testing.T) {
),
expectPush(
[]*repository.Event{
eventFromEventPusher(
eventFromEventPusherWithInstanceID(
"INSTANCE",
newSMTPConfigChangedEvent(
context.Background(),
false,
@@ -247,7 +275,7 @@ func TestCommandSide_ChangeSMTPConfig(t *testing.T) {
),
},
args: args{
ctx: context.Background(),
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
smtp: &smtp.EmailConfig{
Tls: false,
From: "from2",
@@ -270,7 +298,7 @@ func TestCommandSide_ChangeSMTPConfig(t *testing.T) {
r := &Commands{
eventstore: tt.fields.eventstore,
}
got, err := r.ChangeSMTPConfig(tt.args.ctx, tt.args.instanceID, tt.args.smtp)
got, err := r.ChangeSMTPConfig(tt.args.ctx, tt.args.smtp)
if tt.res.err == nil {
assert.NoError(t, err)
}
@@ -290,9 +318,8 @@ func TestCommandSide_ChangeSMTPConfigPassword(t *testing.T) {
alg crypto.EncryptionAlgorithm
}
type args struct {
ctx context.Context
instanceID string
password string
ctx context.Context
password string
}
type res struct {
want *domain.ObjectDetails
@@ -341,16 +368,18 @@ func TestCommandSide_ChangeSMTPConfigPassword(t *testing.T) {
),
expectPush(
[]*repository.Event{
eventFromEventPusher(instance.NewSMTPConfigPasswordChangedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("password"),
},
),
eventFromEventPusherWithInstanceID(
"INSTANCE",
instance.NewSMTPConfigPasswordChangedEvent(
context.Background(),
&instance.NewAggregate("INSTANCE").Aggregate,
&crypto.CryptoValue{
CryptoType: crypto.TypeEncryption,
Algorithm: "enc",
KeyID: "id",
Crypted: []byte("password"),
},
),
),
},
),
@@ -358,9 +387,8 @@ func TestCommandSide_ChangeSMTPConfigPassword(t *testing.T) {
alg: crypto.CreateMockEncryptionAlg(gomock.NewController(t)),
},
args: args{
ctx: context.Background(),
instanceID: "INSTANCE",
password: "password",
ctx: authz.WithInstanceID(context.Background(), "INSTANCE"),
password: "password",
},
res: res{
want: &domain.ObjectDetails{
@@ -375,7 +403,7 @@ func TestCommandSide_ChangeSMTPConfigPassword(t *testing.T) {
eventstore: tt.fields.eventstore,
smtpEncryption: tt.fields.alg,
}
got, err := r.ChangeSMTPConfigPassword(tt.args.ctx, tt.args.instanceID, tt.args.password)
got, err := r.ChangeSMTPConfigPassword(tt.args.ctx, tt.args.password)
if tt.res.err == nil {
assert.NoError(t, err)
}