From 71bd19d6906f0b682cff905461cfbc5193489d3c Mon Sep 17 00:00:00 2001 From: Silvan Date: Mon, 16 Jan 2023 14:07:31 +0100 Subject: [PATCH] fix: login name case insensitive (#5032) checks for login names case insensitive during login --- internal/auth/repository/eventsourcing/view/user.go | 2 +- internal/query/user.go | 8 +++++++- internal/query/user_test.go | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/auth/repository/eventsourcing/view/user.go b/internal/auth/repository/eventsourcing/view/user.go index a38ec94532..ab24f5fd2d 100644 --- a/internal/auth/repository/eventsourcing/view/user.go +++ b/internal/auth/repository/eventsourcing/view/user.go @@ -53,7 +53,7 @@ func (v *View) UserByLoginNameAndResourceOwner(loginName, resourceOwner, instanc } func (v *View) UserByEmail(email, instanceID string) (*model.UserView, error) { - emailQuery, err := query.NewUserVerifiedEmailSearchQuery(email, query.TextEquals) + emailQuery, err := query.NewUserVerifiedEmailSearchQuery(email, query.TextEqualsIgnoreCase) if err != nil { return nil, err } diff --git a/internal/query/user.go b/internal/query/user.go index 6d3b39fda1..e5bd6d7a88 100644 --- a/internal/query/user.go +++ b/internal/query/user.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" errs "errors" + "strings" "time" sq "github.com/Masterminds/squirrel" @@ -179,6 +180,10 @@ var ( name: "loginnames", table: userLoginNamesTable, } + userLoginNamesLowerListCol = Column{ + name: "loginnames_lower", + table: userLoginNamesTable, + } userPreferredLoginNameTable = loginNameTable.setAlias("preferred_login_name") userPreferredLoginNameUserIDCol = LoginNameUserIDCol.setTable(userPreferredLoginNameTable) userPreferredLoginNameCol = LoginNameNameCol.setTable(userPreferredLoginNameTable) @@ -642,7 +647,7 @@ func NewUserPreferredLoginNameSearchQuery(value string, comparison TextCompariso } func NewUserLoginNamesSearchQuery(value string) (SearchQuery, error) { - return NewTextQuery(userLoginNamesListCol, value, TextListContains) + return NewTextQuery(userLoginNamesLowerListCol, strings.ToLower(value), TextListContains) } func NewUserLoginNameExistsQuery(value string, comparison TextComparison) (SearchQuery, error) { @@ -677,6 +682,7 @@ func prepareLoginNamesQuery() (string, []interface{}, error) { return sq.Select( userLoginNamesUserIDCol.identifier(), "ARRAY_AGG("+userLoginNamesNameCol.identifier()+")::TEXT[] AS "+userLoginNamesListCol.name, + "ARRAY_AGG(LOWER("+userLoginNamesNameCol.identifier()+"))::TEXT[] AS "+userLoginNamesLowerListCol.name, userLoginNamesInstanceIDCol.identifier(), userLoginNamesOwnerRemovedUserCol.identifier(), userLoginNamesOwnerRemovedPolicyCol.identifier(), diff --git a/internal/query/user_test.go b/internal/query/user_test.go index b6159339e9..7e0685618c 100644 --- a/internal/query/user_test.go +++ b/internal/query/user_test.go @@ -17,7 +17,7 @@ import ( ) var ( - loginNamesQuery = `SELECT login_names.user_id, ARRAY_AGG(login_names.login_name)::TEXT[] AS loginnames, login_names.instance_id, login_names.user_owner_removed, login_names.policy_owner_removed, login_names.domain_owner_removed` + + loginNamesQuery = `SELECT login_names.user_id, ARRAY_AGG(login_names.login_name)::TEXT[] AS loginnames, ARRAY_AGG(LOWER(login_names.login_name))::TEXT[] AS loginnames_lower, login_names.instance_id, login_names.user_owner_removed, login_names.policy_owner_removed, login_names.domain_owner_removed` + ` FROM projections.login_names2 AS login_names` + ` GROUP BY login_names.user_id, login_names.instance_id, login_names.user_owner_removed, login_names.policy_owner_removed, login_names.domain_owner_removed` preferredLoginNameQuery = `SELECT preferred_login_name.user_id, preferred_login_name.login_name, preferred_login_name.instance_id, preferred_login_name.user_owner_removed, preferred_login_name.policy_owner_removed, preferred_login_name.domain_owner_removed` +