summaryrefslogtreecommitdiffstats
path: root/api/oauth_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'api/oauth_test.go')
-rw-r--r--api/oauth_test.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/api/oauth_test.go b/api/oauth_test.go
index 47fc342ce..944b1a95b 100644
--- a/api/oauth_test.go
+++ b/api/oauth_test.go
@@ -222,6 +222,62 @@ func TestGetOAuthAppInfo(t *testing.T) {
}
}
+func TestGetAuthorizedApps(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ Client := th.BasicClient
+ AdminClient := th.SystemAdminClient
+
+ utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
+
+ app := &model.OAuthApp{Name: "TestApp5" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
+
+ app = AdminClient.Must(AdminClient.RegisterApp(app)).Data.(*model.OAuthApp)
+
+ if _, err := Client.AllowOAuth(model.AUTHCODE_RESPONSE_TYPE, app.Id, "https://nowhere.com", "user", ""); err != nil {
+ t.Fatal(err)
+ }
+
+ if result, err := Client.GetOAuthAuthorizedApps(); err != nil {
+ t.Fatal(err)
+ } else {
+ apps := result.Data.([]*model.OAuthApp)
+
+ if len(apps) != 1 {
+ t.Fatal("incorrect number of apps should have been 1")
+ }
+ }
+}
+
+func TestDeauthorizeApp(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ Client := th.BasicClient
+ AdminClient := th.SystemAdminClient
+
+ utils.Cfg.ServiceSettings.EnableOAuthServiceProvider = true
+
+ app := &model.OAuthApp{Name: "TestApp5" + model.NewId(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
+
+ app = AdminClient.Must(AdminClient.RegisterApp(app)).Data.(*model.OAuthApp)
+
+ if _, err := Client.AllowOAuth(model.AUTHCODE_RESPONSE_TYPE, app.Id, "https://nowhere.com", "user", ""); err != nil {
+ t.Fatal(err)
+ }
+
+ if err := Client.OAuthDeauthorizeApp(app.Id); err != nil {
+ t.Fatal(err)
+ }
+
+ if result, err := Client.GetOAuthAuthorizedApps(); err != nil {
+ t.Fatal(err)
+ } else {
+ apps := result.Data.([]*model.OAuthApp)
+
+ if len(apps) != 0 {
+ t.Fatal("incorrect number of apps should have been 0")
+ }
+ }
+}
+
func TestOAuthDeleteApp(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
Client := th.BasicClient