summaryrefslogtreecommitdiffstats
path: root/api4/user_test.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-04-10 08:19:49 -0400
committerChristopher Speller <crspeller@gmail.com>2017-04-10 08:19:49 -0400
commitdfc6db737411bd4ad68a803be5182f06055a1769 (patch)
tree375d93b8d1d8b1384988dc708c9f337e0ea2366c /api4/user_test.go
parent7b77bcf87e85330a1f7f0b2a2dcbf71326bf2fba (diff)
downloadchat-dfc6db737411bd4ad68a803be5182f06055a1769.tar.gz
chat-dfc6db737411bd4ad68a803be5182f06055a1769.tar.bz2
chat-dfc6db737411bd4ad68a803be5182f06055a1769.zip
Refactor switching login type code into app layer and add v4 endpoint (#6000)
* Refactor switching login type code into app layer and add v4 endpoint * Fix unit test
Diffstat (limited to 'api4/user_test.go')
-rw-r--r--api4/user_test.go93
1 files changed, 92 insertions, 1 deletions
diff --git a/api4/user_test.go b/api4/user_test.go
index b3e4edc3d..f904bd460 100644
--- a/api4/user_test.go
+++ b/api4/user_test.go
@@ -1297,7 +1297,7 @@ func TestUpdateUserPassword(t *testing.T) {
// Should fail because account is locked out
_, resp = Client.UpdateUserPassword(th.BasicUser.Id, th.BasicUser.Password, "newpwd")
CheckErrorMessage(t, resp, "api.user.check_user_login_attempts.too_many.app_error")
- CheckForbiddenStatus(t, resp)
+ CheckUnauthorizedStatus(t, resp)
// System admin can update another user's password
adminSetPassword := "pwdsetbyadmin"
@@ -1651,3 +1651,94 @@ func TestSetProfileImage(t *testing.T) {
t.Fatal(err)
}
}
+
+func TestSwitchAccount(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+
+ enableGitLab := utils.Cfg.GitLabSettings.Enable
+ defer func() {
+ utils.Cfg.GitLabSettings.Enable = enableGitLab
+ }()
+ utils.Cfg.GitLabSettings.Enable = true
+
+ Client.Logout()
+
+ sr := &model.SwitchRequest{
+ CurrentService: model.USER_AUTH_SERVICE_EMAIL,
+ NewService: model.USER_AUTH_SERVICE_GITLAB,
+ Email: th.BasicUser.Email,
+ Password: th.BasicUser.Password,
+ }
+
+ link, resp := Client.SwitchAccountType(sr)
+ CheckNoError(t, resp)
+
+ if link == "" {
+ t.Fatal("bad link")
+ }
+
+ th.LoginBasic()
+
+ fakeAuthData := "1"
+ if result := <-app.Srv.Store.User().UpdateAuthData(th.BasicUser.Id, model.USER_AUTH_SERVICE_GITLAB, &fakeAuthData, th.BasicUser.Email, true); result.Err != nil {
+ t.Fatal(result.Err)
+ }
+
+ sr = &model.SwitchRequest{
+ CurrentService: model.USER_AUTH_SERVICE_GITLAB,
+ NewService: model.USER_AUTH_SERVICE_EMAIL,
+ Email: th.BasicUser.Email,
+ NewPassword: th.BasicUser.Password,
+ }
+
+ link, resp = Client.SwitchAccountType(sr)
+ CheckNoError(t, resp)
+
+ if link != "/login?extra=signin_change" {
+ t.Log(link)
+ t.Fatal("bad link")
+ }
+
+ Client.Logout()
+ _, resp = Client.Login(th.BasicUser.Email, th.BasicUser.Password)
+ CheckNoError(t, resp)
+ Client.Logout()
+
+ sr = &model.SwitchRequest{
+ CurrentService: model.USER_AUTH_SERVICE_GITLAB,
+ NewService: model.SERVICE_GOOGLE,
+ }
+
+ _, resp = Client.SwitchAccountType(sr)
+ CheckBadRequestStatus(t, resp)
+
+ sr = &model.SwitchRequest{
+ CurrentService: model.USER_AUTH_SERVICE_EMAIL,
+ NewService: model.USER_AUTH_SERVICE_GITLAB,
+ Password: th.BasicUser.Password,
+ }
+
+ _, resp = Client.SwitchAccountType(sr)
+ CheckNotFoundStatus(t, resp)
+
+ sr = &model.SwitchRequest{
+ CurrentService: model.USER_AUTH_SERVICE_EMAIL,
+ NewService: model.USER_AUTH_SERVICE_GITLAB,
+ Email: th.BasicUser.Email,
+ }
+
+ _, resp = Client.SwitchAccountType(sr)
+ CheckUnauthorizedStatus(t, resp)
+
+ sr = &model.SwitchRequest{
+ CurrentService: model.USER_AUTH_SERVICE_GITLAB,
+ NewService: model.USER_AUTH_SERVICE_EMAIL,
+ Email: th.BasicUser.Email,
+ NewPassword: th.BasicUser.Password,
+ }
+
+ _, resp = Client.SwitchAccountType(sr)
+ CheckUnauthorizedStatus(t, resp)
+}