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
This commit is contained in:
Livio Spring 2022-09-01 09:10:07 +02:00 committed by GitHub
parent b79670ea96
commit 32b751a3a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 52 deletions

View File

@ -8,7 +8,7 @@ import (
"github.com/zitadel/zitadel/internal/view/repository" "github.com/zitadel/zitadel/internal/view/repository"
) )
var dbList = []string{"auth", "adminapi", "notification"} var dbList = []string{"auth", "adminapi"}
type AdministratorRepo struct { type AdministratorRepo struct {
View *view.View View *view.View

View File

@ -12,7 +12,7 @@ import (
) )
const ( const (
UserAuthMethodTable = "projections.user_auth_methods2" UserAuthMethodTable = "projections.user_auth_methods3"
UserAuthMethodUserIDCol = "user_id" UserAuthMethodUserIDCol = "user_id"
UserAuthMethodTypeCol = "method_type" UserAuthMethodTypeCol = "method_type"
@ -37,7 +37,7 @@ func newUserAuthMethodProjection(ctx context.Context, config crdb.StatementHandl
config.InitCheck = crdb.NewTableCheck( config.InitCheck = crdb.NewTableCheck(
crdb.NewTable([]*crdb.Column{ crdb.NewTable([]*crdb.Column{
crdb.NewColumn(UserAuthMethodUserIDCol, crdb.ColumnTypeText), crdb.NewColumn(UserAuthMethodUserIDCol, crdb.ColumnTypeText),
crdb.NewColumn(UserAuthMethodTypeCol, crdb.ColumnTypeText), crdb.NewColumn(UserAuthMethodTypeCol, crdb.ColumnTypeEnum),
crdb.NewColumn(UserAuthMethodTokenIDCol, crdb.ColumnTypeText), crdb.NewColumn(UserAuthMethodTokenIDCol, crdb.ColumnTypeText),
crdb.NewColumn(UserAuthMethodCreationDateCol, crdb.ColumnTypeTimestamp), crdb.NewColumn(UserAuthMethodCreationDateCol, crdb.ColumnTypeTimestamp),
crdb.NewColumn(UserAuthMethodChangeDateCol, crdb.ColumnTypeTimestamp), crdb.NewColumn(UserAuthMethodChangeDateCol, crdb.ColumnTypeTimestamp),

View File

@ -41,7 +41,7 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
executer: &testExecuter{ executer: &testExecuter{
executions: []execution{ 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{}{ expectedArgs: []interface{}{
"token-id", "token-id",
anyArg{}, anyArg{},
@ -79,7 +79,7 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
executer: &testExecuter{ executer: &testExecuter{
executions: []execution{ 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{}{ expectedArgs: []interface{}{
"token-id", "token-id",
anyArg{}, anyArg{},
@ -116,7 +116,7 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
executer: &testExecuter{ executer: &testExecuter{
executions: []execution{ 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{}{ expectedArgs: []interface{}{
"", "",
anyArg{}, anyArg{},
@ -155,7 +155,7 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
executer: &testExecuter{ executer: &testExecuter{
executions: []execution{ 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{}{ expectedArgs: []interface{}{
anyArg{}, anyArg{},
uint64(15), uint64(15),
@ -192,7 +192,7 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
executer: &testExecuter{ executer: &testExecuter{
executions: []execution{ 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{}{ expectedArgs: []interface{}{
anyArg{}, anyArg{},
uint64(15), uint64(15),
@ -227,7 +227,7 @@ func TestUserAuthMethodProjection_reduces(t *testing.T) {
executer: &testExecuter{ executer: &testExecuter{
executions: []execution{ 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{}{ expectedArgs: []interface{}{
anyArg{}, anyArg{},
uint64(15), uint64(15),

View File

@ -27,17 +27,17 @@ func Test_UserAuthMethodPrepares(t *testing.T) {
prepare: prepareUserAuthMethodsQuery, prepare: prepareUserAuthMethodsQuery,
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.user_auth_methods2.token_id,`+ regexp.QuoteMeta(`SELECT projections.user_auth_methods3.token_id,`+
` projections.user_auth_methods2.creation_date,`+ ` projections.user_auth_methods3.creation_date,`+
` projections.user_auth_methods2.change_date,`+ ` projections.user_auth_methods3.change_date,`+
` projections.user_auth_methods2.resource_owner,`+ ` projections.user_auth_methods3.resource_owner,`+
` projections.user_auth_methods2.user_id,`+ ` projections.user_auth_methods3.user_id,`+
` projections.user_auth_methods2.sequence,`+ ` projections.user_auth_methods3.sequence,`+
` projections.user_auth_methods2.name,`+ ` projections.user_auth_methods3.name,`+
` projections.user_auth_methods2.state,`+ ` projections.user_auth_methods3.state,`+
` projections.user_auth_methods2.method_type,`+ ` projections.user_auth_methods3.method_type,`+
` COUNT(*) OVER ()`+ ` COUNT(*) OVER ()`+
` FROM projections.user_auth_methods2`), ` FROM projections.user_auth_methods3`),
nil, nil,
nil, nil,
), ),
@ -49,17 +49,17 @@ func Test_UserAuthMethodPrepares(t *testing.T) {
prepare: prepareUserAuthMethodsQuery, prepare: prepareUserAuthMethodsQuery,
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.user_auth_methods2.token_id,`+ regexp.QuoteMeta(`SELECT projections.user_auth_methods3.token_id,`+
` projections.user_auth_methods2.creation_date,`+ ` projections.user_auth_methods3.creation_date,`+
` projections.user_auth_methods2.change_date,`+ ` projections.user_auth_methods3.change_date,`+
` projections.user_auth_methods2.resource_owner,`+ ` projections.user_auth_methods3.resource_owner,`+
` projections.user_auth_methods2.user_id,`+ ` projections.user_auth_methods3.user_id,`+
` projections.user_auth_methods2.sequence,`+ ` projections.user_auth_methods3.sequence,`+
` projections.user_auth_methods2.name,`+ ` projections.user_auth_methods3.name,`+
` projections.user_auth_methods2.state,`+ ` projections.user_auth_methods3.state,`+
` projections.user_auth_methods2.method_type,`+ ` projections.user_auth_methods3.method_type,`+
` COUNT(*) OVER ()`+ ` COUNT(*) OVER ()`+
` FROM projections.user_auth_methods2`), ` FROM projections.user_auth_methods3`),
[]string{ []string{
"token_id", "token_id",
"creation_date", "creation_date",
@ -111,17 +111,17 @@ func Test_UserAuthMethodPrepares(t *testing.T) {
prepare: prepareUserAuthMethodsQuery, prepare: prepareUserAuthMethodsQuery,
want: want{ want: want{
sqlExpectations: mockQueries( sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.user_auth_methods2.token_id,`+ regexp.QuoteMeta(`SELECT projections.user_auth_methods3.token_id,`+
` projections.user_auth_methods2.creation_date,`+ ` projections.user_auth_methods3.creation_date,`+
` projections.user_auth_methods2.change_date,`+ ` projections.user_auth_methods3.change_date,`+
` projections.user_auth_methods2.resource_owner,`+ ` projections.user_auth_methods3.resource_owner,`+
` projections.user_auth_methods2.user_id,`+ ` projections.user_auth_methods3.user_id,`+
` projections.user_auth_methods2.sequence,`+ ` projections.user_auth_methods3.sequence,`+
` projections.user_auth_methods2.name,`+ ` projections.user_auth_methods3.name,`+
` projections.user_auth_methods2.state,`+ ` projections.user_auth_methods3.state,`+
` projections.user_auth_methods2.method_type,`+ ` projections.user_auth_methods3.method_type,`+
` COUNT(*) OVER ()`+ ` COUNT(*) OVER ()`+
` FROM projections.user_auth_methods2`), ` FROM projections.user_auth_methods3`),
[]string{ []string{
"token_id", "token_id",
"creation_date", "creation_date",
@ -195,17 +195,17 @@ func Test_UserAuthMethodPrepares(t *testing.T) {
prepare: prepareUserAuthMethodsQuery, prepare: prepareUserAuthMethodsQuery,
want: want{ want: want{
sqlExpectations: mockQueryErr( sqlExpectations: mockQueryErr(
regexp.QuoteMeta(`SELECT projections.user_auth_methods2.token_id,`+ regexp.QuoteMeta(`SELECT projections.user_auth_methods3.token_id,`+
` projections.user_auth_methods2.creation_date,`+ ` projections.user_auth_methods3.creation_date,`+
` projections.user_auth_methods2.change_date,`+ ` projections.user_auth_methods3.change_date,`+
` projections.user_auth_methods2.resource_owner,`+ ` projections.user_auth_methods3.resource_owner,`+
` projections.user_auth_methods2.user_id,`+ ` projections.user_auth_methods3.user_id,`+
` projections.user_auth_methods2.sequence,`+ ` projections.user_auth_methods3.sequence,`+
` projections.user_auth_methods2.name,`+ ` projections.user_auth_methods3.name,`+
` projections.user_auth_methods2.state,`+ ` projections.user_auth_methods3.state,`+
` projections.user_auth_methods2.method_type,`+ ` projections.user_auth_methods3.method_type,`+
` COUNT(*) OVER ()`+ ` COUNT(*) OVER ()`+
` FROM projections.user_auth_methods2`), ` FROM projections.user_auth_methods3`),
sql.ErrConnDone, sql.ErrConnDone,
), ),
err: func(err error) (error, bool) { err: func(err error) (error, bool) {

View File

@ -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) { func (w *Config) serverFromContext(ctx context.Context) (*webauthn.WebAuthn, error) {
host := authz.GetInstance(ctx).RequestedDomain() instance := authz.GetInstance(ctx)
return webauthn.New(&webauthn.Config{ return webauthn.New(&webauthn.Config{
RPDisplayName: w.DisplayName, RPDisplayName: w.DisplayName,
RPID: host, RPID: instance.RequestedDomain(),
RPOrigin: http.BuildOrigin(host, w.ExternalSecure), RPOrigin: http.BuildOrigin(instance.RequestedHost(), w.ExternalSecure),
}) })
} }