diff options
author | George Goldberg <george@gberg.me> | 2017-09-27 18:44:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-27 18:44:22 +0100 |
commit | 8d662105d3049a5cd67a7bf42ab70d479d4348e2 (patch) | |
tree | d9153571bbbea3bca202ab1b547ddefe2e18ca37 /store/sqlstore/user_store_test.go | |
parent | 8c80cdde38cceb3424b2b1f43eadf7a1aab0c6df (diff) | |
download | chat-8d662105d3049a5cd67a7bf42ab70d479d4348e2.tar.gz chat-8d662105d3049a5cd67a7bf42ab70d479d4348e2.tar.bz2 chat-8d662105d3049a5cd67a7bf42ab70d479d4348e2.zip |
PLT-7207: Change from fulltext to LIKE search for user filtering (#7343)
* PLT-7202: Switch user search to LIKE queries to avoid fulltext pitfalls.
* Add 2 char name unit test.
* Escape underscores properly.
* Add more tests and fix * handling.
* Make search/indexes case insensitive for postgres.
Diffstat (limited to 'store/sqlstore/user_store_test.go')
-rw-r--r-- | store/sqlstore/user_store_test.go | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/store/sqlstore/user_store_test.go b/store/sqlstore/user_store_test.go index d46513ccc..646d785f7 100644 --- a/store/sqlstore/user_store_test.go +++ b/store/sqlstore/user_store_test.go @@ -1334,10 +1334,28 @@ func TestUserStoreSearch(t *testing.T) { u3.DeleteAt = 1 store.Must(ss.User().Save(u3)) + u5 := &model.User{} + u5.Username = "yu" + model.NewId() + u5.FirstName = "En" + u5.LastName = "Yu" + u5.Nickname = "enyu" + u5.Email = model.NewId() + "@simulator.amazonses.com" + store.Must(ss.User().Save(u5)) + + u6 := &model.User{} + u6.Username = "underscore" + model.NewId() + u6.FirstName = "Du_" + u6.LastName = "_DE" + u6.Nickname = "lodash" + u6.Email = model.NewId() + "@simulator.amazonses.com" + store.Must(ss.User().Save(u6)) + tid := model.NewId() store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: tid, UserId: u1.Id})) store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: tid, UserId: u2.Id})) store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: tid, UserId: u3.Id})) + store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: tid, UserId: u5.Id})) + store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: tid, UserId: u6.Id})) searchOptions := map[string]bool{} searchOptions[store.USER_SEARCH_OPTION_NAMES_ONLY] = true @@ -1367,6 +1385,22 @@ func TestUserStoreSearch(t *testing.T) { } } + if r1 := <-ss.User().Search(tid, "en", searchOptions); r1.Err != nil { + t.Fatal(r1.Err) + } else { + profiles := r1.Data.([]*model.User) + found1 := false + for _, profile := range profiles { + if profile.Id == u5.Id { + found1 = true + } + } + + if !found1 { + t.Fatal("should have found user") + } + } + searchOptions[store.USER_SEARCH_OPTION_NAMES_ONLY] = false if r1 := <-ss.User().Search(tid, u1.Email, searchOptions); r1.Err != nil { @@ -1429,6 +1463,56 @@ func TestUserStoreSearch(t *testing.T) { } } + // % should be escaped and searched for. + if r1 := <-ss.User().Search(tid, "h%", searchOptions); r1.Err != nil { + t.Fatal(r1.Err) + } else { + profiles := r1.Data.([]*model.User) + if len(profiles) != 0 { + t.Fatal("shouldn't have found anything") + } + } + + // "_" should be properly escaped and searched for. + if r1 := <-ss.User().Search(tid, "h_", searchOptions); r1.Err != nil { + t.Fatal(r1.Err) + } else { + profiles := r1.Data.([]*model.User) + if len(profiles) != 0 { + t.Fatal("shouldn't have found anything") + } + } + if r1 := <-ss.User().Search(tid, "Du_", searchOptions); r1.Err != nil { + t.Fatal(r1.Err) + } else { + profiles := r1.Data.([]*model.User) + found6 := false + for _, profile := range profiles { + if profile.Id == u6.Id { + found6 = true + } + } + + if !found6 { + t.Fatal("should have found user") + } + } + if r1 := <-ss.User().Search(tid, "_dE", searchOptions); r1.Err != nil { + t.Fatal(r1.Err) + } else { + profiles := r1.Data.([]*model.User) + found6 := false + for _, profile := range profiles { + if profile.Id == u6.Id { + found6 = true + } + } + + if !found6 { + t.Fatal("should have found user") + } + } + searchOptions[store.USER_SEARCH_OPTION_ALLOW_INACTIVE] = true if r1 := <-ss.User().Search(tid, "jimb", searchOptions); r1.Err != nil { |