summaryrefslogtreecommitdiffstats
path: root/api4/apitestlib.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-04-20 09:55:02 -0400
committerGitHub <noreply@github.com>2017-04-20 09:55:02 -0400
commitbe9624e2adce7c95039e62fc4ee22538d7fa2d2f (patch)
tree318179b4d3a4cb5114f887797a5a4c836e5255d7 /api4/apitestlib.go
parent1a0f8d1b3c7451eac43bfdc5971de060caabf441 (diff)
downloadchat-be9624e2adce7c95039e62fc4ee22538d7fa2d2f.tar.gz
chat-be9624e2adce7c95039e62fc4ee22538d7fa2d2f.tar.bz2
chat-be9624e2adce7c95039e62fc4ee22538d7fa2d2f.zip
Implement v4 endpoints for OAuth (#6040)
* Implement POST /oauth/apps endpoint for APIv4 * Implement GET /oauth/apps endpoint for APIv4 * Implement GET /oauth/apps/{app_id} and /oauth/apps/{app_id}/info endpoints for APIv4 * Refactor API version independent oauth endpoints * Implement DELETE /oauth/apps/{app_id} endpoint for APIv4 * Implement /oauth/apps/{app_id}/regen_secret endpoint for APIv4 * Implement GET /user/{user_id}/oauth/apps/authorized endpoint for APIv4 * Implement POST /oauth/deauthorize endpoint
Diffstat (limited to 'api4/apitestlib.go')
-rw-r--r--api4/apitestlib.go75
1 files changed, 53 insertions, 22 deletions
diff --git a/api4/apitestlib.go b/api4/apitestlib.go
index 81a9ca311..e6b4fb0c8 100644
--- a/api4/apitestlib.go
+++ b/api4/apitestlib.go
@@ -12,6 +12,7 @@ import (
"runtime/debug"
"strconv"
"strings"
+ "sync"
"testing"
"time"
@@ -107,31 +108,57 @@ func Setup() *TestHelper {
func TearDown() {
utils.DisableDebugLogForTest()
- options := map[string]bool{}
- options[store.USER_SEARCH_OPTION_NAMES_ONLY_NO_FULL_NAME] = true
- if result := <-app.Srv.Store.User().Search("", "fakeuser", options); result.Err != nil {
- l4g.Error("Error tearing down test users")
- } else {
- users := result.Data.([]*model.User)
-
- for _, u := range users {
- if err := app.PermanentDeleteUser(u); err != nil {
- l4g.Error(err.Error())
+ var wg sync.WaitGroup
+ wg.Add(3)
+
+ go func() {
+ defer wg.Done()
+ options := map[string]bool{}
+ options[store.USER_SEARCH_OPTION_NAMES_ONLY_NO_FULL_NAME] = true
+ if result := <-app.Srv.Store.User().Search("", "fakeuser", options); result.Err != nil {
+ l4g.Error("Error tearing down test users")
+ } else {
+ users := result.Data.([]*model.User)
+
+ for _, u := range users {
+ if err := app.PermanentDeleteUser(u); err != nil {
+ l4g.Error(err.Error())
+ }
}
}
- }
-
- if result := <-app.Srv.Store.Team().SearchByName("faketeam"); result.Err != nil {
- l4g.Error("Error tearing down test teams")
- } else {
- teams := result.Data.([]*model.Team)
-
- for _, t := range teams {
- if err := app.PermanentDeleteTeam(t); err != nil {
- l4g.Error(err.Error())
+ }()
+
+ go func() {
+ defer wg.Done()
+ if result := <-app.Srv.Store.Team().SearchByName("faketeam"); result.Err != nil {
+ l4g.Error("Error tearing down test teams")
+ } else {
+ teams := result.Data.([]*model.Team)
+
+ for _, t := range teams {
+ if err := app.PermanentDeleteTeam(t); err != nil {
+ l4g.Error(err.Error())
+ }
}
}
- }
+ }()
+
+ go func() {
+ defer wg.Done()
+ if result := <-app.Srv.Store.OAuth().GetApps(0, 1000); result.Err != nil {
+ l4g.Error("Error tearing down test oauth apps")
+ } else {
+ apps := result.Data.([]*model.OAuthApp)
+
+ for _, a := range apps {
+ if strings.HasPrefix(a.Name, "fakeoauthapp") {
+ <-app.Srv.Store.OAuth().DeleteApp(a.Id)
+ }
+ }
+ }
+ }()
+
+ wg.Wait()
utils.EnableDebugLogForTest()
}
@@ -378,7 +405,7 @@ func GenerateTestEmail() string {
}
func GenerateTestUsername() string {
- return "fakeuser" + model.NewRandomString(13)
+ return "fakeuser" + model.NewRandomString(10)
}
func GenerateTestTeamName() string {
@@ -389,6 +416,10 @@ func GenerateTestChannelName() string {
return "fakechannel" + model.NewRandomString(10)
}
+func GenerateTestAppName() string {
+ return "fakeoauthapp" + model.NewRandomString(10)
+}
+
func GenerateTestId() string {
return model.NewId()
}