summaryrefslogtreecommitdiffstats
path: root/api/user_test.go
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2015-12-17 12:44:46 -0500
committerJoramWilander <jwawilander@gmail.com>2015-12-17 12:44:46 -0500
commita6ae90ac2a74871331707751e823b4746136ff09 (patch)
tree2651cc8adfeca84a0ee89974ba6c40f167a81123 /api/user_test.go
parent58358ddd7cd0152bf16a7326e1d595524fb51246 (diff)
downloadchat-a6ae90ac2a74871331707751e823b4746136ff09.tar.gz
chat-a6ae90ac2a74871331707751e823b4746136ff09.tar.bz2
chat-a6ae90ac2a74871331707751e823b4746136ff09.zip
Add ability to switch between SSO and email account
Diffstat (limited to 'api/user_test.go')
-rw-r--r--api/user_test.go103
1 files changed, 103 insertions, 0 deletions
diff --git a/api/user_test.go b/api/user_test.go
index 731450321..ffa96cb66 100644
--- a/api/user_test.go
+++ b/api/user_test.go
@@ -1085,3 +1085,106 @@ func TestStatuses(t *testing.T) {
}
}
+
+func TestSwitchToSSO(t *testing.T) {
+ Setup()
+
+ team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
+ rteam, _ := Client.CreateTeam(&team)
+
+ user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
+ ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User)
+ store.Must(Srv.Store.User().VerifyEmail(ruser.Id))
+
+ m := map[string]string{}
+ if _, err := Client.SwitchToSSO(m); err == nil {
+ t.Fatal("should have failed - empty data")
+ }
+
+ m["password"] = "pwd"
+ _, err := Client.SwitchToSSO(m)
+ if err == nil {
+ t.Fatal("should have failed - missing team_name, service, email")
+ }
+
+ m["team_name"] = team.Name
+ if _, err := Client.SwitchToSSO(m); err == nil {
+ t.Fatal("should have failed - missing service, email")
+ }
+
+ m["service"] = "someservice"
+ if _, err := Client.SwitchToSSO(m); err == nil {
+ t.Fatal("should have failed - missing email")
+ }
+
+ m["team_name"] = "junk"
+ if _, err := Client.SwitchToSSO(m); err == nil {
+ t.Fatal("should have failed - bad team name")
+ }
+
+ m["team_name"] = team.Name
+ m["email"] = "junk"
+ if _, err := Client.SwitchToSSO(m); err == nil {
+ t.Fatal("should have failed - bad email")
+ }
+
+ m["email"] = ruser.Email
+ m["password"] = "junk"
+ if _, err := Client.SwitchToSSO(m); err == nil {
+ t.Fatal("should have failed - bad password")
+ }
+}
+
+func TestSwitchToEmail(t *testing.T) {
+ Setup()
+
+ team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
+ rteam, _ := Client.CreateTeam(&team)
+
+ user := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
+ ruser := Client.Must(Client.CreateUser(&user, "")).Data.(*model.User)
+ store.Must(Srv.Store.User().VerifyEmail(ruser.Id))
+
+ user2 := model.User{TeamId: rteam.Data.(*model.Team).Id, Email: strings.ToLower(model.NewId()) + "corey+test@test.com", Nickname: "Corey Hulen", Password: "pwd"}
+ ruser2 := Client.Must(Client.CreateUser(&user2, "")).Data.(*model.User)
+ store.Must(Srv.Store.User().VerifyEmail(ruser2.Id))
+
+ m := map[string]string{}
+ if _, err := Client.SwitchToSSO(m); err == nil {
+ t.Fatal("should have failed - not logged in")
+ }
+
+ Client.LoginByEmail(team.Name, user.Email, user.Password)
+
+ if _, err := Client.SwitchToSSO(m); err == nil {
+ t.Fatal("should have failed - empty data")
+ }
+
+ m["password"] = "pwd"
+ _, err := Client.SwitchToSSO(m)
+ if err == nil {
+ t.Fatal("should have failed - missing team_name, service, email")
+ }
+
+ m["team_name"] = team.Name
+ if _, err := Client.SwitchToSSO(m); err == nil {
+ t.Fatal("should have failed - missing email")
+ }
+
+ m["email"] = ruser.Email
+ m["team_name"] = "junk"
+ if _, err := Client.SwitchToSSO(m); err == nil {
+ t.Fatal("should have failed - bad team name")
+ }
+
+ m["team_name"] = team.Name
+ m["email"] = "junk"
+ if _, err := Client.SwitchToSSO(m); err == nil {
+ t.Fatal("should have failed - bad email")
+ }
+
+ m["email"] = ruser2.Email
+ if _, err := Client.SwitchToSSO(m); err == nil {
+ t.Fatal("should have failed - wrong user")
+ }
+}