mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-13 02:58:11 +00:00
feat: add http as smtp provider (#8545)
# Which Problems Are Solved Send Email messages as a HTTP call to a relay, for own logic on handling different Email providers # How the Problems Are Solved Create endpoints under Email provider to manage SMTP and HTTP in the notification handlers. # Additional Changes Clean up old logic in command and query side to handle the general Email providers with deactivate, activate and remove. # Additional Context Partially closes #8270 --------- Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
@@ -28,19 +28,20 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
instance.SMTPConfigChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"instance_id": "instance-id",
|
||||
"resource_owner": "ro-id",
|
||||
"aggregate_id": "agg-id",
|
||||
"id": "config-id",
|
||||
"description": "test",
|
||||
"tls": true,
|
||||
"senderAddress": "sender",
|
||||
"senderName": "name",
|
||||
"replyToAddress": "reply-to",
|
||||
"host": "host",
|
||||
"user": "user",
|
||||
"id": "44444",
|
||||
"resource_owner": "ro-id",
|
||||
"instance_id": "instance-id"
|
||||
"user": "user"
|
||||
}`,
|
||||
),
|
||||
), instance.SMTPConfigChangedEventMapper),
|
||||
), eventstore.GenericEventMapper[instance.SMTPConfigChangedEvent]),
|
||||
},
|
||||
reduce: (&smtpConfigProjection{}).reduceSMTPConfigChanged,
|
||||
want: wantReduce{
|
||||
@@ -49,19 +50,233 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs2 SET (change_date, sequence, tls, sender_address, sender_name, reply_to_address, host, username, description) = ($1, $2, $3, $4, $5, $6, $7, $8, $9) WHERE (id = $10) AND (resource_owner = $11) AND (instance_id = $12)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs3 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"test",
|
||||
"config-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs3_smtp SET (tls, sender_address, sender_name, reply_to_address, host, username) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (instance_id = $8)",
|
||||
expectedArgs: []interface{}{
|
||||
true,
|
||||
"sender",
|
||||
"name",
|
||||
"reply-to",
|
||||
"host",
|
||||
"user",
|
||||
"config-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reduceSMTPConfigChanged, description",
|
||||
args: args{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SMTPConfigChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"instance_id": "instance-id",
|
||||
"resource_owner": "ro-id",
|
||||
"aggregate_id": "agg-id",
|
||||
"id": "config-id",
|
||||
"description": "test"
|
||||
}`,
|
||||
),
|
||||
), eventstore.GenericEventMapper[instance.SMTPConfigChangedEvent]),
|
||||
},
|
||||
reduce: (&smtpConfigProjection{}).reduceSMTPConfigChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs3 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"test",
|
||||
"44444",
|
||||
"ro-id",
|
||||
"config-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reduceSMTPConfigChanged, senderAddress",
|
||||
args: args{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SMTPConfigChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"instance_id": "instance-id",
|
||||
"resource_owner": "ro-id",
|
||||
"aggregate_id": "agg-id",
|
||||
"id": "config-id",
|
||||
"senderAddress": "sender"
|
||||
}`,
|
||||
),
|
||||
), eventstore.GenericEventMapper[instance.SMTPConfigChangedEvent]),
|
||||
},
|
||||
reduce: (&smtpConfigProjection{}).reduceSMTPConfigChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs3 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"config-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs3_smtp SET sender_address = $1 WHERE (id = $2) AND (instance_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"sender",
|
||||
"config-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reduceSMTPConfigHTTPChanged",
|
||||
args: args{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SMTPConfigHTTPChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"instance_id": "instance-id",
|
||||
"resource_owner": "ro-id",
|
||||
"aggregate_id": "agg-id",
|
||||
"id": "config-id",
|
||||
"description": "test",
|
||||
"endpoint": "endpoint"
|
||||
}`,
|
||||
),
|
||||
), eventstore.GenericEventMapper[instance.SMTPConfigHTTPChangedEvent]),
|
||||
},
|
||||
reduce: (&smtpConfigProjection{}).reduceSMTPConfigHTTPChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs3 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"test",
|
||||
"config-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs3_http SET endpoint = $1 WHERE (id = $2) AND (instance_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"endpoint",
|
||||
"config-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reduceSMTPConfigHTTPChanged, description",
|
||||
args: args{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SMTPConfigHTTPChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"instance_id": "instance-id",
|
||||
"resource_owner": "ro-id",
|
||||
"aggregate_id": "agg-id",
|
||||
"id": "config-id",
|
||||
"description": "test"
|
||||
}`,
|
||||
),
|
||||
), eventstore.GenericEventMapper[instance.SMTPConfigHTTPChangedEvent]),
|
||||
},
|
||||
reduce: (&smtpConfigProjection{}).reduceSMTPConfigHTTPChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs3 SET (change_date, sequence, description) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"test",
|
||||
"config-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reduceSMTPConfigHTTPChanged, endpoint",
|
||||
args: args{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SMTPConfigHTTPChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"instance_id": "instance-id",
|
||||
"resource_owner": "ro-id",
|
||||
"aggregate_id": "agg-id",
|
||||
"id": "config-id",
|
||||
"endpoint": "endpoint"
|
||||
}`,
|
||||
),
|
||||
), eventstore.GenericEventMapper[instance.SMTPConfigHTTPChangedEvent]),
|
||||
},
|
||||
reduce: (&smtpConfigProjection{}).reduceSMTPConfigHTTPChanged,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs3 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"config-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs3_http SET endpoint = $1 WHERE (id = $2) AND (instance_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"endpoint",
|
||||
"config-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
@@ -77,9 +292,12 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
instance.SMTPConfigAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"tls": true,
|
||||
"id": "id",
|
||||
"instance_id": "instance-id",
|
||||
"resource_owner": "ro-id",
|
||||
"aggregate_id": "agg-id",
|
||||
"id": "config-id",
|
||||
"description": "test",
|
||||
"tls": true,
|
||||
"senderAddress": "sender",
|
||||
"senderName": "name",
|
||||
"replyToAddress": "reply-to",
|
||||
@@ -91,7 +309,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
"keyId": "key-id"
|
||||
}
|
||||
}`),
|
||||
), instance.SMTPConfigAddedEventMapper),
|
||||
), eventstore.GenericEventMapper[instance.SMTPConfigAddedEvent]),
|
||||
},
|
||||
reduce: (&smtpConfigProjection{}).reduceSMTPConfigAdded,
|
||||
want: wantReduce{
|
||||
@@ -100,14 +318,24 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs2 (creation_date, change_date, resource_owner, instance_id, sequence, id, tls, sender_address, sender_name, reply_to_address, host, username, password, state, description) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)",
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs3 (creation_date, change_date, instance_id, resource_owner, aggregate_id, id, sequence, state, description) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
"ro-id",
|
||||
"agg-id",
|
||||
"config-id",
|
||||
uint64(15),
|
||||
"id",
|
||||
domain.SMTPConfigStateInactive,
|
||||
"test",
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs3_smtp (instance_id, id, tls, sender_address, sender_name, reply_to_address, host, username, password) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedArgs: []interface{}{
|
||||
"instance-id",
|
||||
"config-id",
|
||||
true,
|
||||
"sender",
|
||||
"name",
|
||||
@@ -115,10 +343,58 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
"host",
|
||||
"user",
|
||||
anyArg{},
|
||||
domain.SMTPConfigState(3),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "reduceSMTPConfigHTTPAdded",
|
||||
args: args{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
instance.SMTPConfigHTTPAddedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"instance_id": "instance-id",
|
||||
"resource_owner": "ro-id",
|
||||
"aggregate_id": "agg-id",
|
||||
"id": "config-id",
|
||||
"description": "test",
|
||||
"senderAddress": "sender",
|
||||
"endpoint": "endpoint"
|
||||
}`),
|
||||
), eventstore.GenericEventMapper[instance.SMTPConfigHTTPAddedEvent]),
|
||||
},
|
||||
reduce: (&smtpConfigProjection{}).reduceSMTPConfigHTTPAdded,
|
||||
want: wantReduce{
|
||||
aggregateType: eventstore.AggregateType("instance"),
|
||||
sequence: 15,
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs3 (creation_date, change_date, instance_id, resource_owner, aggregate_id, id, sequence, state, description) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
"instance-id",
|
||||
"ro-id",
|
||||
"agg-id",
|
||||
"config-id",
|
||||
uint64(15),
|
||||
domain.SMTPConfigStateInactive,
|
||||
"test",
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.smtp_configs3_http (instance_id, id, endpoint) VALUES ($1, $2, $3)",
|
||||
expectedArgs: []interface{}{
|
||||
"instance-id",
|
||||
"config-id",
|
||||
"endpoint",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -130,9 +406,12 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
instance.SMTPConfigActivatedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "config-id"
|
||||
"instance_id": "instance-id",
|
||||
"resource_owner": "ro-id",
|
||||
"aggregate_id": "agg-id",
|
||||
"id": "config-id"
|
||||
}`),
|
||||
), instance.SMTPConfigActivatedEventMapper),
|
||||
), eventstore.GenericEventMapper[instance.SMTPConfigActivatedEvent]),
|
||||
},
|
||||
reduce: (&smtpConfigProjection{}).reduceSMTPConfigActivated,
|
||||
want: wantReduce{
|
||||
@@ -141,13 +420,23 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs2 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (resource_owner = $5) AND (instance_id = $6)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs3 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (NOT (id = $4)) AND (state = $5) AND (instance_id = $6)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
domain.SMTPConfigStateInactive,
|
||||
"config-id",
|
||||
domain.SMTPConfigStateActive,
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs3 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
domain.SMTPConfigStateActive,
|
||||
"config-id",
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
@@ -162,9 +451,12 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
instance.SMTPConfigDeactivatedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "config-id"
|
||||
"instance_id": "instance-id",
|
||||
"resource_owner": "ro-id",
|
||||
"aggregate_id": "agg-id",
|
||||
"id": "config-id"
|
||||
}`),
|
||||
), instance.SMTPConfigDeactivatedEventMapper),
|
||||
), eventstore.GenericEventMapper[instance.SMTPConfigDeactivatedEvent]),
|
||||
},
|
||||
reduce: (&smtpConfigProjection{}).reduceSMTPConfigDeactivated,
|
||||
want: wantReduce{
|
||||
@@ -173,13 +465,12 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs2 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (resource_owner = $5) AND (instance_id = $6)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs3 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
domain.SMTPConfigStateInactive,
|
||||
"config-id",
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
@@ -195,14 +486,17 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
instance.SMTPConfigPasswordChangedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{
|
||||
"id": "config-id",
|
||||
"instance_id": "instance-id",
|
||||
"resource_owner": "ro-id",
|
||||
"aggregate_id": "agg-id",
|
||||
"id": "config-id",
|
||||
"password": {
|
||||
"cryptoType": 0,
|
||||
"algorithm": "RSA-265",
|
||||
"keyId": "key-id"
|
||||
}
|
||||
}`),
|
||||
), instance.SMTPConfigPasswordChangedEventMapper),
|
||||
), eventstore.GenericEventMapper[instance.SMTPConfigPasswordChangedEvent]),
|
||||
},
|
||||
reduce: (&smtpConfigProjection{}).reduceSMTPConfigPasswordChanged,
|
||||
want: wantReduce{
|
||||
@@ -211,13 +505,19 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs2 SET (change_date, sequence, password) = ($1, $2, $3) WHERE (id = $4) AND (resource_owner = $5) AND (instance_id = $6)",
|
||||
expectedStmt: "UPDATE projections.smtp_configs3_smtp SET password = $1 WHERE (id = $2) AND (instance_id = $3)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
"config-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedStmt: "UPDATE projections.smtp_configs3 SET (change_date, sequence) = ($1, $2) WHERE (id = $3) AND (instance_id = $4)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
anyArg{},
|
||||
"config-id",
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
@@ -231,8 +531,13 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
event: getEvent(testEvent(
|
||||
instance.SMTPConfigRemovedEventType,
|
||||
instance.AggregateType,
|
||||
[]byte(`{ "id": "config-id"}`),
|
||||
), instance.SMTPConfigRemovedEventMapper),
|
||||
[]byte(`{
|
||||
"instance_id": "instance-id",
|
||||
"resource_owner": "ro-id",
|
||||
"aggregate_id": "agg-id",
|
||||
"id": "config-id"
|
||||
}`),
|
||||
), eventstore.GenericEventMapper[instance.SMTPConfigRemovedEvent]),
|
||||
},
|
||||
reduce: (&smtpConfigProjection{}).reduceSMTPConfigRemoved,
|
||||
want: wantReduce{
|
||||
@@ -241,10 +546,9 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM projections.smtp_configs2 WHERE (id = $1) AND (resource_owner = $2) AND (instance_id = $3)",
|
||||
expectedStmt: "DELETE FROM projections.smtp_configs3 WHERE (id = $1) AND (instance_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"config-id",
|
||||
"ro-id",
|
||||
"instance-id",
|
||||
},
|
||||
},
|
||||
@@ -269,7 +573,7 @@ func TestSMTPConfigProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM projections.smtp_configs2 WHERE (instance_id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.smtp_configs3 WHERE (instance_id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
|
Reference in New Issue
Block a user