From 7c68c5aa69ed76a84a37a37a3555277ddc772cf8 Mon Sep 17 00:00:00 2001 From: Jonas Hungershausen Date: Mon, 4 Mar 2024 10:37:47 +0100 Subject: [PATCH] fix: make sure emails can still be sent with SMS enabled (#3795) --- driver/config/config.go | 6 +++--- driver/config/config_test.go | 4 +++- driver/config/stub/.kratos.courier.channels.yaml | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/driver/config/config.go b/driver/config/config.go index 6af7e7c17c5c..ad2d414fdfa3 100644 --- a/driver/config/config.go +++ b/driver/config/config.go @@ -1020,7 +1020,7 @@ func (p *Config) SelfServiceFlowLogoutRedirectURL(ctx context.Context) *url.URL } func (p *Config) CourierEmailStrategy(ctx context.Context) string { - return p.GetProvider(ctx).String(ViperKeyCourierDeliveryStrategy) + return p.GetProvider(ctx).StringF(ViperKeyCourierDeliveryStrategy, "smtp") } func (p *Config) CourierEmailRequestConfig(ctx context.Context) json.RawMessage { @@ -1169,7 +1169,6 @@ func (p *Config) CourierChannels(ctx context.Context) (ccs []*CourierChannel, _ } } } - return ccs, nil } // load legacy configs @@ -1188,7 +1187,8 @@ func (p *Config) CourierChannels(ctx context.Context) (ccs []*CourierChannel, _ return nil, errors.WithStack(err) } } - return []*CourierChannel{&channel}, nil + ccs = append(ccs, &channel) + return ccs, nil } func splitUrlAndFragment(s string) (string, string) { diff --git a/driver/config/config_test.go b/driver/config/config_test.go index 38e3a01fd055..ee30b48fbaa8 100644 --- a/driver/config/config_test.go +++ b/driver/config/config_test.go @@ -1157,9 +1157,11 @@ func TestCourierChannels(t *testing.T) { channelConfig, err := conf.CourierChannels(ctx) require.NoError(t, err) - require.Len(t, channelConfig, 1) + require.Len(t, channelConfig, 2) assert.Equal(t, channelConfig[0].ID, "phone") assert.NotEmpty(t, channelConfig[0].RequestConfig) + assert.Equal(t, channelConfig[1].ID, "email") + assert.NotEmpty(t, channelConfig[1].SMTPConfig) }) t.Run("case=defaults", func(t *testing.T) { diff --git a/driver/config/stub/.kratos.courier.channels.yaml b/driver/config/stub/.kratos.courier.channels.yaml index 9f4cdcd6de94..16b116ba276f 100644 --- a/driver/config/stub/.kratos.courier.channels.yaml +++ b/driver/config/stub/.kratos.courier.channels.yaml @@ -1,4 +1,6 @@ courier: + smtp: + connection_uri: smtp://username:password@smtp.example.com:587 channels: - id: phone request_config: