From 32b751a3a06ad3e1895a57254d66e1abab061cd7 Mon Sep 17 00:00:00 2001 From: Livio Spring Date: Thu, 1 Sep 2022 09:10:07 +0200 Subject: [PATCH] fix: WebAuthN (registration / login) and list on users (#4290) * fix: WebAuthN when running under non default port * fix: remove notification schema from list of views / failed events * fix: auth method column type in user auth methods --- .../eventsourcing/eventstore/administrator.go | 2 +- internal/query/projection/user_auth_method.go | 4 +- .../query/projection/user_auth_method_test.go | 12 +-- internal/query/user_auth_method_test.go | 80 +++++++++---------- internal/webauthn/webauthn.go | 6 +- 5 files changed, 52 insertions(+), 52 deletions(-) diff --git a/internal/admin/repository/eventsourcing/eventstore/administrator.go b/internal/admin/repository/eventsourcing/eventstore/administrator.go index 22cfb9ccd..c802d9be8 100644 --- a/internal/admin/repository/eventsourcing/eventstore/administrator.go +++ b/internal/admin/repository/eventsourcing/eventstore/administrator.go @@ -8,7 +8,7 @@ import ( "github.com/zitadel/zitadel/internal/view/repository" ) -var dbList = []string{"auth", "adminapi", "notification"} +var dbList = []string{"auth", "adminapi"} type AdministratorRepo struct { View *view.View diff --git a/internal/query/projection/user_auth_method.go b/internal/query/projection/user_auth_method.go index cf337236d..599562751 100644 --- a/internal/query/projection/user_auth_method.go +++ b/internal/query/projection/user_auth_method.go @@ -12,7 +12,7 @@ import ( ) const ( - UserAuthMethodTable = "projections.user_auth_methods2" + UserAuthMethodTable = "projections.user_auth_methods3" UserAuthMethodUserIDCol = "user_id" UserAuthMethodTypeCol = "method_type" @@ -37,7 +37,7 @@ func newUserAuthMethodProjection(ctx context.Context, config crdb.StatementHandl config.InitCheck = crdb.NewTableCheck( crdb.NewTable([]*crdb.Column{ crdb.NewColumn(UserAuthMethodUserIDCol, crdb.ColumnTypeText), - crdb.NewColumn(UserAuthMethodTypeCol, crdb.ColumnTypeText), + crdb.NewColumn(UserAuthMethodTypeCol, crdb.ColumnTypeEnum), crdb.NewColumn(UserAuthMethodTokenIDCol, crdb.ColumnTypeText), crdb.NewColumn(UserAuthMethodCreationDateCol, crdb.ColumnTypeTimestamp), crdb.NewColumn(UserAuthMethodChangeDateCol, crdb.ColumnTypeTimestamp), diff --git a/internal/query/projection/user_auth_method_test.go b/internal/query/projection/user_auth_method_test.go index baad8d5bf..5b540a015 100644 --- a/internal/query/projection/user_auth_method_test.go +++ b/internal/query/projection/user_auth_method_test.go @@ -41,7 +41,7 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.user_auth_methods2 (token_id, creation_date, change_date, resource_owner, instance_id, user_id, sequence, state, method_type, name) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) ON CONFLICT (instance_id, user_id, method_type, token_id) DO UPDATE SET (creation_date, change_date, resource_owner, sequence, state, name) = (EXCLUDED.creation_date, EXCLUDED.change_date, EXCLUDED.resource_owner, EXCLUDED.sequence, EXCLUDED.state, EXCLUDED.name)", + expectedStmt: "INSERT INTO projections.user_auth_methods3 (token_id, creation_date, change_date, resource_owner, instance_id, user_id, sequence, state, method_type, name) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) ON CONFLICT (instance_id, user_id, method_type, token_id) DO UPDATE SET (creation_date, change_date, resource_owner, sequence, state, name) = (EXCLUDED.creation_date, EXCLUDED.change_date, EXCLUDED.resource_owner, EXCLUDED.sequence, EXCLUDED.state, EXCLUDED.name)", expectedArgs: []interface{}{ "token-id", anyArg{}, @@ -79,7 +79,7 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.user_auth_methods2 (token_id, creation_date, change_date, resource_owner, instance_id, user_id, sequence, state, method_type, name) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) ON CONFLICT (instance_id, user_id, method_type, token_id) DO UPDATE SET (creation_date, change_date, resource_owner, sequence, state, name) = (EXCLUDED.creation_date, EXCLUDED.change_date, EXCLUDED.resource_owner, EXCLUDED.sequence, EXCLUDED.state, EXCLUDED.name)", + expectedStmt: "INSERT INTO projections.user_auth_methods3 (token_id, creation_date, change_date, resource_owner, instance_id, user_id, sequence, state, method_type, name) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) ON CONFLICT (instance_id, user_id, method_type, token_id) DO UPDATE SET (creation_date, change_date, resource_owner, sequence, state, name) = (EXCLUDED.creation_date, EXCLUDED.change_date, EXCLUDED.resource_owner, EXCLUDED.sequence, EXCLUDED.state, EXCLUDED.name)", expectedArgs: []interface{}{ "token-id", anyArg{}, @@ -116,7 +116,7 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "INSERT INTO projections.user_auth_methods2 (token_id, creation_date, change_date, resource_owner, instance_id, user_id, sequence, state, method_type, name) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) ON CONFLICT (instance_id, user_id, method_type, token_id) DO UPDATE SET (creation_date, change_date, resource_owner, sequence, state, name) = (EXCLUDED.creation_date, EXCLUDED.change_date, EXCLUDED.resource_owner, EXCLUDED.sequence, EXCLUDED.state, EXCLUDED.name)", + expectedStmt: "INSERT INTO projections.user_auth_methods3 (token_id, creation_date, change_date, resource_owner, instance_id, user_id, sequence, state, method_type, name) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) ON CONFLICT (instance_id, user_id, method_type, token_id) DO UPDATE SET (creation_date, change_date, resource_owner, sequence, state, name) = (EXCLUDED.creation_date, EXCLUDED.change_date, EXCLUDED.resource_owner, EXCLUDED.sequence, EXCLUDED.state, EXCLUDED.name)", expectedArgs: []interface{}{ "", anyArg{}, @@ -155,7 +155,7 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.user_auth_methods2 SET (change_date, sequence, name, state) = ($1, $2, $3, $4) WHERE (user_id = $5) AND (method_type = $6) AND (resource_owner = $7) AND (token_id = $8)", + expectedStmt: "UPDATE projections.user_auth_methods3 SET (change_date, sequence, name, state) = ($1, $2, $3, $4) WHERE (user_id = $5) AND (method_type = $6) AND (resource_owner = $7) AND (token_id = $8)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -192,7 +192,7 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.user_auth_methods2 SET (change_date, sequence, name, state) = ($1, $2, $3, $4) WHERE (user_id = $5) AND (method_type = $6) AND (resource_owner = $7) AND (token_id = $8)", + expectedStmt: "UPDATE projections.user_auth_methods3 SET (change_date, sequence, name, state) = ($1, $2, $3, $4) WHERE (user_id = $5) AND (method_type = $6) AND (resource_owner = $7) AND (token_id = $8)", expectedArgs: []interface{}{ anyArg{}, uint64(15), @@ -227,7 +227,7 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) { executer: &testExecuter{ executions: []execution{ { - expectedStmt: "UPDATE projections.user_auth_methods2 SET (change_date, sequence, name, state) = ($1, $2, $3, $4) WHERE (user_id = $5) AND (method_type = $6) AND (resource_owner = $7) AND (token_id = $8)", + expectedStmt: "UPDATE projections.user_auth_methods3 SET (change_date, sequence, name, state) = ($1, $2, $3, $4) WHERE (user_id = $5) AND (method_type = $6) AND (resource_owner = $7) AND (token_id = $8)", expectedArgs: []interface{}{ anyArg{}, uint64(15), diff --git a/internal/query/user_auth_method_test.go b/internal/query/user_auth_method_test.go index 23d6e780d..cb0a8a389 100644 --- a/internal/query/user_auth_method_test.go +++ b/internal/query/user_auth_method_test.go @@ -27,17 +27,17 @@ func Test_UserAuthMethodPrepares(t *testing.T) { prepare: prepareUserAuthMethodsQuery, want: want{ sqlExpectations: mockQueries( - regexp.QuoteMeta(`SELECT projections.user_auth_methods2.token_id,`+ - ` projections.user_auth_methods2.creation_date,`+ - ` projections.user_auth_methods2.change_date,`+ - ` projections.user_auth_methods2.resource_owner,`+ - ` projections.user_auth_methods2.user_id,`+ - ` projections.user_auth_methods2.sequence,`+ - ` projections.user_auth_methods2.name,`+ - ` projections.user_auth_methods2.state,`+ - ` projections.user_auth_methods2.method_type,`+ + regexp.QuoteMeta(`SELECT projections.user_auth_methods3.token_id,`+ + ` projections.user_auth_methods3.creation_date,`+ + ` projections.user_auth_methods3.change_date,`+ + ` projections.user_auth_methods3.resource_owner,`+ + ` projections.user_auth_methods3.user_id,`+ + ` projections.user_auth_methods3.sequence,`+ + ` projections.user_auth_methods3.name,`+ + ` projections.user_auth_methods3.state,`+ + ` projections.user_auth_methods3.method_type,`+ ` COUNT(*) OVER ()`+ - ` FROM projections.user_auth_methods2`), + ` FROM projections.user_auth_methods3`), nil, nil, ), @@ -49,17 +49,17 @@ func Test_UserAuthMethodPrepares(t *testing.T) { prepare: prepareUserAuthMethodsQuery, want: want{ sqlExpectations: mockQueries( - regexp.QuoteMeta(`SELECT projections.user_auth_methods2.token_id,`+ - ` projections.user_auth_methods2.creation_date,`+ - ` projections.user_auth_methods2.change_date,`+ - ` projections.user_auth_methods2.resource_owner,`+ - ` projections.user_auth_methods2.user_id,`+ - ` projections.user_auth_methods2.sequence,`+ - ` projections.user_auth_methods2.name,`+ - ` projections.user_auth_methods2.state,`+ - ` projections.user_auth_methods2.method_type,`+ + regexp.QuoteMeta(`SELECT projections.user_auth_methods3.token_id,`+ + ` projections.user_auth_methods3.creation_date,`+ + ` projections.user_auth_methods3.change_date,`+ + ` projections.user_auth_methods3.resource_owner,`+ + ` projections.user_auth_methods3.user_id,`+ + ` projections.user_auth_methods3.sequence,`+ + ` projections.user_auth_methods3.name,`+ + ` projections.user_auth_methods3.state,`+ + ` projections.user_auth_methods3.method_type,`+ ` COUNT(*) OVER ()`+ - ` FROM projections.user_auth_methods2`), + ` FROM projections.user_auth_methods3`), []string{ "token_id", "creation_date", @@ -111,17 +111,17 @@ func Test_UserAuthMethodPrepares(t *testing.T) { prepare: prepareUserAuthMethodsQuery, want: want{ sqlExpectations: mockQueries( - regexp.QuoteMeta(`SELECT projections.user_auth_methods2.token_id,`+ - ` projections.user_auth_methods2.creation_date,`+ - ` projections.user_auth_methods2.change_date,`+ - ` projections.user_auth_methods2.resource_owner,`+ - ` projections.user_auth_methods2.user_id,`+ - ` projections.user_auth_methods2.sequence,`+ - ` projections.user_auth_methods2.name,`+ - ` projections.user_auth_methods2.state,`+ - ` projections.user_auth_methods2.method_type,`+ + regexp.QuoteMeta(`SELECT projections.user_auth_methods3.token_id,`+ + ` projections.user_auth_methods3.creation_date,`+ + ` projections.user_auth_methods3.change_date,`+ + ` projections.user_auth_methods3.resource_owner,`+ + ` projections.user_auth_methods3.user_id,`+ + ` projections.user_auth_methods3.sequence,`+ + ` projections.user_auth_methods3.name,`+ + ` projections.user_auth_methods3.state,`+ + ` projections.user_auth_methods3.method_type,`+ ` COUNT(*) OVER ()`+ - ` FROM projections.user_auth_methods2`), + ` FROM projections.user_auth_methods3`), []string{ "token_id", "creation_date", @@ -195,17 +195,17 @@ func Test_UserAuthMethodPrepares(t *testing.T) { prepare: prepareUserAuthMethodsQuery, want: want{ sqlExpectations: mockQueryErr( - regexp.QuoteMeta(`SELECT projections.user_auth_methods2.token_id,`+ - ` projections.user_auth_methods2.creation_date,`+ - ` projections.user_auth_methods2.change_date,`+ - ` projections.user_auth_methods2.resource_owner,`+ - ` projections.user_auth_methods2.user_id,`+ - ` projections.user_auth_methods2.sequence,`+ - ` projections.user_auth_methods2.name,`+ - ` projections.user_auth_methods2.state,`+ - ` projections.user_auth_methods2.method_type,`+ + regexp.QuoteMeta(`SELECT projections.user_auth_methods3.token_id,`+ + ` projections.user_auth_methods3.creation_date,`+ + ` projections.user_auth_methods3.change_date,`+ + ` projections.user_auth_methods3.resource_owner,`+ + ` projections.user_auth_methods3.user_id,`+ + ` projections.user_auth_methods3.sequence,`+ + ` projections.user_auth_methods3.name,`+ + ` projections.user_auth_methods3.state,`+ + ` projections.user_auth_methods3.method_type,`+ ` COUNT(*) OVER ()`+ - ` FROM projections.user_auth_methods2`), + ` FROM projections.user_auth_methods3`), sql.ErrConnDone, ), err: func(err error) (error, bool) { diff --git a/internal/webauthn/webauthn.go b/internal/webauthn/webauthn.go index a06f90943..d1a62819b 100644 --- a/internal/webauthn/webauthn.go +++ b/internal/webauthn/webauthn.go @@ -176,10 +176,10 @@ func (w *Config) FinishLogin(ctx context.Context, user *domain.Human, webAuthN * } func (w *Config) serverFromContext(ctx context.Context) (*webauthn.WebAuthn, error) { - host := authz.GetInstance(ctx).RequestedDomain() + instance := authz.GetInstance(ctx) return webauthn.New(&webauthn.Config{ RPDisplayName: w.DisplayName, - RPID: host, - RPOrigin: http.BuildOrigin(host, w.ExternalSecure), + RPID: instance.RequestedDomain(), + RPOrigin: http.BuildOrigin(instance.RequestedHost(), w.ExternalSecure), }) }