summaryrefslogtreecommitdiffstats
path: root/app/oauth_test.go
diff options
context:
space:
mode:
authorenahum <nahumhbl@gmail.com>2017-04-03 14:37:58 -0300
committerCorey Hulen <corey@hulen.com>2017-04-03 10:37:58 -0700
commit1cbe6e797517089140ee2db12d73c0781f5e3e6b (patch)
tree5671819dcbfdc6f359410e3558135090d3724e4c /app/oauth_test.go
parent68bb5a2ec85a6d34726a137bad65157d0ff65247 (diff)
downloadchat-1cbe6e797517089140ee2db12d73c0781f5e3e6b.tar.gz
chat-1cbe6e797517089140ee2db12d73c0781f5e3e6b.tar.bz2
chat-1cbe6e797517089140ee2db12d73c0781f5e3e6b.zip
Add more OAuth unit tests (#5946)
Diffstat (limited to 'app/oauth_test.go')
-rw-r--r--app/oauth_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/app/oauth_test.go b/app/oauth_test.go
new file mode 100644
index 000000000..3ca3a2d4a
--- /dev/null
+++ b/app/oauth_test.go
@@ -0,0 +1,44 @@
+// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package app
+
+import (
+ "testing"
+
+ "github.com/mattermost/platform/model"
+)
+
+func TestOAuthRevokeAccessToken(t *testing.T) {
+ Setup()
+ if err := RevokeAccessToken(model.NewRandomString(16)); err == nil {
+ t.Fatal("Should have failed bad token")
+ }
+
+ session := &model.Session{}
+ session.CreateAt = model.GetMillis()
+ session.UserId = model.NewId()
+ session.Token = model.NewId()
+ session.Roles = model.ROLE_SYSTEM_USER.Id
+ session.SetExpireInDays(1)
+
+ session, _ = CreateSession(session)
+ if err := RevokeAccessToken(session.Token); err == nil {
+ t.Fatal("Should have failed does not have an access token")
+ }
+
+ accessData := &model.AccessData{}
+ accessData.Token = session.Token
+ accessData.UserId = session.UserId
+ accessData.RedirectUri = "http://example.com"
+ accessData.ClientId = model.NewId()
+ accessData.ExpiresAt = session.ExpiresAt
+
+ if result := <-Srv.Store.OAuth().SaveAccessData(accessData); result.Err != nil {
+ t.Fatal(result.Err)
+ }
+
+ if err := RevokeAccessToken(accessData.Token); err != nil {
+ t.Fatal(err)
+ }
+}