mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-16 10:45:12 +00:00
Merge commit from fork
* Add DenyLists parsing * Remove unneeded returned error * Plug global denylist into Command * app creation: apply denylist to backchannel logout URI * Inject denylist to backchannel logout worker * webhook config: validate against blocked URLs * Add notificationsWebhook denylist target * command: Add SMTP endpoint validation against blocklist * command: Add SMS endpoint validation against blocklist * Validate webhook endpoint against denylist on channel notification * Remove unused tests * handle deprecated denylists * remove unintended denylist entry in deprecated list * use single http client * fix tests * update comments * fixes * cleanup * address comments * fix merge --------- Co-authored-by: Livio Spring <[email protected]>
This commit is contained in:
@@ -38,7 +38,7 @@ func InitChannel(ctx context.Context, cfg Config) (channels.NotificationChannel,
|
||||
return err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
resp, err := cfg.Client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package set
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
CallURL string
|
||||
Client *http.Client
|
||||
}
|
||||
|
||||
func (w *Config) Validate() error {
|
||||
|
||||
@@ -48,7 +48,7 @@ func InitChannel(ctx context.Context, cfg Config) (channels.NotificationChannel,
|
||||
req.Header.Set(SigningHeader, actions.ComputeSignatureHeader(time.Now(), []byte(payload), cfg.SigningKey))
|
||||
}
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
resp, err := cfg.Client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ type Config struct {
|
||||
Method string
|
||||
Headers http.Header
|
||||
SigningKey string
|
||||
Client *http.Client
|
||||
}
|
||||
|
||||
func (w *Config) Validate() error {
|
||||
|
||||
@@ -3,6 +3,7 @@ package handlers
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/riverqueue/river"
|
||||
@@ -30,6 +31,7 @@ type BackChannelLogoutWorker struct {
|
||||
config *BackChannelLogoutWorkerConfig
|
||||
now nowFunc
|
||||
idGenerator id.Generator
|
||||
httpClient *http.Client
|
||||
}
|
||||
|
||||
// Timeout implements the Timeout-function of [river.Worker].
|
||||
@@ -97,7 +99,8 @@ func (w *BackChannelLogoutWorker) sendLogoutRequest(ctx context.Context, request
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = types.SendSecurityTokenEvent(ctx, set.Config{CallURL: request.BackChannelLogoutURI}, w.channels, &LogoutTokenMessage{LogoutToken: token}, request.TriggeringEventType).WithoutTemplate(); err != nil {
|
||||
backchannelNotifCfg := set.Config{CallURL: request.BackChannelLogoutURI, Client: w.httpClient}
|
||||
if err = types.SendSecurityTokenEvent(ctx, backchannelNotifCfg, w.channels, &LogoutTokenMessage{LogoutToken: token}, request.TriggeringEventType).WithoutTemplate(); err != nil {
|
||||
return err
|
||||
}
|
||||
return w.commands.BackChannelLogoutSent(ctx, request.SessionID, request.OIDCSessionID, request.Aggregate.InstanceID)
|
||||
@@ -129,6 +132,7 @@ func NewBackChannelLogoutWorker(
|
||||
config *BackChannelLogoutWorkerConfig,
|
||||
|
||||
idGenerator id.Generator,
|
||||
httpClient *http.Client,
|
||||
) *BackChannelLogoutWorker {
|
||||
return &BackChannelLogoutWorker{
|
||||
commands: commands,
|
||||
@@ -139,6 +143,7 @@ func NewBackChannelLogoutWorker(
|
||||
config: config,
|
||||
now: time.Now,
|
||||
idGenerator: idGenerator,
|
||||
httpClient: httpClient,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -439,6 +439,7 @@ func newBackChannelLogoutWorker(queries Queries, commands Commands, es *eventsto
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
eventstore: es,
|
||||
queue: queue,
|
||||
|
||||
@@ -36,6 +36,7 @@ func (n *NotificationQueries) GetActiveEmailConfig(ctx context.Context) (*email.
|
||||
Method: http.MethodPost,
|
||||
Headers: nil,
|
||||
SigningKey: config.HTTPConfig.SigningKey,
|
||||
Client: n.httpClient,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -11,33 +13,41 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/notification/channels/email"
|
||||
"github.com/zitadel/zitadel/internal/notification/channels/smtp"
|
||||
"github.com/zitadel/zitadel/internal/notification/channels/webhook"
|
||||
"github.com/zitadel/zitadel/internal/notification/handlers/mock"
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
func TestNotificationQueries_GetActiveEmailConfig(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
t.Parallel()
|
||||
const instId = "instance-1"
|
||||
const cryptAlg = "alg1"
|
||||
const keyId = "key1"
|
||||
const pwd = "password"
|
||||
const clientSecret = "client-secret"
|
||||
|
||||
encryptedPwd := []byte("password-encrypted")
|
||||
cryptAlgMock := crypto.NewMockEncryptionAlgorithm(ctrl)
|
||||
cryptAlgMock.EXPECT().DecryptString(gomock.Any(), gomock.Any()).Return(pwd, nil)
|
||||
cryptAlgMock.EXPECT().Algorithm().Return(cryptAlg)
|
||||
cryptAlgMock.EXPECT().DecryptionKeyIDs().Return([]string{keyId})
|
||||
encryptedClientSecret := []byte("client-secret-encrypted")
|
||||
|
||||
var (
|
||||
errDecryptionFailed = errors.New("decryption failed")
|
||||
errDatabaseError = errors.New("database error")
|
||||
)
|
||||
|
||||
tt := []struct {
|
||||
smtpConfig *query.SMTPConfig
|
||||
expected *email.Config
|
||||
name string
|
||||
smtpConfig *query.SMTPConfig
|
||||
smtpConfigErr error
|
||||
setupCrypto func(m *crypto.MockEncryptionAlgorithm)
|
||||
expected *email.Config
|
||||
expectedErr error
|
||||
}{
|
||||
{
|
||||
name: "smtp config with plain auth (user and password)",
|
||||
smtpConfig: &query.SMTPConfig{
|
||||
ID: "smtp1",
|
||||
Description: "smtp config with authentication (user and password)",
|
||||
Description: "smtp config with plain auth (user and password)",
|
||||
SMTPConfig: &query.SMTP{
|
||||
TLS: true,
|
||||
SenderAddress: "[email protected]",
|
||||
@@ -55,10 +65,15 @@ func TestNotificationQueries_GetActiveEmailConfig(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
setupCrypto: func(m *crypto.MockEncryptionAlgorithm) {
|
||||
m.EXPECT().Algorithm().Return(cryptAlg)
|
||||
m.EXPECT().DecryptionKeyIDs().Return([]string{keyId})
|
||||
m.EXPECT().DecryptString(gomock.Any(), gomock.Any()).Return(pwd, nil)
|
||||
},
|
||||
expected: &email.Config{
|
||||
ProviderConfig: &email.Provider{
|
||||
ID: "smtp1",
|
||||
Description: "smtp config with authentication (user and password)",
|
||||
Description: "smtp config with plain auth (user and password)",
|
||||
},
|
||||
SMTPConfig: &smtp.Config{
|
||||
SMTP: smtp.SMTP{
|
||||
@@ -76,9 +91,10 @@ func TestNotificationQueries_GetActiveEmailConfig(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "smtp config with user but no plain auth config (fallback to plain auth without password)",
|
||||
smtpConfig: &query.SMTPConfig{
|
||||
ID: "smtp2",
|
||||
Description: "smtp config with authentication (user and no password)",
|
||||
Description: "smtp config with user but no plain auth config (fallback to plain auth without password)",
|
||||
SMTPConfig: &query.SMTP{
|
||||
TLS: true,
|
||||
SenderAddress: "[email protected]",
|
||||
@@ -91,7 +107,7 @@ func TestNotificationQueries_GetActiveEmailConfig(t *testing.T) {
|
||||
expected: &email.Config{
|
||||
ProviderConfig: &email.Provider{
|
||||
ID: "smtp2",
|
||||
Description: "smtp config with authentication (user and no password)",
|
||||
Description: "smtp config with user but no plain auth config (fallback to plain auth without password)",
|
||||
},
|
||||
SMTPConfig: &smtp.Config{
|
||||
SMTP: smtp.SMTP{
|
||||
@@ -108,6 +124,7 @@ func TestNotificationQueries_GetActiveEmailConfig(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "smtp config without authentication",
|
||||
smtpConfig: &query.SMTPConfig{
|
||||
ID: "smtp3",
|
||||
Description: "smtp config without authentication",
|
||||
@@ -135,18 +152,205 @@ func TestNotificationQueries_GetActiveEmailConfig(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "smtp config with xoauth2 auth and client credentials",
|
||||
smtpConfig: &query.SMTPConfig{
|
||||
ID: "smtp4",
|
||||
Description: "smtp config with xoauth2 auth and client credentials",
|
||||
SMTPConfig: &query.SMTP{
|
||||
SenderAddress: "[email protected]",
|
||||
SenderName: "sender",
|
||||
Host: "mail.com",
|
||||
User: "mail-user",
|
||||
XOAuth2Auth: &query.XOAuth2Auth{
|
||||
TokenEndpoint: "https://token.example.com/token",
|
||||
Scopes: []string{"https://mail.example.com/.default"},
|
||||
ClientCredentials: &query.XOAuthClientCredentials{
|
||||
ClientId: "client-id",
|
||||
ClientSecret: &crypto.CryptoValue{
|
||||
Algorithm: cryptAlg,
|
||||
KeyID: keyId,
|
||||
Crypted: encryptedClientSecret,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
setupCrypto: func(m *crypto.MockEncryptionAlgorithm) {
|
||||
m.EXPECT().Algorithm().Return(cryptAlg)
|
||||
m.EXPECT().DecryptionKeyIDs().Return([]string{keyId})
|
||||
m.EXPECT().DecryptString(gomock.Any(), gomock.Any()).Return(clientSecret, nil)
|
||||
},
|
||||
expected: &email.Config{
|
||||
ProviderConfig: &email.Provider{
|
||||
ID: "smtp4",
|
||||
Description: "smtp config with xoauth2 auth and client credentials",
|
||||
},
|
||||
SMTPConfig: &smtp.Config{
|
||||
SMTP: smtp.SMTP{
|
||||
Host: "mail.com",
|
||||
XOAuth2Auth: &smtp.XOAuth2AuthConfig{
|
||||
User: "mail-user",
|
||||
TokenEndpoint: "https://token.example.com/token",
|
||||
Scopes: []string{"https://mail.example.com/.default"},
|
||||
ClientCredentialsAuth: &smtp.OAuth2ClientCredentials{
|
||||
ClientId: "client-id",
|
||||
ClientSecret: clientSecret,
|
||||
},
|
||||
},
|
||||
},
|
||||
From: "[email protected]",
|
||||
FromName: "sender",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "smtp config with xoauth2 auth without client credentials",
|
||||
smtpConfig: &query.SMTPConfig{
|
||||
ID: "smtp5",
|
||||
Description: "smtp config with xoauth2 auth without client credentials",
|
||||
SMTPConfig: &query.SMTP{
|
||||
SenderAddress: "[email protected]",
|
||||
SenderName: "sender",
|
||||
Host: "mail.com",
|
||||
User: "mail-user",
|
||||
XOAuth2Auth: &query.XOAuth2Auth{
|
||||
TokenEndpoint: "https://token.example.com/token",
|
||||
Scopes: []string{"scope1"},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: &email.Config{
|
||||
ProviderConfig: &email.Provider{
|
||||
ID: "smtp5",
|
||||
Description: "smtp config with xoauth2 auth without client credentials",
|
||||
},
|
||||
SMTPConfig: &smtp.Config{
|
||||
SMTP: smtp.SMTP{
|
||||
Host: "mail.com",
|
||||
XOAuth2Auth: &smtp.XOAuth2AuthConfig{
|
||||
User: "mail-user",
|
||||
TokenEndpoint: "https://token.example.com/token",
|
||||
Scopes: []string{"scope1"},
|
||||
},
|
||||
},
|
||||
From: "[email protected]",
|
||||
FromName: "sender",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "plain auth password decryption error",
|
||||
smtpConfig: &query.SMTPConfig{
|
||||
ID: "smtp6",
|
||||
Description: "plain auth password decryption error",
|
||||
SMTPConfig: &query.SMTP{
|
||||
Host: "mail.com",
|
||||
User: "mail-user",
|
||||
PlainAuth: &query.PlainAuth{
|
||||
Password: &crypto.CryptoValue{
|
||||
Algorithm: cryptAlg,
|
||||
KeyID: keyId,
|
||||
Crypted: encryptedPwd,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
setupCrypto: func(m *crypto.MockEncryptionAlgorithm) {
|
||||
m.EXPECT().Algorithm().Return(cryptAlg)
|
||||
m.EXPECT().DecryptionKeyIDs().Return([]string{keyId})
|
||||
m.EXPECT().DecryptString(gomock.Any(), gomock.Any()).Return("", errDecryptionFailed)
|
||||
},
|
||||
expectedErr: errDecryptionFailed,
|
||||
},
|
||||
{
|
||||
name: "xoauth2 client credentials decryption error",
|
||||
smtpConfig: &query.SMTPConfig{
|
||||
ID: "smtp7",
|
||||
Description: "xoauth2 client credentials decryption error",
|
||||
SMTPConfig: &query.SMTP{
|
||||
Host: "mail.com",
|
||||
User: "mail-user",
|
||||
XOAuth2Auth: &query.XOAuth2Auth{
|
||||
TokenEndpoint: "https://token.example.com/token",
|
||||
ClientCredentials: &query.XOAuthClientCredentials{
|
||||
ClientId: "client-id",
|
||||
ClientSecret: &crypto.CryptoValue{
|
||||
CryptoType: 0,
|
||||
Algorithm: cryptAlg,
|
||||
KeyID: keyId,
|
||||
Crypted: encryptedClientSecret,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
setupCrypto: func(m *crypto.MockEncryptionAlgorithm) {
|
||||
m.EXPECT().Algorithm().Return(cryptAlg)
|
||||
m.EXPECT().DecryptionKeyIDs().Return([]string{keyId})
|
||||
m.EXPECT().DecryptString(gomock.Any(), gomock.Any()).Return("", errDecryptionFailed)
|
||||
},
|
||||
expectedErr: errDecryptionFailed,
|
||||
},
|
||||
{
|
||||
name: "http webhook config",
|
||||
smtpConfig: &query.SMTPConfig{
|
||||
ID: "http1",
|
||||
Description: "http webhook config",
|
||||
HTTPConfig: &query.HTTP{
|
||||
Endpoint: "https://example.com/notify",
|
||||
SigningKey: "my-signing-key",
|
||||
},
|
||||
},
|
||||
expected: &email.Config{
|
||||
ProviderConfig: &email.Provider{
|
||||
ID: "http1",
|
||||
Description: "http webhook config",
|
||||
},
|
||||
WebhookConfig: &webhook.Config{
|
||||
CallURL: "https://example.com/notify",
|
||||
Method: http.MethodPost,
|
||||
SigningKey: "my-signing-key",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "neither smtp nor http config set",
|
||||
smtpConfig: &query.SMTPConfig{
|
||||
ID: "smtp8",
|
||||
Description: "neither smtp nor http config set",
|
||||
},
|
||||
expectedErr: zerrors.ThrowNotFound(nil, "", ""),
|
||||
},
|
||||
{
|
||||
name: "SMTPConfigActive query error",
|
||||
smtpConfigErr: errDatabaseError,
|
||||
expectedErr: errDatabaseError,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.smtpConfig.Description, func(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctrl := gomock.NewController(t)
|
||||
ctx := authz.NewMockContext(instId, "org-1", "user-1")
|
||||
|
||||
queryMock := mock.NewMockQueries(ctrl)
|
||||
queryMock.EXPECT().SMTPConfigActive(gomock.Any(), instId).Return(tc.smtpConfig, nil)
|
||||
cryptAlgMock := crypto.NewMockEncryptionAlgorithm(ctrl)
|
||||
if tc.setupCrypto != nil {
|
||||
tc.setupCrypto(cryptAlgMock)
|
||||
}
|
||||
|
||||
notificationQueries := NewNotificationQueries(queryMock, &eventstore.Eventstore{}, "ext domain", uint16(1234), false, "filepath", nil, cryptAlgMock, nil)
|
||||
queryMock := mock.NewMockQueries(ctrl)
|
||||
queryMock.EXPECT().SMTPConfigActive(gomock.Any(), instId).Return(tc.smtpConfig, tc.smtpConfigErr)
|
||||
|
||||
notificationQueries := NewNotificationQueries(queryMock, &eventstore.Eventstore{}, "ext domain", uint16(1234), false, "filepath", nil, cryptAlgMock, nil, nil)
|
||||
cfg, err := notificationQueries.GetActiveEmailConfig(ctx)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.ErrorIs(t, err, tc.expectedErr)
|
||||
if tc.expectedErr != nil {
|
||||
return
|
||||
}
|
||||
|
||||
assert.EqualValues(t, tc.expected, cfg)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ func (n *NotificationQueries) GetActiveSMSConfig(ctx context.Context) (*sms.Conf
|
||||
Method: http.MethodPost,
|
||||
Headers: nil,
|
||||
SigningKey: config.HTTPConfig.SigningKey,
|
||||
Client: n.httpClient,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/mock/gomock"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/authz"
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/notification/channels/sms"
|
||||
"github.com/zitadel/zitadel/internal/notification/channels/twilio"
|
||||
"github.com/zitadel/zitadel/internal/notification/channels/webhook"
|
||||
"github.com/zitadel/zitadel/internal/notification/handlers/mock"
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
func TestNotificationQueries_GetActiveSMSConfig(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const instId = "instance-1"
|
||||
const cryptAlg = "alg1"
|
||||
const keyId = "key1"
|
||||
const token = "twilio-token"
|
||||
|
||||
encryptedToken := []byte("twilio-token-encrypted")
|
||||
|
||||
var (
|
||||
errDecryptionFailed = errors.New("decryption failed")
|
||||
errDatabaseError = errors.New("database error")
|
||||
)
|
||||
|
||||
tt := []struct {
|
||||
name string
|
||||
smsConfig *query.SMSConfig
|
||||
smsConfigErr error
|
||||
setupCrypto func(m *crypto.MockEncryptionAlgorithm)
|
||||
expected *sms.Config
|
||||
expectedErr error
|
||||
}{
|
||||
{
|
||||
name: "twilio config with token",
|
||||
smsConfig: &query.SMSConfig{
|
||||
ID: "twilio1",
|
||||
Description: "twilio config with token",
|
||||
TwilioConfig: &query.Twilio{
|
||||
SID: "sid-1",
|
||||
SenderNumber: "+10005550100",
|
||||
VerifyServiceSID: "verify-sid-1",
|
||||
Token: &crypto.CryptoValue{
|
||||
Algorithm: cryptAlg,
|
||||
KeyID: keyId,
|
||||
Crypted: encryptedToken,
|
||||
},
|
||||
},
|
||||
},
|
||||
setupCrypto: func(m *crypto.MockEncryptionAlgorithm) {
|
||||
m.EXPECT().Algorithm().Return(cryptAlg)
|
||||
m.EXPECT().DecryptionKeyIDs().Return([]string{keyId})
|
||||
m.EXPECT().DecryptString(gomock.Any(), gomock.Any()).Return(token, nil)
|
||||
},
|
||||
expected: &sms.Config{
|
||||
ProviderConfig: &sms.Provider{
|
||||
ID: "twilio1",
|
||||
Description: "twilio config with token",
|
||||
},
|
||||
TwilioConfig: &twilio.Config{
|
||||
SID: "sid-1",
|
||||
Token: token,
|
||||
SenderNumber: "+10005550100",
|
||||
VerifyServiceSID: "verify-sid-1",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "twilio config with nil token",
|
||||
smsConfig: &query.SMSConfig{
|
||||
ID: "twilio2",
|
||||
Description: "twilio config with nil token",
|
||||
TwilioConfig: &query.Twilio{
|
||||
SID: "sid-2",
|
||||
SenderNumber: "+10005550100",
|
||||
},
|
||||
},
|
||||
expectedErr: zerrors.ThrowNotFound(nil, "", ""),
|
||||
},
|
||||
{
|
||||
name: "twilio token decryption error",
|
||||
smsConfig: &query.SMSConfig{
|
||||
ID: "twilio3",
|
||||
Description: "twilio token decryption error",
|
||||
TwilioConfig: &query.Twilio{
|
||||
SID: "sid-3",
|
||||
SenderNumber: "+10005550100",
|
||||
Token: &crypto.CryptoValue{
|
||||
Algorithm: cryptAlg,
|
||||
KeyID: keyId,
|
||||
Crypted: encryptedToken,
|
||||
},
|
||||
},
|
||||
},
|
||||
setupCrypto: func(m *crypto.MockEncryptionAlgorithm) {
|
||||
m.EXPECT().Algorithm().Return(cryptAlg)
|
||||
m.EXPECT().DecryptionKeyIDs().Return([]string{keyId})
|
||||
m.EXPECT().DecryptString(gomock.Any(), gomock.Any()).Return("", errDecryptionFailed)
|
||||
},
|
||||
expectedErr: errDecryptionFailed,
|
||||
},
|
||||
{
|
||||
name: "http webhook config",
|
||||
smsConfig: &query.SMSConfig{
|
||||
ID: "http1",
|
||||
Description: "http webhook config",
|
||||
HTTPConfig: &query.HTTP{
|
||||
Endpoint: "https://example.com/sms",
|
||||
SigningKey: "my-signing-key",
|
||||
},
|
||||
},
|
||||
expected: &sms.Config{
|
||||
ProviderConfig: &sms.Provider{
|
||||
ID: "http1",
|
||||
Description: "http webhook config",
|
||||
},
|
||||
WebhookConfig: &webhook.Config{
|
||||
CallURL: "https://example.com/sms",
|
||||
Method: http.MethodPost,
|
||||
Headers: nil,
|
||||
SigningKey: "my-signing-key",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "neither twilio nor http config set",
|
||||
smsConfig: &query.SMSConfig{
|
||||
ID: "sms1",
|
||||
Description: "neither twilio nor http config set",
|
||||
},
|
||||
expectedErr: zerrors.ThrowNotFound(nil, "", ""),
|
||||
},
|
||||
{
|
||||
name: "SMSProviderConfigActive query error",
|
||||
smsConfigErr: errDatabaseError,
|
||||
expectedErr: errDatabaseError,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctrl := gomock.NewController(t)
|
||||
ctx := authz.NewMockContext(instId, "org-1", "user-1")
|
||||
|
||||
cryptAlgMock := crypto.NewMockEncryptionAlgorithm(ctrl)
|
||||
if tc.setupCrypto != nil {
|
||||
tc.setupCrypto(cryptAlgMock)
|
||||
}
|
||||
|
||||
queryMock := mock.NewMockQueries(ctrl)
|
||||
queryMock.EXPECT().SMSProviderConfigActive(gomock.Any(), instId).Return(tc.smsConfig, tc.smsConfigErr)
|
||||
|
||||
notificationQueries := NewNotificationQueries(queryMock, &eventstore.Eventstore{}, "ext domain", uint16(1234), false, "filepath", nil, nil, cryptAlgMock, nil)
|
||||
cfg, err := notificationQueries.GetActiveSMSConfig(ctx)
|
||||
|
||||
assert.ErrorIs(t, err, tc.expectedErr)
|
||||
if tc.expectedErr != nil {
|
||||
return
|
||||
}
|
||||
|
||||
assert.EqualValues(t, tc.expected, cfg)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -433,6 +433,7 @@ func newNotificationWorker(t *testing.T, ctrl *gomock.Controller, queries *mock.
|
||||
f.userDataCrypto,
|
||||
smtpAlg,
|
||||
f.SMSTokenCrypto,
|
||||
nil,
|
||||
),
|
||||
channels: ¬ificationChannels{
|
||||
Chain: *senders.ChainChannels(channel),
|
||||
|
||||
@@ -2,6 +2,7 @@ package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-jose/go-jose/v4"
|
||||
"golang.org/x/text/language"
|
||||
@@ -44,6 +45,7 @@ type NotificationQueries struct {
|
||||
UserDataCrypto crypto.EncryptionAlgorithm
|
||||
SMTPPasswordCrypto crypto.EncryptionAlgorithm
|
||||
SMSTokenCrypto crypto.EncryptionAlgorithm
|
||||
httpClient *http.Client
|
||||
}
|
||||
|
||||
func NewNotificationQueries(
|
||||
@@ -56,6 +58,7 @@ func NewNotificationQueries(
|
||||
userDataCrypto crypto.EncryptionAlgorithm,
|
||||
smtpPasswordCrypto crypto.EncryptionAlgorithm,
|
||||
smsTokenCrypto crypto.EncryptionAlgorithm,
|
||||
httpClient *http.Client,
|
||||
) *NotificationQueries {
|
||||
return &NotificationQueries{
|
||||
Queries: baseQueries,
|
||||
@@ -67,5 +70,6 @@ func NewNotificationQueries(
|
||||
UserDataCrypto: userDataCrypto,
|
||||
SMTPPasswordCrypto: smtpPasswordCrypto,
|
||||
SMSTokenCrypto: smsTokenCrypto,
|
||||
httpClient: httpClient,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ func (u *quotaNotifier) reduceNotificationDue(event eventstore.Event) (*handler.
|
||||
if alreadyHandled {
|
||||
return nil
|
||||
}
|
||||
err = types.SendJSON(ctx, webhook.Config{CallURL: e.CallURL, Method: http.MethodPost}, u.channels, e, e.Type()).WithoutTemplate()
|
||||
err = types.SendJSON(ctx, webhook.Config{CallURL: e.CallURL, Method: http.MethodPost, Client: u.queries.httpClient}, u.channels, e, e.Type()).WithoutTemplate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ func (t *telemetryPusher) pushMilestone(ctx context.Context, e *milestone.Reache
|
||||
CallURL: endpoint,
|
||||
Method: http.MethodPost,
|
||||
Headers: t.cfg.Headers,
|
||||
Client: t.queries.httpClient,
|
||||
},
|
||||
t.channels,
|
||||
&struct {
|
||||
|
||||
@@ -1972,6 +1972,7 @@ func newUserNotifierLegacy(t *testing.T, ctrl *gomock.Controller, queries *mock.
|
||||
f.userDataCrypto,
|
||||
smtpAlg,
|
||||
f.SMSTokenCrypto,
|
||||
nil,
|
||||
),
|
||||
otpEmailTmpl: func(origin *url.URL) string {
|
||||
return origin.String() + defaultOTPEmailTemplate
|
||||
|
||||
@@ -1936,6 +1936,7 @@ func newUserNotifier(t *testing.T, ctrl *gomock.Controller, queries *mock.MockQu
|
||||
f.userDataCrypto,
|
||||
smtpAlg,
|
||||
f.SMSTokenCrypto,
|
||||
nil,
|
||||
),
|
||||
otpEmailTmpl: func(origin *url.URL) string {
|
||||
return origin.String() + defaultOTPEmailTemplate
|
||||
|
||||
@@ -3,6 +3,7 @@ package notification
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/zitadel/logging"
|
||||
@@ -40,6 +41,7 @@ func Register(
|
||||
fileSystemPath string,
|
||||
userEncryption, smtpEncryption, smsEncryption crypto.EncryptionAlgorithm,
|
||||
queue *queue.Queue,
|
||||
httpClient *http.Client,
|
||||
) {
|
||||
if !notificationWorkerConfig.LegacyEnabled {
|
||||
queue.ShouldStart()
|
||||
@@ -48,7 +50,7 @@ func Register(
|
||||
// make sure the slice does not contain old values
|
||||
projections = nil
|
||||
|
||||
q := handlers.NewNotificationQueries(queries, es, externalDomain, externalPort, externalSecure, fileSystemPath, userEncryption, smtpEncryption, smsEncryption)
|
||||
q := handlers.NewNotificationQueries(queries, es, externalDomain, externalPort, externalSecure, fileSystemPath, userEncryption, smtpEncryption, smsEncryption, httpClient)
|
||||
c := newChannels(q)
|
||||
projections = append(projections, handlers.NewUserNotifier(ctx, projection.ApplyCustomConfig(userHandlerCustomConfig), commands, q, c, otpEmailTmpl, notificationWorkerConfig, queue))
|
||||
projections = append(projections, handlers.NewQuotaNotifier(ctx, projection.ApplyCustomConfig(quotaHandlerCustomConfig), commands, q, c))
|
||||
@@ -59,7 +61,16 @@ func Register(
|
||||
queue,
|
||||
backChannelLogoutWorkerConfig.MaxAttempts,
|
||||
))
|
||||
queue.AddWorkers(ctx, handlers.NewBackChannelLogoutWorker(commands, q, es, queue, c, backChannelLogoutWorkerConfig, id.SonyFlakeGenerator()))
|
||||
queue.AddWorkers(ctx, handlers.NewBackChannelLogoutWorker(
|
||||
commands,
|
||||
q,
|
||||
es,
|
||||
queue,
|
||||
c,
|
||||
backChannelLogoutWorkerConfig,
|
||||
id.SonyFlakeGenerator(),
|
||||
httpClient,
|
||||
))
|
||||
if telemetryCfg.Enabled {
|
||||
projections = append(projections, handlers.NewTelemetryPusher(ctx, telemetryCfg, projection.ApplyCustomConfig(telemetryHandlerCustomConfig), commands, q, c))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user