Remove use of dialect.LikeStr (#104460)
* Fix TestIntegrationUpdatingProvisionionedDashboards* tests when running on Spanner by fixing case-insensitive search for dashboard title. * Fix use of case-insensitive LIKE when running on Spanner. * Fix use of LikeStr in anonstore. * Fix use of LikeStr in ngalert/store and org/orgimpl. * Fix use of LikeStr in queryhistory search. * Fix use of LikeStr in serviceaccounts. * Fix use of LikeStr in serviceaccounts. * Fix use of LikeStr in services/team. * Remove LikeStr method.
This commit is contained in:
@@ -327,9 +327,11 @@ func (s *ServiceAccountsStoreImpl) SearchOrgServiceAccounts(ctx context.Context,
|
||||
whereParams = append(whereParams, acFilter.Args...)
|
||||
|
||||
if query.Query != "" {
|
||||
queryWithWildcards := "%" + query.Query + "%"
|
||||
whereConditions = append(whereConditions, "(email "+s.sqlStore.GetDialect().LikeStr()+" ? OR name "+s.sqlStore.GetDialect().LikeStr()+" ? OR login "+s.sqlStore.GetDialect().LikeStr()+" ?)")
|
||||
whereParams = append(whereParams, queryWithWildcards, queryWithWildcards, queryWithWildcards)
|
||||
sql1, param1 := s.sqlStore.GetDialect().LikeOperator("email", true, query.Query, true)
|
||||
sql2, param2 := s.sqlStore.GetDialect().LikeOperator("name", true, query.Query, true)
|
||||
sql3, param3 := s.sqlStore.GetDialect().LikeOperator("login", true, query.Query, true)
|
||||
whereConditions = append(whereConditions, fmt.Sprintf("(%s OR %s OR %s)", sql1, sql2, sql3))
|
||||
whereParams = append(whereParams, param1, param2, param3)
|
||||
}
|
||||
|
||||
switch query.Filter {
|
||||
@@ -348,10 +350,9 @@ func (s *ServiceAccountsStoreImpl) SearchOrgServiceAccounts(ctx context.Context,
|
||||
"is_disabled = ?")
|
||||
whereParams = append(whereParams, s.sqlStore.GetDialect().BooleanValue(true))
|
||||
case serviceaccounts.FilterOnlyExternal:
|
||||
whereConditions = append(
|
||||
whereConditions,
|
||||
"login "+s.sqlStore.GetDialect().LikeStr()+" ?")
|
||||
whereParams = append(whereParams, serviceaccounts.ExtSvcLoginPrefix(query.OrgID)+"%")
|
||||
sql, param := s.sqlStore.GetDialect().LikeOperator("login", false, serviceaccounts.ExtSvcLoginPrefix(query.OrgID), true)
|
||||
whereConditions = append(whereConditions, sql)
|
||||
whereParams = append(whereParams, param)
|
||||
default:
|
||||
s.log.Warn("Invalid filter user for service account filtering", "service account search filtering", query.Filter)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -334,7 +335,7 @@ func TestIntegrationStore_MigrateApiKeys(t *testing.T) {
|
||||
desc: "api key should be migrated to service account token",
|
||||
serviceAccounts: []user.CreateUserCommand{},
|
||||
key: tests.TestApiKey{Name: "test1", Role: org.RoleEditor, OrgId: 1},
|
||||
expectedLogin: "sa-autogen-1-test1",
|
||||
expectedLogin: "sa-AuToGeN-1-test1", // Using mixed-case to test case-insensitive search.
|
||||
expectedErr: nil,
|
||||
},
|
||||
{
|
||||
@@ -343,7 +344,7 @@ func TestIntegrationStore_MigrateApiKeys(t *testing.T) {
|
||||
{Login: "sa-autogen-1-test2"},
|
||||
},
|
||||
key: tests.TestApiKey{Name: "test2", Role: org.RoleEditor, OrgId: 1},
|
||||
expectedLogin: "sa-autogen-1-test2-001",
|
||||
expectedLogin: "sa-AuToGeN-1-test2-001", // Using mixed-case to test case-insensitive search.
|
||||
expectedErr: nil,
|
||||
},
|
||||
{
|
||||
@@ -361,7 +362,7 @@ func TestIntegrationStore_MigrateApiKeys(t *testing.T) {
|
||||
{Login: "sa-autogen-1-test3-009"},
|
||||
},
|
||||
key: tests.TestApiKey{Name: "test3", Role: org.RoleEditor, OrgId: 1},
|
||||
expectedLogin: "sa-autogen-1-test3-010",
|
||||
expectedLogin: "sa-AuToGeN-1-test3-010", // Using mixed-case to test case-insensitive search.
|
||||
expectedErr: nil,
|
||||
},
|
||||
{
|
||||
@@ -429,7 +430,7 @@ func TestIntegrationStore_MigrateApiKeys(t *testing.T) {
|
||||
require.Equal(t, int64(1), serviceAccounts.TotalCount)
|
||||
saMigrated := serviceAccounts.ServiceAccounts[0]
|
||||
require.Equal(t, string(key.Role), saMigrated.Role)
|
||||
require.Equal(t, c.expectedLogin, saMigrated.Login)
|
||||
require.Equal(t, strings.ToLower(c.expectedLogin), saMigrated.Login)
|
||||
|
||||
tokens, err := store.ListTokens(context.Background(), &serviceaccounts.GetSATokensQuery{
|
||||
OrgID: &key.OrgID,
|
||||
@@ -700,7 +701,7 @@ func TestIntegrationServiceAccountsStoreImpl_SearchOrgServiceAccounts(t *testing
|
||||
desc: "should return service accounts with sa-1-satest login",
|
||||
query: &serviceaccounts.SearchOrgServiceAccountsQuery{
|
||||
OrgID: orgID,
|
||||
Query: "sa-1-satest",
|
||||
Query: "SA-1-SaTeSt", // Using mixed-case to test case-insensitive search
|
||||
SignedInUser: userWithPerm,
|
||||
Filter: serviceaccounts.FilterIncludeAll,
|
||||
CountTokens: true,
|
||||
|
||||
Reference in New Issue
Block a user