mirror of
https://github.com/zitadel/zitadel.git
synced 2025-07-11 13:38:33 +00:00

This PR summarizes multiple changes specifically only available with ZITADEL v3: - feat: Web Keys management (https://github.com/zitadel/zitadel/pull/9526) - fix(cmd): ensure proper working of mirror (https://github.com/zitadel/zitadel/pull/9509) - feat(Authz): system user support for permission check v2 (https://github.com/zitadel/zitadel/pull/9640) - chore(license): change from Apache to AGPL (https://github.com/zitadel/zitadel/pull/9597) - feat(console): list v2 sessions (https://github.com/zitadel/zitadel/pull/9539) - fix(console): add loginV2 feature flag (https://github.com/zitadel/zitadel/pull/9682) - fix(feature flags): allow reading "own" flags (https://github.com/zitadel/zitadel/pull/9649) - feat(console): add Actions V2 UI (https://github.com/zitadel/zitadel/pull/9591) BREAKING CHANGE - feat(webkey): migrate to v2beta API (https://github.com/zitadel/zitadel/pull/9445) - chore!: remove CockroachDB Support (https://github.com/zitadel/zitadel/pull/9444) - feat(actions): migrate to v2beta API (https://github.com/zitadel/zitadel/pull/9489) --------- Co-authored-by: Livio Spring <livio.a@gmail.com> Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com> Co-authored-by: Silvan <27845747+adlerhurst@users.noreply.github.com> Co-authored-by: Ramon <mail@conblem.me> Co-authored-by: Elio Bischof <elio@zitadel.com> Co-authored-by: Kenta Yamaguchi <56732734+KEY60228@users.noreply.github.com> Co-authored-by: Harsha Reddy <harsha.reddy@klaviyo.com> Co-authored-by: Livio Spring <livio@zitadel.com> Co-authored-by: Max Peintner <max@caos.ch> Co-authored-by: Iraq <66622793+kkrime@users.noreply.github.com> Co-authored-by: Florian Forster <florian@zitadel.com> Co-authored-by: Tim Möhlmann <tim+github@zitadel.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Max Peintner <peintnerm@gmail.com>
293 lines
6.9 KiB
Go
293 lines
6.9 KiB
Go
package query
|
|
|
|
import (
|
|
"database/sql"
|
|
"database/sql/driver"
|
|
"errors"
|
|
"fmt"
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/zitadel/zitadel/internal/crypto"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
var (
|
|
prepareSMTPConfigStmt = `SELECT projections.smtp_configs5.creation_date,` +
|
|
` projections.smtp_configs5.change_date,` +
|
|
` projections.smtp_configs5.resource_owner,` +
|
|
` projections.smtp_configs5.sequence,` +
|
|
` projections.smtp_configs5.id,` +
|
|
` projections.smtp_configs5.state,` +
|
|
` projections.smtp_configs5.description,` +
|
|
` projections.smtp_configs5_smtp.id,` +
|
|
` projections.smtp_configs5_smtp.tls,` +
|
|
` projections.smtp_configs5_smtp.sender_address,` +
|
|
` projections.smtp_configs5_smtp.sender_name,` +
|
|
` projections.smtp_configs5_smtp.reply_to_address,` +
|
|
` projections.smtp_configs5_smtp.host,` +
|
|
` projections.smtp_configs5_smtp.username,` +
|
|
` projections.smtp_configs5_smtp.password,` +
|
|
` projections.smtp_configs5_http.id,` +
|
|
` projections.smtp_configs5_http.endpoint` +
|
|
` FROM projections.smtp_configs5` +
|
|
` LEFT JOIN projections.smtp_configs5_smtp ON projections.smtp_configs5.id = projections.smtp_configs5_smtp.id AND projections.smtp_configs5.instance_id = projections.smtp_configs5_smtp.instance_id` +
|
|
` LEFT JOIN projections.smtp_configs5_http ON projections.smtp_configs5.id = projections.smtp_configs5_http.id AND projections.smtp_configs5.instance_id = projections.smtp_configs5_http.instance_id`
|
|
prepareSMTPConfigCols = []string{
|
|
"creation_date",
|
|
"change_date",
|
|
"resource_owner",
|
|
"sequence",
|
|
"id",
|
|
"state",
|
|
"description",
|
|
"id",
|
|
"tls",
|
|
"sender_address",
|
|
"sender_name",
|
|
"reply_to_address",
|
|
"smtp_host",
|
|
"smtp_user",
|
|
"smtp_password",
|
|
"id",
|
|
"endpoint",
|
|
}
|
|
)
|
|
|
|
func Test_SMTPConfigsPrepares(t *testing.T) {
|
|
type want struct {
|
|
sqlExpectations sqlExpectation
|
|
err checkErr
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
prepare interface{}
|
|
want want
|
|
object interface{}
|
|
}{
|
|
{
|
|
name: "prepareSMTPConfigQuery no result",
|
|
prepare: prepareSMTPConfigQuery,
|
|
want: want{
|
|
sqlExpectations: mockQueriesScanErr(
|
|
prepareSMTPConfigStmt,
|
|
nil,
|
|
nil,
|
|
),
|
|
err: func(err error) (error, bool) {
|
|
if !zerrors.IsNotFound(err) {
|
|
return fmt.Errorf("err should be zitadel.NotFoundError got: %w", err), false
|
|
}
|
|
return nil, true
|
|
},
|
|
},
|
|
object: (*SMTPConfig)(nil),
|
|
},
|
|
{
|
|
name: "prepareSMTPConfigQuery found",
|
|
prepare: prepareSMTPConfigQuery,
|
|
want: want{
|
|
sqlExpectations: mockQuery(
|
|
regexp.QuoteMeta(prepareSMTPConfigStmt),
|
|
prepareSMTPConfigCols,
|
|
[]driver.Value{
|
|
testNow,
|
|
testNow,
|
|
"ro",
|
|
uint64(20211108),
|
|
"2232323",
|
|
domain.SMTPConfigStateActive,
|
|
"test",
|
|
"2232323",
|
|
true,
|
|
"sender",
|
|
"name",
|
|
"reply-to",
|
|
"host",
|
|
"user",
|
|
&crypto.CryptoValue{},
|
|
nil,
|
|
nil,
|
|
},
|
|
),
|
|
},
|
|
object: &SMTPConfig{
|
|
CreationDate: testNow,
|
|
ChangeDate: testNow,
|
|
ResourceOwner: "ro",
|
|
Sequence: 20211108,
|
|
SMTPConfig: &SMTP{
|
|
TLS: true,
|
|
SenderAddress: "sender",
|
|
SenderName: "name",
|
|
ReplyToAddress: "reply-to",
|
|
Host: "host",
|
|
User: "user",
|
|
Password: &crypto.CryptoValue{},
|
|
},
|
|
ID: "2232323",
|
|
State: domain.SMTPConfigStateActive,
|
|
Description: "test",
|
|
},
|
|
},
|
|
{
|
|
name: "prepareSMTPConfigQuery found, http",
|
|
prepare: prepareSMTPConfigQuery,
|
|
want: want{
|
|
sqlExpectations: mockQuery(
|
|
regexp.QuoteMeta(prepareSMTPConfigStmt),
|
|
prepareSMTPConfigCols,
|
|
[]driver.Value{
|
|
testNow,
|
|
testNow,
|
|
"ro",
|
|
uint64(20211108),
|
|
"2232323",
|
|
domain.SMTPConfigStateActive,
|
|
"test",
|
|
nil,
|
|
nil,
|
|
nil,
|
|
nil,
|
|
nil,
|
|
nil,
|
|
nil,
|
|
nil,
|
|
"2232323",
|
|
"endpoint",
|
|
},
|
|
),
|
|
},
|
|
object: &SMTPConfig{
|
|
CreationDate: testNow,
|
|
ChangeDate: testNow,
|
|
ResourceOwner: "ro",
|
|
Sequence: 20211108,
|
|
HTTPConfig: &HTTP{
|
|
Endpoint: "endpoint",
|
|
},
|
|
ID: "2232323",
|
|
State: domain.SMTPConfigStateActive,
|
|
Description: "test",
|
|
},
|
|
},
|
|
{
|
|
name: "prepareSMTPConfigQuery another config found",
|
|
prepare: prepareSMTPConfigQuery,
|
|
want: want{
|
|
sqlExpectations: mockQuery(
|
|
regexp.QuoteMeta(prepareSMTPConfigStmt),
|
|
prepareSMTPConfigCols,
|
|
[]driver.Value{
|
|
testNow,
|
|
testNow,
|
|
"ro",
|
|
uint64(20211109),
|
|
"44442323",
|
|
domain.SMTPConfigStateInactive,
|
|
"test2",
|
|
"44442323",
|
|
true,
|
|
"sender2",
|
|
"name2",
|
|
"reply-to2",
|
|
"host2",
|
|
"user2",
|
|
&crypto.CryptoValue{},
|
|
nil,
|
|
nil,
|
|
},
|
|
),
|
|
},
|
|
object: &SMTPConfig{
|
|
CreationDate: testNow,
|
|
ChangeDate: testNow,
|
|
ResourceOwner: "ro",
|
|
Sequence: 20211109,
|
|
SMTPConfig: &SMTP{
|
|
TLS: true,
|
|
SenderAddress: "sender2",
|
|
SenderName: "name2",
|
|
ReplyToAddress: "reply-to2",
|
|
Host: "host2",
|
|
User: "user2",
|
|
Password: &crypto.CryptoValue{},
|
|
},
|
|
ID: "44442323",
|
|
State: domain.SMTPConfigStateInactive,
|
|
Description: "test2",
|
|
},
|
|
},
|
|
{
|
|
name: "prepareSMTPConfigQuery yet another config found",
|
|
prepare: prepareSMTPConfigQuery,
|
|
want: want{
|
|
sqlExpectations: mockQuery(
|
|
regexp.QuoteMeta(prepareSMTPConfigStmt),
|
|
prepareSMTPConfigCols,
|
|
[]driver.Value{
|
|
testNow,
|
|
testNow,
|
|
"ro",
|
|
uint64(20211109),
|
|
"23234444",
|
|
domain.SMTPConfigStateInactive,
|
|
"test3",
|
|
"23234444",
|
|
true,
|
|
"sender3",
|
|
"name3",
|
|
"reply-to3",
|
|
"host3",
|
|
"user3",
|
|
&crypto.CryptoValue{},
|
|
nil,
|
|
nil,
|
|
},
|
|
),
|
|
},
|
|
object: &SMTPConfig{
|
|
CreationDate: testNow,
|
|
ChangeDate: testNow,
|
|
ResourceOwner: "ro",
|
|
Sequence: 20211109,
|
|
SMTPConfig: &SMTP{
|
|
TLS: true,
|
|
SenderAddress: "sender3",
|
|
SenderName: "name3",
|
|
ReplyToAddress: "reply-to3",
|
|
Host: "host3",
|
|
User: "user3",
|
|
Password: &crypto.CryptoValue{},
|
|
},
|
|
ID: "23234444",
|
|
State: domain.SMTPConfigStateInactive,
|
|
Description: "test3",
|
|
},
|
|
},
|
|
{
|
|
name: "prepareSMTPConfigQuery sql err",
|
|
prepare: prepareSMTPConfigQuery,
|
|
want: want{
|
|
sqlExpectations: mockQueryErr(
|
|
regexp.QuoteMeta(prepareSMTPConfigStmt),
|
|
sql.ErrConnDone,
|
|
),
|
|
err: func(err error) (error, bool) {
|
|
if !errors.Is(err, sql.ErrConnDone) {
|
|
return fmt.Errorf("err should be sql.ErrConnDone got: %w", err), false
|
|
}
|
|
return nil, true
|
|
},
|
|
},
|
|
object: (*SMTPConfig)(nil),
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assertPrepare(t, tt.prepare, tt.object, tt.want.sqlExpectations, tt.want.err)
|
|
})
|
|
}
|
|
}
|