summaryrefslogtreecommitdiffstats
path: root/app/user_test.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-02-23 03:53:33 -0500
committerGeorge Goldberg <george@gberg.me>2017-02-23 08:53:33 +0000
commit9220254f05b6200de2e8ac78476a8df536c821ec (patch)
tree9fc67b94e25e65ebe85ddef1b0b5a4df6fe263dc /app/user_test.go
parent7883a515e72690e08e10d38fafc741da1e7a0deb (diff)
downloadchat-9220254f05b6200de2e8ac78476a8df536c821ec.tar.gz
chat-9220254f05b6200de2e8ac78476a8df536c821ec.tar.bz2
chat-9220254f05b6200de2e8ac78476a8df536c821ec.zip
Block OAuth account creation when disabled in config (#5506)
Diffstat (limited to 'app/user_test.go')
-rw-r--r--app/user_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/app/user_test.go b/app/user_test.go
index 5b994d219..0dba86241 100644
--- a/app/user_test.go
+++ b/app/user_test.go
@@ -4,7 +4,12 @@
package app
import (
+ "strings"
"testing"
+
+ "github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/model/gitlab"
+ "github.com/mattermost/platform/utils"
)
func TestIsUsernameTaken(t *testing.T) {
@@ -51,3 +56,32 @@ func TestCheckUserDomain(t *testing.T) {
}
}
}
+
+func TestCreateOAuthUser(t *testing.T) {
+ th := Setup().InitBasic()
+ glUser := oauthgitlab.GitLabUser{Id: 1000, Username: model.NewId(), Email: model.NewId() + "@simulator.amazonses.com", Name: "Joram Wilander"}
+
+ json := glUser.ToJson()
+ user, err := CreateOAuthUser(model.USER_AUTH_SERVICE_GITLAB, strings.NewReader(json), th.BasicTeam.Id)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if user.Username != glUser.Username {
+ t.Fatal("usernames didn't match")
+ }
+
+ PermanentDeleteUser(user)
+
+ userCreation := utils.Cfg.TeamSettings.EnableUserCreation
+ defer func() {
+ utils.Cfg.TeamSettings.EnableUserCreation = userCreation
+ }()
+ utils.Cfg.TeamSettings.EnableUserCreation = false
+
+ _, err = CreateOAuthUser(model.USER_AUTH_SERVICE_GITLAB, strings.NewReader(json), th.BasicTeam.Id)
+ if err == nil {
+ t.Fatal("should have failed - user creation disabled")
+ }
+
+}