summaryrefslogtreecommitdiffstats
path: root/api/user_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'api/user_test.go')
-rw-r--r--api/user_test.go114
1 files changed, 108 insertions, 6 deletions
diff --git a/api/user_test.go b/api/user_test.go
index 1ffb2140c..a10cee961 100644
--- a/api/user_test.go
+++ b/api/user_test.go
@@ -80,6 +80,51 @@ func TestCreateUser(t *testing.T) {
}
}
+func TestCheckUserDomain(t *testing.T) {
+ th := Setup().InitBasic()
+ user := th.BasicUser
+
+ cases := []struct {
+ domains string
+ matched bool
+ }{
+ {"simulator.amazonses.com", true},
+ {"gmail.com", false},
+ {"", true},
+ {"gmail.com simulator.amazonses.com", true},
+ }
+ for _, c := range cases {
+ matched := CheckUserDomain(user, c.domains)
+ if matched != c.matched {
+ if c.matched {
+ t.Logf("'%v' should have matched '%v'", user.Email, c.domains)
+ } else {
+ t.Logf("'%v' should not have matched '%v'", user.Email, c.domains)
+ }
+ t.FailNow()
+ }
+ }
+}
+
+func TestIsUsernameTaken(t *testing.T) {
+ th := Setup().InitBasic()
+ user := th.BasicUser
+ taken := IsUsernameTaken(user.Username)
+
+ if !taken {
+ t.Logf("the username '%v' should be taken", user.Username)
+ t.FailNow()
+ }
+
+ newUsername := "randomUsername"
+ taken = IsUsernameTaken(newUsername)
+
+ if taken {
+ t.Logf("the username '%v' should not be taken", newUsername)
+ t.FailNow()
+ }
+}
+
func TestLogin(t *testing.T) {
th := Setup()
Client := th.CreateClient()
@@ -1088,8 +1133,9 @@ func TestUserUpdateDeviceId(t *testing.T) {
}
func TestUserUpdateActive(t *testing.T) {
- th := Setup()
+ th := Setup().InitSystemAdmin()
Client := th.CreateClient()
+ SystemAdminClient := th.SystemAdminClient
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
@@ -1142,6 +1188,18 @@ func TestUserUpdateActive(t *testing.T) {
if _, err := Client.UpdateActive("12345678901234567890123456", false); err == nil {
t.Fatal("Should have errored, bad id")
}
+
+ SetStatusOnline(user3.Id, "", false)
+
+ if _, err := SystemAdminClient.UpdateActive(user3.Id, false); err != nil {
+ t.Fatal(err)
+ }
+
+ if status, err := GetStatus(user3.Id); err != nil {
+ t.Fatal(err)
+ } else if status.Status != model.STATUS_OFFLINE {
+ t.Fatal("status should have been set to offline")
+ }
}
func TestUserPermDelete(t *testing.T) {
@@ -1198,16 +1256,21 @@ func TestSendPasswordReset(t *testing.T) {
LinkUserToTeam(user, team)
store.Must(Srv.Store.User().VerifyEmail(user.Id))
- if _, err := Client.SendPasswordReset(user.Email); err != nil {
+ if result, err := Client.SendPasswordReset(user.Email); err != nil {
t.Fatal(err)
+ } else {
+ resp := result.Data.(map[string]string)
+ if resp["email"] != user.Email {
+ t.Fatal("wrong email")
+ }
}
- if _, err := Client.SendPasswordReset(""); err == nil {
- t.Fatal("Should have errored - no email")
+ if _, err := Client.SendPasswordReset("junk@junk.com"); err != nil {
+ t.Fatal("Should have errored - bad email")
}
- if _, err := Client.SendPasswordReset("junk@junk.com"); err == nil {
- t.Fatal("Should have errored - bad email")
+ if _, err := Client.SendPasswordReset(""); err == nil {
+ t.Fatal("Should have errored - no email")
}
authData := model.NewId()
@@ -2276,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")
+ }
+ }
+
+}