summaryrefslogtreecommitdiffstats
path: root/api/oauth_test.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-04-25 12:38:33 -0400
committerCorey Hulen <corey@hulen.com>2017-04-25 09:38:33 -0700
commit8d1a132eda861f3e491a406233b726ff953cdffd (patch)
treef4739b7357c2887a339cebe739abca62a8744e99 /api/oauth_test.go
parent83ca76f8f2bfef819ba928dd1e5c94d65eed46cf (diff)
downloadchat-8d1a132eda861f3e491a406233b726ff953cdffd.tar.gz
chat-8d1a132eda861f3e491a406233b726ff953cdffd.tar.bz2
chat-8d1a132eda861f3e491a406233b726ff953cdffd.zip
Fix OAuth SSO first account creation, add mobile support, and fix refresh tokens (#6181)
Diffstat (limited to 'api/oauth_test.go')
-rw-r--r--api/oauth_test.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/api/oauth_test.go b/api/oauth_test.go
index 9e5102b97..014facb44 100644
--- a/api/oauth_test.go
+++ b/api/oauth_test.go
@@ -517,7 +517,17 @@ func TestOAuthAccessToken(t *testing.T) {
th := Setup().InitBasic()
Client := th.BasicClient
+ enableOAuth := utils.Cfg.ServiceSettings.EnableOAuthServiceProvider
+ adminOnly := *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
+ defer func() {
+ utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = enableOAuth
+ *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = adminOnly
+ utils.SetDefaultRolesBasedOnConfig()
+ }()
utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
+ *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ utils.SetDefaultRolesBasedOnConfig()
+
oauthApp := &model.OAuthApp{Name: "TestApp5" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
oauthApp = Client.Must(Client.RegisterApp(oauthApp)).Data.(*model.OAuthApp)
@@ -593,6 +603,8 @@ func TestOAuthAccessToken(t *testing.T) {
rsp := result.Data.(*model.AccessResponse)
if len(rsp.AccessToken) == 0 {
t.Fatal("access token not returned")
+ } else if len(rsp.RefreshToken) == 0 {
+ t.Fatal("refresh token not returned")
} else {
token = rsp.AccessToken
refreshToken = rsp.RefreshToken
@@ -644,8 +656,21 @@ func TestOAuthAccessToken(t *testing.T) {
}
data.Set("refresh_token", refreshToken)
- if _, err := Client.GetAccessToken(data); err != nil {
+ if result, err := Client.GetAccessToken(data); err != nil {
t.Fatal(err)
+ } else {
+ rsp := result.Data.(*model.AccessResponse)
+ if len(rsp.AccessToken) == 0 {
+ t.Fatal("access token not returned")
+ } else if len(rsp.RefreshToken) == 0 {
+ t.Fatal("refresh token not returned")
+ } else if rsp.RefreshToken == refreshToken {
+ t.Fatal("refresh token did not update")
+ }
+
+ if rsp.TokenType != model.ACCESS_TOKEN_TYPE {
+ t.Fatal("access token type incorrect")
+ }
}
authData := &model.AuthData{ClientId: oauthApp.Id, RedirectUri: oauthApp.CallbackUrls[0], UserId: th.BasicUser.Id, Code: model.NewId(), ExpiresIn: -1}