summaryrefslogtreecommitdiffstats
path: root/api4/user_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'api4/user_test.go')
-rw-r--r--api4/user_test.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/api4/user_test.go b/api4/user_test.go
index 40f6b4117..dc8a82310 100644
--- a/api4/user_test.go
+++ b/api4/user_test.go
@@ -131,6 +131,71 @@ func TestGetUser(t *testing.T) {
}
}
+func TestGetUserByEmail(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+
+ user := th.CreateUser()
+
+ ruser, resp := Client.GetUserByEmail(user.Email, "")
+ CheckNoError(t, resp)
+ CheckUserSanitization(t, ruser)
+
+ if ruser.Email != user.Email {
+ t.Fatal("emails did not match")
+ }
+
+ ruser, resp = Client.GetUserByEmail(user.Email, resp.Etag)
+ CheckEtag(t, ruser, resp)
+
+
+ _, resp = Client.GetUserByEmail(GenerateTestUsername(), "")
+ CheckBadRequestStatus(t, resp)
+
+ _, resp = Client.GetUserByEmail(GenerateTestEmail(), "")
+ CheckNotFoundStatus(t, resp)
+
+ // Check against privacy config settings
+ 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
+
+ ruser, resp = Client.GetUserByEmail(user.Email, "")
+ CheckNoError(t, resp)
+
+ if ruser.Email != "" {
+ t.Fatal("email should be blank")
+ }
+ if ruser.FirstName != "" {
+ t.Fatal("first name should be blank")
+ }
+ if ruser.LastName != "" {
+ t.Fatal("last name should be blank")
+ }
+
+ Client.Logout()
+ _, resp = Client.GetUserByEmail(user.Email, "")
+ CheckUnauthorizedStatus(t, resp)
+
+ // System admins should ignore privacy settings
+ ruser, resp = th.SystemAdminClient.GetUserByEmail(user.Email, resp.Etag)
+ if ruser.Email == "" {
+ t.Fatal("email should not be blank")
+ }
+ if ruser.FirstName == "" {
+ t.Fatal("first name should not be blank")
+ }
+ if ruser.LastName == "" {
+ t.Fatal("last name should not be blank")
+ }
+}
+
func TestGetUsersByIds(t *testing.T) {
th := Setup().InitBasic()
Client := th.Client