From d57ab7a81e295c0f1a731f1f4f5fa04d5cba398b Mon Sep 17 00:00:00 2001 From: Carlos Tadeu Panato Junior Date: Tue, 22 Nov 2016 00:50:57 +0100 Subject: PLT-3762 - Add API call to get a user by their username (#4611) * PLT-3762 - Add API call to get a user by their username * fix lint * update rote * update per code review * update per code review * remove first/last name is not used in this test --- api/user_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'api/user_test.go') diff --git a/api/user_test.go b/api/user_test.go index bc804ca11..a10cee961 100644 --- a/api/user_test.go +++ b/api/user_test.go @@ -2339,3 +2339,42 @@ func TestAutocompleteUsers(t *testing.T) { t.Fatal("should have errored - bad team id") } } + +func TestGetByUsername(t *testing.T) { + th := Setup().InitBasic() + Client := th.BasicClient + + if result, err := Client.GetByUsername(th.BasicUser.Username, ""); err != nil { + t.Fatal("Failed to get user") + } else { + if result.Data.(*model.User).Password != "" { + t.Fatal("User shouldn't have any password data once set") + } + } + + emailPrivacy := utils.Cfg.PrivacySettings.ShowEmailAddress + namePrivacy := utils.Cfg.PrivacySettings.ShowFullName + defer func() { + utils.Cfg.PrivacySettings.ShowEmailAddress = emailPrivacy + utils.Cfg.PrivacySettings.ShowFullName = namePrivacy + }() + + utils.Cfg.PrivacySettings.ShowEmailAddress = false + utils.Cfg.PrivacySettings.ShowFullName = false + + if result, err := Client.GetByUsername(th.BasicUser2.Username, ""); err != nil { + t.Fatal(err) + } else { + u := result.Data.(*model.User) + if u.Password != "" { + t.Fatal("password must be empty") + } + if *u.AuthData != "" { + t.Fatal("auth data must be empty") + } + if u.Email != "" { + t.Fatal("email should be sanitized") + } + } + +} -- cgit v1.2.3-1-g7c22