func TestUserStoreUpdateAuthData(t *testing.T) { Setup() teamId := model.NewId() u1 := &model.User{} u1.Email = model.NewId() Must(store.User().Save(u1)) Must(store.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u1.Id})) service := "someservice" authData := model.NewId() if err := (<-store.User().UpdateAuthData(u1.Id, service, &authData, "")).Err; err != nil { t.Fatal(err) } if r1 := <-store.User().GetByEmail(u1.Email); r1.Err != nil { t.Fatal(r1.Err) } else { user := r1.Data.(*model.User) if user.AuthService != service { t.Fatal("AuthService was not updated correctly") } if *user.AuthData != authData { t.Fatal("AuthData was not updated correctly") } if user.Password != "" { t.Fatal("Password was not cleared properly") } } }
func TestTeamStoreGetByName(t *testing.T) { Setup() o1 := model.Team{} o1.DisplayName = "DisplayName" o1.Name = "a" + model.NewId() + "b" o1.Email = model.NewId() + "@nowhere.com" o1.Type = model.TEAM_OPEN if err := (<-store.Team().Save(&o1)).Err; err != nil { t.Fatal(err) } if r1 := <-store.Team().GetByName(o1.Name); r1.Err != nil { t.Fatal(r1.Err) } else { if r1.Data.(*model.Team).ToJson() != o1.ToJson() { t.Fatal("invalid returned team") } } if err := (<-store.Team().GetByName("")).Err; err == nil { t.Fatal("Missing id should have failed") } }
func TestAllTeamListing(t *testing.T) { Setup() o1 := model.Team{} o1.DisplayName = "DisplayName" o1.Name = "a" + model.NewId() + "b" o1.Email = model.NewId() + "@nowhere.com" o1.Type = model.TEAM_OPEN o1.AllowTeamListing = true Must(store.Team().Save(&o1)) o2 := model.Team{} o2.DisplayName = "DisplayName" o2.Name = "a" + model.NewId() + "b" o2.Email = model.NewId() + "@nowhere.com" o2.Type = model.TEAM_OPEN Must(store.Team().Save(&o2)) if r1 := <-store.Team().GetAllTeamListing(); r1.Err != nil { t.Fatal(r1.Err) } else { teams := r1.Data.([]*model.Team) if len(teams) == 0 { t.Fatal("failed team listing") } } }
func TestGetAudits(t *testing.T) { Setup() team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} rteam, _ := Client.CreateTeam(&team) user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "*****@*****.**", Nickname: "Corey Hulen", Password: "******"} ruser, _ := Client.CreateUser(&user, "") store.Must(Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) time.Sleep(100 * time.Millisecond) Client.LoginByEmail(team.Name, user.Email, user.Password) time.Sleep(100 * time.Millisecond) if result, err := Client.GetAudits(ruser.Data.(*model.User).Id, ""); err != nil { t.Fatal(err) } else { if len(result.Data.(model.Audits)) != 2 { t.Fatal(result.Data.(model.Audits)) } if cache_result, err := Client.GetAudits(ruser.Data.(*model.User).Id, result.Etag); err != nil { t.Fatal(err) } else if cache_result.Data.(model.Audits) != nil { t.Fatal("cache should be empty") } } if _, err := Client.GetAudits("FORBIDDENERROR", ""); err == nil { t.Fatal("audit log shouldn't exist") } }
func TestPostStorePermDelete1Level(t *testing.T) { Setup() o1 := &model.Post{} o1.ChannelId = model.NewId() o1.UserId = model.NewId() o1.Message = "a" + model.NewId() + "b" o1 = (<-store.Post().Save(o1)).Data.(*model.Post) o2 := &model.Post{} o2.ChannelId = o1.ChannelId o2.UserId = model.NewId() o2.Message = "a" + model.NewId() + "b" o2.ParentId = o1.Id o2.RootId = o1.Id o2 = (<-store.Post().Save(o2)).Data.(*model.Post) if r2 := <-store.Post().PermanentDeleteByUser(o2.UserId); r2.Err != nil { t.Fatal(r2.Err) } if r3 := (<-store.Post().Get(o1.Id)); r3.Err != nil { t.Fatal("Deleted id shouldn't have failed") } if r4 := (<-store.Post().Get(o2.Id)); r4.Err == nil { t.Fatal("Deleted id should have failed") } }
func TestFuzzyUserCreate(t *testing.T) { Setup() team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} rteam, _ := Client.CreateTeam(&team) for i := 0; i < len(utils.FUZZY_STRINGS_NAMES) || i < len(utils.FUZZY_STRINGS_EMAILS); i++ { testName := "Name" testEmail := "*****@*****.**" if i < len(utils.FUZZY_STRINGS_NAMES) { testName = utils.FUZZY_STRINGS_NAMES[i] } if i < len(utils.FUZZY_STRINGS_EMAILS) { testEmail = utils.FUZZY_STRINGS_EMAILS[i] } user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + testEmail, Nickname: testName, Password: "******"} _, err := Client.CreateUser(&user, "") if err != nil { t.Fatal(err) } } }
func TestGetAllTeams(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() th.BasicClient.Logout() Client := th.BasicClient team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team) user := &model.User{Email: model.NewId() + "*****@*****.**", Nickname: "Corey Hulen", Password: "******"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) LinkUserToTeam(user, team) store.Must(Srv.Store.User().VerifyEmail(user.Id)) Client.Login(user.Email, "passwd1") Client.SetTeamId(team.Id) if r1, err := Client.GetAllTeams(); err != nil { t.Fatal(err) } else if teams := r1.Data.(map[string]*model.Team); len(teams) != 1 { t.Fatal("non admin users only get the teams that they're a member of") } else if receivedTeam, ok := teams[team.Id]; !ok || receivedTeam.Id != team.Id { t.Fatal("should've received team that the user is a member of") } if r1, err := th.SystemAdminClient.GetAllTeams(); err != nil { t.Fatal(err) } else if teams := r1.Data.(map[string]*model.Team); len(teams) == 1 { t.Fatal("admin users should receive all teams") } else if receivedTeam, ok := teams[team.Id]; !ok || receivedTeam.Id != team.Id { t.Fatal("admin should've received team that they aren't a member of") } }
func TestDeletePosts(t *testing.T) { Setup() team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team) userAdmin := &model.User{TeamId: team.Id, Email: team.Email, Nickname: "Corey Hulen", Password: "******"} userAdmin = Client.Must(Client.CreateUser(userAdmin, "")).Data.(*model.User) store.Must(Srv.Store.User().VerifyEmail(userAdmin.Id)) user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "*****@*****.**", Nickname: "Corey Hulen", Password: "******"} user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User) store.Must(Srv.Store.User().VerifyEmail(user1.Id)) Client.LoginByEmail(team.Name, user1.Email, "pwd") channel1 := &model.Channel{DisplayName: "TestGetPosts", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) time.Sleep(10 * time.Millisecond) post1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"} post1 = Client.Must(Client.CreatePost(post1)).Data.(*model.Post) time.Sleep(10 * time.Millisecond) post1a1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: post1.Id} post1a1 = Client.Must(Client.CreatePost(post1a1)).Data.(*model.Post) time.Sleep(10 * time.Millisecond) post1a2 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: post1.Id, ParentId: post1a1.Id} post1a2 = Client.Must(Client.CreatePost(post1a2)).Data.(*model.Post) time.Sleep(10 * time.Millisecond) post2 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"} post2 = Client.Must(Client.CreatePost(post2)).Data.(*model.Post) time.Sleep(10 * time.Millisecond) post3 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"} post3 = Client.Must(Client.CreatePost(post3)).Data.(*model.Post) time.Sleep(10 * time.Millisecond) post3a1 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a", RootId: post3.Id} post3a1 = Client.Must(Client.CreatePost(post3a1)).Data.(*model.Post) time.Sleep(10 * time.Millisecond) Client.Must(Client.DeletePost(channel1.Id, post3.Id)) r2 := Client.Must(Client.GetPosts(channel1.Id, 0, 10, "")).Data.(*model.PostList) if len(r2.Posts) != 4 { t.Fatal("should have returned 4 items") } time.Sleep(10 * time.Millisecond) post4 := &model.Post{ChannelId: channel1.Id, Message: "a" + model.NewId() + "a"} post4 = Client.Must(Client.CreatePost(post4)).Data.(*model.Post) Client.LoginByEmail(team.Name, userAdmin.Email, "pwd") Client.Must(Client.DeletePost(channel1.Id, post4.Id)) }
func TestFuzzyPosts(t *testing.T) { Setup() team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team) user := &model.User{TeamId: team.Id, Email: model.NewId() + "*****@*****.**", Nickname: "Corey Hulen", Password: "******"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) store.Must(Srv.Store.User().VerifyEmail(user.Id)) Client.LoginByEmail(team.Name, user.Email, "pwd") channel1 := &model.Channel{DisplayName: "Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) filenames := []string{"junk"} for i := 0; i < len(utils.FUZZY_STRINGS_POSTS); i++ { post := &model.Post{ChannelId: channel1.Id, Message: utils.FUZZY_STRINGS_POSTS[i], Filenames: filenames} _, err := Client.CreatePost(post) if err != nil { t.Fatal(err) } } }
func TestOAuthStoreGetAccessData(t *testing.T) { Setup() a1 := model.AccessData{} a1.ClientId = model.NewId() a1.UserId = model.NewId() a1.Token = model.NewId() a1.RefreshToken = model.NewId() a1.ExpiresAt = model.GetMillis() Must(store.OAuth().SaveAccessData(&a1)) if result := <-store.OAuth().GetAccessData(a1.Token); result.Err != nil { t.Fatal(result.Err) } else { ra1 := result.Data.(*model.AccessData) if a1.Token != ra1.Token { t.Fatal("tokens didn't match") } } if err := (<-store.OAuth().GetPreviousAccessData(a1.UserId, a1.ClientId)).Err; err != nil { t.Fatal(err) } if err := (<-store.OAuth().GetPreviousAccessData("user", "junk")).Err; err != nil { t.Fatal(err) } }
func TestSearchHashtagPosts(t *testing.T) { Setup() team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team) user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "*****@*****.**", Nickname: "Corey Hulen", Password: "******"} user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User) store.Must(Srv.Store.User().VerifyEmail(user1.Id)) Client.LoginByEmail(team.Name, user1.Email, "pwd") channel1 := &model.Channel{DisplayName: "TestGetPosts", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id} channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel) post1 := &model.Post{ChannelId: channel1.Id, Message: "#sgtitlereview with space"} post1 = Client.Must(Client.CreatePost(post1)).Data.(*model.Post) post2 := &model.Post{ChannelId: channel1.Id, Message: "#sgtitlereview\n with return"} post2 = Client.Must(Client.CreatePost(post2)).Data.(*model.Post) post3 := &model.Post{ChannelId: channel1.Id, Message: "no hashtag"} post3 = Client.Must(Client.CreatePost(post3)).Data.(*model.Post) r1 := Client.Must(Client.SearchPosts("#sgtitlereview")).Data.(*model.PostList) if len(r1.Order) != 2 { t.Fatal("wrong search") } }
func TestOAuthStoreUpdateApp(t *testing.T) { Setup() a1 := model.OAuthApp{} a1.CreatorId = model.NewId() a1.Name = "TestApp" + model.NewId() a1.CallbackUrls = []string{"https://nowhere.com"} a1.Homepage = "https://nowhere.com" Must(store.OAuth().SaveApp(&a1)) a1.CreateAt = 1 a1.ClientSecret = "pwd" a1.CreatorId = "12345678901234567890123456" a1.Name = "NewName" if result := <-store.OAuth().UpdateApp(&a1); result.Err != nil { t.Fatal(result.Err) } else { ua1 := (result.Data.([2]*model.OAuthApp)[0]) if ua1.Name != "NewName" { t.Fatal("name did not update") } if ua1.CreateAt == 1 { t.Fatal("create at should not have updated") } if ua1.CreatorId == "12345678901234567890123456" { t.Fatal("creator id should not have updated") } } }
func TestOAuthGetAuthorizedApps(t *testing.T) { Setup() a1 := model.OAuthApp{} a1.CreatorId = model.NewId() a1.Name = "TestApp" + model.NewId() a1.CallbackUrls = []string{"https://nowhere.com"} a1.Homepage = "https://nowhere.com" Must(store.OAuth().SaveApp(&a1)) // allow the app p := model.Preference{} p.UserId = a1.CreatorId p.Category = model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP p.Name = a1.Id p.Value = "true" Must(store.Preference().Save(&model.Preferences{p})) if result := <-store.OAuth().GetAuthorizedApps(a1.CreatorId); result.Err != nil { t.Fatal(result.Err) } else { apps := result.Data.([]*model.OAuthApp) if len(apps) == 0 { t.Fatal("It should have return apps") } } }
func (cfg *AutoTeamCreator) createRandomTeam() (*model.Team, bool) { var teamEmail string var teamDisplayName string var teamName string if cfg.Fuzzy { teamEmail = "success+" + model.NewId() + "simulator.amazonses.com" teamDisplayName = utils.FuzzName() teamName = utils.FuzzName() } else { teamEmail = "success+" + model.NewId() + "simulator.amazonses.com" teamDisplayName = utils.RandomName(cfg.NameLength, cfg.NameCharset) teamName = utils.RandomName(cfg.NameLength, cfg.NameCharset) + model.NewId() } team := &model.Team{ DisplayName: teamDisplayName, Name: teamName, Email: teamEmail, Type: model.TEAM_OPEN, } result, err := cfg.client.CreateTeam(team) if err != nil { return nil, false } createdTeam := result.Data.(*model.Team) return createdTeam, true }
func TestUpdateTeamDisplayName(t *testing.T) { Setup() team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team) user := &model.User{TeamId: team.Id, Email: "*****@*****.**", Nickname: "Corey Hulen", Password: "******"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) store.Must(Srv.Store.User().VerifyEmail(user.Id)) user2 := &model.User{TeamId: team.Id, Email: model.NewId() + "*****@*****.**", Nickname: "Corey Hulen", Password: "******"} user2 = Client.Must(Client.CreateUser(user2, "")).Data.(*model.User) store.Must(Srv.Store.User().VerifyEmail(user2.Id)) Client.LoginByEmail(team.Name, user2.Email, "pwd") vteam := &model.Team{DisplayName: team.DisplayName, Name: team.Name, Email: team.Email, Type: team.Type} vteam.DisplayName = "NewName" if _, err := Client.UpdateTeam(vteam); err == nil { t.Fatal("Should have errored, not admin") } Client.LoginByEmail(team.Name, user.Email, "pwd") vteam.DisplayName = "" if _, err := Client.UpdateTeam(vteam); err == nil { t.Fatal("Should have errored, empty name") } vteam.DisplayName = "NewName" if _, err := Client.UpdateTeam(vteam); err != nil { t.Fatal(err) } }
func TestListTeamCommands(t *testing.T) { Setup() enableCommands := *utils.Cfg.ServiceSettings.EnableCommands defer func() { utils.Cfg.ServiceSettings.EnableCommands = &enableCommands }() *utils.Cfg.ServiceSettings.EnableCommands = true team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team) user := &model.User{TeamId: team.Id, Email: model.NewId() + "*****@*****.**", Nickname: "Corey Hulen", Password: "******"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) store.Must(Srv.Store.User().VerifyEmail(user.Id)) c := &Context{} c.RequestId = model.NewId() c.IpAddress = "cmd_line" UpdateRoles(c, user, model.ROLE_SYSTEM_ADMIN) Client.LoginByEmail(team.Name, user.Email, "pwd") cmd1 := &model.Command{URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST} cmd1 = Client.Must(Client.CreateCommand(cmd1)).Data.(*model.Command) if result, err := Client.ListTeamCommands(); err != nil { t.Fatal(err) } else { cmds := result.Data.([]*model.Command) if len(cmds) != 1 { t.Fatal("incorrect number of cmd") } } }
func TestGetMyTeam(t *testing.T) { Setup() team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} rteam, _ := Client.CreateTeam(&team) user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "*****@*****.**", Nickname: "Corey Hulen", Password: "******"} ruser, _ := Client.CreateUser(&user, "") store.Must(Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) Client.LoginByEmail(team.Name, user.Email, user.Password) if result, err := Client.GetMyTeam(""); err != nil { t.Fatal("Failed to get user") } else { if result.Data.(*model.Team).DisplayName != team.DisplayName { t.Fatal("team names did not match") } if result.Data.(*model.Team).Name != team.Name { t.Fatal("team domains did not match") } if result.Data.(*model.Team).Type != team.Type { t.Fatal("team types did not match") } } }
func TestRegenToken(t *testing.T) { Setup() enableCommands := *utils.Cfg.ServiceSettings.EnableCommands defer func() { utils.Cfg.ServiceSettings.EnableCommands = &enableCommands }() *utils.Cfg.ServiceSettings.EnableCommands = true team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team) user := &model.User{TeamId: team.Id, Email: model.NewId() + "*****@*****.**", Nickname: "Corey Hulen", Password: "******"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) store.Must(Srv.Store.User().VerifyEmail(user.Id)) c := &Context{} c.RequestId = model.NewId() c.IpAddress = "cmd_line" UpdateRoles(c, user, model.ROLE_SYSTEM_ADMIN) Client.LoginByEmail(team.Name, user.Email, "pwd") cmd := &model.Command{URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST} cmd = Client.Must(Client.CreateCommand(cmd)).Data.(*model.Command) data := make(map[string]string) data["id"] = cmd.Id if result, err := Client.RegenCommandToken(data); err != nil { t.Fatal(err) } else { if result.Data.(*model.Command).Token == cmd.Token { t.Fatal("regen didn't work properly") } } }
func TestGetPreference(t *testing.T) { th := Setup().InitBasic() Client := th.BasicClient user := th.BasicUser preferences := model.Preferences{ { UserId: user.Id, Category: model.PREFERENCE_CATEGORY_DIRECT_CHANNEL_SHOW, Name: model.NewId(), Value: model.NewId(), }, } Client.Must(Client.SetPreferences(&preferences)) if result, err := Client.GetPreference(preferences[0].Category, preferences[0].Name); err != nil { t.Fatal(err) } else if data := result.Data.(*model.Preference); *data != preferences[0] { t.Fatal("preference saved incorrectly") } preferences[0].Value = model.NewId() Client.Must(Client.SetPreferences(&preferences)) if result, err := Client.GetPreference(preferences[0].Category, preferences[0].Name); err != nil { t.Fatal(err) } else if data := result.Data.(*model.Preference); *data != preferences[0] { t.Fatal("preference updated incorrectly") } }
func TestListCommands(t *testing.T) { Setup() team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team) user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "*****@*****.**", Nickname: "Corey Hulen", Password: "******"} user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User) store.Must(Srv.Store.User().VerifyEmail(user1.Id)) Client.LoginByEmail(team.Name, user1.Email, "pwd") if results, err := Client.ListCommands(); err != nil { t.Fatal(err) } else { commands := results.Data.([]*model.Command) foundEcho := false for _, command := range commands { if command.Trigger == "echo" { foundEcho = true } } if !foundEcho { t.Fatal("Couldn't find echo command") } } }
func TestGetMyTeam(t *testing.T) { th := Setup().InitBasic() th.BasicClient.Logout() Client := th.BasicClient team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} rteam, _ := Client.CreateTeam(team) team = rteam.Data.(*model.Team) user := model.User{Email: "success+" + model.NewId() + "@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "******"} ruser, _ := Client.CreateUser(&user, "") LinkUserToTeam(ruser.Data.(*model.User), rteam.Data.(*model.Team)) store.Must(Srv.Store.User().VerifyEmail(ruser.Data.(*model.User).Id)) Client.Login(user.Email, user.Password) Client.SetTeamId(team.Id) if result, err := Client.GetMyTeam(""); err != nil { t.Fatal(err) } else { if result.Data.(*model.Team).DisplayName != team.DisplayName { t.Fatal("team names did not match") } if result.Data.(*model.Team).Name != team.Name { t.Fatal("team domains did not match") } if result.Data.(*model.Team).Type != team.Type { t.Fatal("team types did not match") } } }
func TestUserCreateImage(t *testing.T) { Setup() b, err := createProfileImage("Corey Hulen", "eo1zkdr96pdj98pjmq8zy35wba") if err != nil { t.Fatal(err) } rdr := bytes.NewReader(b) img, _, err2 := image.Decode(rdr) if err2 != nil { t.Fatal(err) } colorful := color.RGBA{116, 49, 196, 255} if img.At(1, 1) != colorful { t.Fatal("Failed to create correct color") } team := &model.Team{Name: "Name", Domain: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team) user := &model.User{TeamId: team.Id, Email: strings.ToLower(model.NewId()) + "*****@*****.**", Nickname: "Corey Hulen", Password: "******"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) store.Must(Srv.Store.User().VerifyEmail(user.Id)) Client.LoginByEmail(team.Domain, user.Email, "pwd") Client.DoGet("/users/"+user.Id+"/image", "", "") }
func TestStatuses(t *testing.T) { Setup() team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} rteam, _ := Client.CreateTeam(&team) user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "*****@*****.**", Nickname: "Corey Hulen", Password: "******"} ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User) store.Must(Srv.Store.User().VerifyEmail(ruser.Id)) Client.LoginByEmail(team.Name, user.Email, user.Password) r1, err := Client.GetStatuses() if err != nil { t.Fatal(err) } statuses := r1.Data.(map[string]string) if len(statuses) != 1 { t.Fatal("invalid number of statuses") } for _, status := range statuses { if status != model.USER_OFFLINE && status != model.USER_AWAY && status != model.USER_ONLINE { t.Fatal("one of the statuses had an invalid value") } } }
func TestFindTeamByEmail(t *testing.T) { Setup() team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team) user := &model.User{TeamId: team.Id, Email: model.NewId() + "*****@*****.**", Nickname: "Corey Hulen", Password: "******"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) store.Must(Srv.Store.User().VerifyEmail(user.Id)) if r1, err := Client.FindTeams(user.Email); err != nil { t.Fatal(err) } else { teams := r1.Data.(map[string]*model.Team) if teams[team.Id].Name != team.Name { t.Fatal() } if teams[team.Id].DisplayName != team.DisplayName { t.Fatal() } } if _, err := Client.FindTeams("missing"); err != nil { t.Fatal(err) } }
func TestPostStoreGet(t *testing.T) { Setup() o1 := &model.Post{} o1.ChannelId = model.NewId() o1.UserId = model.NewId() o1.Message = "a" + model.NewId() + "b" etag1 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string) if strings.Index(etag1, model.CurrentVersion+".0.") != 0 { t.Fatal("Invalid Etag") } o1 = (<-store.Post().Save(o1)).Data.(*model.Post) etag2 := (<-store.Post().GetEtag(o1.ChannelId)).Data.(string) if strings.Index(etag2, model.CurrentVersion+"."+o1.Id) != 0 { t.Fatal("Invalid Etag") } if r1 := <-store.Post().Get(o1.Id); r1.Err != nil { t.Fatal(r1.Err) } else { if r1.Data.(*model.PostList).Posts[o1.Id].CreateAt != o1.CreateAt { t.Fatal("invalid returned post") } } if err := (<-store.Post().Get("123")).Err; err == nil { t.Fatal("Missing id should have failed") } }
func TestGetAllTeams(t *testing.T) { Setup() team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team) user := &model.User{TeamId: team.Id, Email: model.NewId() + "*****@*****.**", Nickname: "Corey Hulen", Password: "******"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) store.Must(Srv.Store.User().VerifyEmail(user.Id)) Client.LoginByEmail(team.Name, user.Email, "pwd") if _, err := Client.GetAllTeams(); err == nil { t.Fatal("you shouldn't have permissions") } c := &Context{} c.RequestId = model.NewId() c.IpAddress = "cmd_line" UpdateRoles(c, user, model.ROLE_SYSTEM_ADMIN) Client.LoginByEmail(team.Name, user.Email, "pwd") if r1, err := Client.GetAllTeams(); err != nil { t.Fatal(err) } else { teams := r1.Data.(map[string]*model.Team) if teams[team.Id].Name != team.Name { t.Fatal() } } }
func TestTeamStoreGetForEmail(t *testing.T) { Setup() o1 := model.Team{} o1.DisplayName = "DisplayName" o1.Name = "a" + model.NewId() + "b" o1.Email = model.NewId() + "@nowhere.com" o1.Type = model.TEAM_OPEN Must(store.Team().Save(&o1)) u1 := model.User{} u1.TeamId = o1.Id u1.Email = model.NewId() Must(store.User().Save(&u1)) if r1 := <-store.Team().GetTeamsForEmail(u1.Email); r1.Err != nil { t.Fatal(r1.Err) } else { teams := r1.Data.([]*model.Team) if teams[0].Id != o1.Id { t.Fatal("failed to lookup by email") } } if r1 := <-store.Team().GetTeamsForEmail("missing"); r1.Err != nil { t.Fatal(r1.Err) } }
func TestInviteMembers(t *testing.T) { Setup() team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "*****@*****.**", Type: model.TEAM_OPEN} team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team) user := &model.User{TeamId: team.Id, Email: model.NewId() + "*****@*****.**", Nickname: "Corey Hulen", Password: "******"} user = Client.Must(Client.CreateUser(user, "")).Data.(*model.User) store.Must(Srv.Store.User().VerifyEmail(user.Id)) Client.LoginByEmail(team.Name, user.Email, "pwd") invite := make(map[string]string) invite["email"] = model.NewId() + "*****@*****.**" invite["first_name"] = "Test" invite["last_name"] = "Guy" invites := &model.Invites{Invites: []map[string]string{invite}} invites.Invites = append(invites.Invites, invite) if _, err := Client.InviteMembers(invites); err != nil { t.Fatal(err) } invites = &model.Invites{Invites: []map[string]string{}} if _, err := Client.InviteMembers(invites); err == nil { t.Fatal("Should have errored out on no invites to send") } }
func TestTeamStoreUpdate(t *testing.T) { Setup() o1 := model.Team{} o1.DisplayName = "DisplayName" o1.Name = "a" + model.NewId() + "b" o1.Email = model.NewId() + "@nowhere.com" o1.Type = model.TEAM_OPEN if err := (<-store.Team().Save(&o1)).Err; err != nil { t.Fatal(err) } time.Sleep(100 * time.Millisecond) if err := (<-store.Team().Update(&o1)).Err; err != nil { t.Fatal(err) } o1.Id = "missing" if err := (<-store.Team().Update(&o1)).Err; err == nil { t.Fatal("Update should have failed because of missing key") } o1.Id = model.NewId() if err := (<-store.Team().Update(&o1)).Err; err == nil { t.Fatal("Update should have faile because id change") } }
func TestUserStoreUpdatePassword(t *testing.T) { Setup() teamId := model.NewId() u1 := &model.User{} u1.Email = model.NewId() Must(store.User().Save(u1)) Must(store.Team().SaveMember(&model.TeamMember{TeamId: teamId, UserId: u1.Id})) hashedPassword := model.HashPassword("newpwd") if err := (<-store.User().UpdatePassword(u1.Id, hashedPassword)).Err; err != nil { t.Fatal(err) } if r1 := <-store.User().GetByEmail(u1.Email); r1.Err != nil { t.Fatal(r1.Err) } else { user := r1.Data.(*model.User) if user.Password != hashedPassword { t.Fatal("Password was not updated correctly") } } }