aboutsummaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-04-08 12:22:10 +0800
committerGitHub <noreply@github.com>2022-04-08 06:22:10 +0200
commit3c3d49899f0f7206e190bdeecdc4da248cc7e686 (patch)
tree7d1f57f7655142b47b5adeb197943c74c1e6f8c9 /integrations
parent75f8534c3a8678f4b55e557960450230cf909b93 (diff)
downloadgitea-3c3d49899f0f7206e190bdeecdc4da248cc7e686.tar.gz
gitea-3c3d49899f0f7206e190bdeecdc4da248cc7e686.zip
Remove dependent on session auth for api/v1 routers (#19321)
* Remove dependent on session auth for api/v1 routers * Remove unnecessary session on API context * remove missed header * fix test * fix missed api/v1
Diffstat (limited to 'integrations')
-rw-r--r--integrations/api_issue_test.go61
-rw-r--r--integrations/api_org_test.go17
-rw-r--r--integrations/api_releases_test.go11
-rw-r--r--integrations/api_repo_topic_test.go42
-rw-r--r--integrations/api_team_test.go17
-rw-r--r--integrations/api_user_heatmap_test.go6
-rw-r--r--integrations/integration_test.go4
-rw-r--r--integrations/issue_test.go22
8 files changed, 87 insertions, 93 deletions
diff --git a/integrations/api_issue_test.go b/integrations/api_issue_test.go
index 3957c10233..5ed5a0ad99 100644
--- a/integrations/api_issue_test.go
+++ b/integrations/api_issue_test.go
@@ -168,12 +168,11 @@ func TestAPIEditIssue(t *testing.T) {
func TestAPISearchIssues(t *testing.T) {
defer prepareTestEnv(t)()
- session := loginUser(t, "user2")
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, "user2")
link, _ := url.Parse("/api/v1/repos/issues/search")
- req := NewRequest(t, "GET", link.String())
- resp := session.MakeRequest(t, req, http.StatusOK)
+ req := NewRequest(t, "GET", link.String()+"?token="+token)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiIssues []*api.Issue
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 10)
@@ -181,7 +180,7 @@ func TestAPISearchIssues(t *testing.T) {
query := url.Values{"token": {token}}
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 10)
@@ -189,9 +188,10 @@ func TestAPISearchIssues(t *testing.T) {
before := time.Unix(999307200, 0).Format(time.RFC3339)
query.Add("since", since)
query.Add("before", before)
+ query.Add("token", token)
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 8)
query.Del("since")
@@ -200,14 +200,14 @@ func TestAPISearchIssues(t *testing.T) {
query.Add("state", "closed")
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 2)
query.Set("state", "all")
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.EqualValues(t, "15", resp.Header().Get("X-Total-Count"))
assert.Len(t, apiIssues, 10) // there are more but 10 is page item limit
@@ -215,49 +215,49 @@ func TestAPISearchIssues(t *testing.T) {
query.Add("limit", "20")
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 15)
- query = url.Values{"assigned": {"true"}, "state": {"all"}}
+ query = url.Values{"assigned": {"true"}, "state": {"all"}, "token": {token}}
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 1)
- query = url.Values{"milestones": {"milestone1"}, "state": {"all"}}
+ query = url.Values{"milestones": {"milestone1"}, "state": {"all"}, "token": {token}}
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 1)
- query = url.Values{"milestones": {"milestone1,milestone3"}, "state": {"all"}}
+ query = url.Values{"milestones": {"milestone1,milestone3"}, "state": {"all"}, "token": {token}}
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 2)
- query = url.Values{"owner": {"user2"}} // user
+ query = url.Values{"owner": {"user2"}, "token": {token}} // user
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 6)
- query = url.Values{"owner": {"user3"}} // organization
+ query = url.Values{"owner": {"user3"}, "token": {token}} // organization
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 3)
- query = url.Values{"owner": {"user3"}, "team": {"team1"}} // organization + team
+ query = url.Values{"owner": {"user3"}, "team": {"team1"}, "token": {token}} // organization + team
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 2)
}
@@ -265,12 +265,11 @@ func TestAPISearchIssues(t *testing.T) {
func TestAPISearchIssuesWithLabels(t *testing.T) {
defer prepareTestEnv(t)()
- session := loginUser(t, "user1")
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, "user1")
link, _ := url.Parse("/api/v1/repos/issues/search")
- req := NewRequest(t, "GET", link.String())
- resp := session.MakeRequest(t, req, http.StatusOK)
+ req := NewRequest(t, "GET", link.String()+"?token="+token)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiIssues []*api.Issue
DecodeJSON(t, resp, &apiIssues)
@@ -280,14 +279,14 @@ func TestAPISearchIssuesWithLabels(t *testing.T) {
query.Add("token", token)
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 10)
query.Add("labels", "label1")
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 2)
@@ -295,7 +294,7 @@ func TestAPISearchIssuesWithLabels(t *testing.T) {
query.Set("labels", "label1,label2")
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 2)
@@ -303,7 +302,7 @@ func TestAPISearchIssuesWithLabels(t *testing.T) {
query.Set("labels", "orglabel4")
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 1)
@@ -312,7 +311,7 @@ func TestAPISearchIssuesWithLabels(t *testing.T) {
query.Add("state", "all")
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 2)
@@ -320,7 +319,7 @@ func TestAPISearchIssuesWithLabels(t *testing.T) {
query.Set("labels", "label1,orglabel4")
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 2)
}
diff --git a/integrations/api_org_test.go b/integrations/api_org_test.go
index e33c010e88..a3c1827e70 100644
--- a/integrations/api_org_test.go
+++ b/integrations/api_org_test.go
@@ -20,9 +20,8 @@ import (
func TestAPIOrgCreate(t *testing.T) {
onGiteaRun(t, func(*testing.T, *url.URL) {
- session := loginUser(t, "user1")
+ token := getUserToken(t, "user1")
- token := getTokenForLoggedInUser(t, session)
org := api.CreateOrgOption{
UserName: "user1_org",
FullName: "User1's organization",
@@ -32,7 +31,7 @@ func TestAPIOrgCreate(t *testing.T) {
Visibility: "limited",
}
req := NewRequestWithJSON(t, "POST", "/api/v1/orgs?token="+token, &org)
- resp := session.MakeRequest(t, req, http.StatusCreated)
+ resp := MakeRequest(t, req, http.StatusCreated)
var apiOrg api.Organization
DecodeJSON(t, resp, &apiOrg)
@@ -50,13 +49,13 @@ func TestAPIOrgCreate(t *testing.T) {
FullName: org.FullName,
})
- req = NewRequestf(t, "GET", "/api/v1/orgs/%s", org.UserName)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ req = NewRequestf(t, "GET", "/api/v1/orgs/%s?token=%s", org.UserName, token)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiOrg)
assert.EqualValues(t, org.UserName, apiOrg.UserName)
- req = NewRequestf(t, "GET", "/api/v1/orgs/%s/repos", org.UserName)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ req = NewRequestf(t, "GET", "/api/v1/orgs/%s/repos?token=%s", org.UserName, token)
+ resp = MakeRequest(t, req, http.StatusOK)
var repos []*api.Repository
DecodeJSON(t, resp, &repos)
@@ -64,8 +63,8 @@ func TestAPIOrgCreate(t *testing.T) {
assert.False(t, repo.Private)
}
- req = NewRequestf(t, "GET", "/api/v1/orgs/%s/members", org.UserName)
- resp = session.MakeRequest(t, req, http.StatusOK)
+ req = NewRequestf(t, "GET", "/api/v1/orgs/%s/members?token=%s", org.UserName, token)
+ resp = MakeRequest(t, req, http.StatusOK)
// user1 on this org is public
var users []*api.User
diff --git a/integrations/api_releases_test.go b/integrations/api_releases_test.go
index 80f53717b6..ebb76cc163 100644
--- a/integrations/api_releases_test.go
+++ b/integrations/api_releases_test.go
@@ -25,12 +25,11 @@ func TestAPIListReleases(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
- session := loginUser(t, user2.LowerName)
- token := getTokenForLoggedInUser(t, session)
+ token := getUserToken(t, user2.LowerName)
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/releases", user2.Name, repo.Name))
link.RawQuery = url.Values{"token": {token}}.Encode()
- resp := session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
+ resp := MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
var apiReleases []*api.Release
DecodeJSON(t, resp, &apiReleases)
if assert.Len(t, apiReleases, 3) {
@@ -53,13 +52,11 @@ func TestAPIListReleases(t *testing.T) {
// test filter
testFilterByLen := func(auth bool, query url.Values, expectedLength int, msgAndArgs ...string) {
- link.RawQuery = query.Encode()
if auth {
query.Set("token", token)
- resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
- } else {
- resp = MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
}
+ link.RawQuery = query.Encode()
+ resp = MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK)
DecodeJSON(t, resp, &apiReleases)
assert.Len(t, apiReleases, expectedLength, msgAndArgs)
}
diff --git a/integrations/api_repo_topic_test.go b/integrations/api_repo_topic_test.go
index b7f9a5a5a6..04295724a7 100644
--- a/integrations/api_repo_topic_test.go
+++ b/integrations/api_repo_topic_test.go
@@ -59,36 +59,34 @@ func TestAPIRepoTopic(t *testing.T) {
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3}).(*repo_model.Repository)
// Get user2's token
- session := loginUser(t, user2.Name)
- token2 := getTokenForLoggedInUser(t, session)
+ token2 := getUserToken(t, user2.Name)
// Test read topics using login
url := fmt.Sprintf("/api/v1/repos/%s/%s/topics", user2.Name, repo2.Name)
- req := NewRequest(t, "GET", url)
- res := session.MakeRequest(t, req, http.StatusOK)
+ req := NewRequest(t, "GET", url+"?token="+token2)
+ res := MakeRequest(t, req, http.StatusOK)
var topics *api.TopicName
DecodeJSON(t, res, &topics)
assert.ElementsMatch(t, []string{"topicname1", "topicname2"}, topics.TopicNames)
// Log out user2
- session = emptyTestSession(t)
url = fmt.Sprintf("/api/v1/repos/%s/%s/topics?token=%s", user2.Name, repo2.Name, token2)
// Test delete a topic
req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/topics/%s?token=%s", user2.Name, repo2.Name, "Topicname1", token2)
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
// Test add an existing topic
req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%s/topics/%s?token=%s", user2.Name, repo2.Name, "Golang", token2)
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
// Test add a topic
req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%s/topics/%s?token=%s", user2.Name, repo2.Name, "topicName3", token2)
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
// Test read topics using token
req = NewRequest(t, "GET", url)
- res = session.MakeRequest(t, req, http.StatusOK)
+ res = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, res, &topics)
assert.ElementsMatch(t, []string{"topicname2", "golang", "topicname3"}, topics.TopicNames)
@@ -97,9 +95,9 @@ func TestAPIRepoTopic(t *testing.T) {
req = NewRequestWithJSON(t, "PUT", url, &api.RepoTopicOptions{
Topics: newTopics,
})
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
req = NewRequest(t, "GET", url)
- res = session.MakeRequest(t, req, http.StatusOK)
+ res = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, res, &topics)
assert.ElementsMatch(t, []string{"windows", "mac"}, topics.TopicNames)
@@ -108,9 +106,9 @@ func TestAPIRepoTopic(t *testing.T) {
req = NewRequestWithJSON(t, "PUT", url, &api.RepoTopicOptions{
Topics: newTopics,
})
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
req = NewRequest(t, "GET", url)
- res = session.MakeRequest(t, req, http.StatusOK)
+ res = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, res, &topics)
assert.ElementsMatch(t, []string{"windows", "mac"}, topics.TopicNames)
@@ -119,9 +117,9 @@ func TestAPIRepoTopic(t *testing.T) {
req = NewRequestWithJSON(t, "PUT", url, &api.RepoTopicOptions{
Topics: newTopics,
})
- session.MakeRequest(t, req, http.StatusNoContent)
+ MakeRequest(t, req, http.StatusNoContent)
req = NewRequest(t, "GET", url)
- res = session.MakeRequest(t, req, http.StatusOK)
+ res = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, res, &topics)
assert.Len(t, topics.TopicNames, 25)
@@ -130,29 +128,27 @@ func TestAPIRepoTopic(t *testing.T) {
req = NewRequestWithJSON(t, "PUT", url, &api.RepoTopicOptions{
Topics: newTopics,
})
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
// Test add a topic when there is already maximum
req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%s/topics/%s?token=%s", user2.Name, repo2.Name, "t26", token2)
- session.MakeRequest(t, req, http.StatusUnprocessableEntity)
+ MakeRequest(t, req, http.StatusUnprocessableEntity)
// Test delete a topic that repo doesn't have
req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/topics/%s?token=%s", user2.Name, repo2.Name, "Topicname1", token2)
- session.MakeRequest(t, req, http.StatusNotFound)
+ MakeRequest(t, req, http.StatusNotFound)
// Get user4's token
- session = loginUser(t, user4.Name)
- token4 := getTokenForLoggedInUser(t, session)
- session = emptyTestSession(t)
+ token4 := getUserToken(t, user4.Name)
// Test read topics with write access
url = fmt.Sprintf("/api/v1/repos/%s/%s/topics?token=%s", user3.Name, repo3.Name, token4)
req = NewRequest(t, "GET", url)
- res = session.MakeRequest(t, req, http.StatusOK)
+ res = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, res, &topics)
assert.Empty(t, topics.TopicNames)
// Test add a topic to repo with write access (requires repo admin access)
req = NewRequestf(t, "PUT", "/api/v1/repos/%s/%s/topics/%s?token=%s", user3.Name, repo3.Name, "topicName", token4)
- session.MakeRequest(t, req, http.StatusForbidden)
+ MakeRequest(t, req, http.StatusForbidden)
}
diff --git a/integrations/api_team_test.go b/integrations/api_team_test.go
index 7f6d1b81d4..daf1efa2be 100644
--- a/integrations/api_team_test.go
+++ b/integrations/api_team_test.go
@@ -224,11 +224,9 @@ func TestAPITeamSearch(t *testing.T) {
var results TeamSearchResults
- session := loginUser(t, user.Name)
- csrf := GetCSRF(t, session, "/"+org.Name)
- req := NewRequestf(t, "GET", "/api/v1/orgs/%s/teams/search?q=%s", org.Name, "_team")
- req.Header.Add("X-Csrf-Token", csrf)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ token := getUserToken(t, user.Name)
+ req := NewRequestf(t, "GET", "/api/v1/orgs/%s/teams/search?q=%s&token=%s", org.Name, "_team", token)
+ resp := MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &results)
assert.NotEmpty(t, results.Data)
assert.Len(t, results.Data, 1)
@@ -236,9 +234,8 @@ func TestAPITeamSearch(t *testing.T) {
// no access if not organization member
user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
- session = loginUser(t, user5.Name)
- csrf = GetCSRF(t, session, "/"+org.Name)
- req = NewRequestf(t, "GET", "/api/v1/orgs/%s/teams/search?q=%s", org.Name, "team")
- req.Header.Add("X-Csrf-Token", csrf)
- session.MakeRequest(t, req, http.StatusForbidden)
+ token5 := getUserToken(t, user5.Name)
+
+ req = NewRequestf(t, "GET", "/api/v1/orgs/%s/teams/search?q=%s&token=%s", org.Name, "team", token5)
+ MakeRequest(t, req, http.StatusForbidden)
}
diff --git a/integrations/api_user_heatmap_test.go b/integrations/api_user_heatmap_test.go
index 69f4ff2249..62e70d4c3d 100644
--- a/integrations/api_user_heatmap_test.go
+++ b/integrations/api_user_heatmap_test.go
@@ -20,15 +20,15 @@ func TestUserHeatmap(t *testing.T) {
defer prepareTestEnv(t)()
adminUsername := "user1"
normalUsername := "user2"
- session := loginUser(t, adminUsername)
+ token := getUserToken(t, adminUsername)
fakeNow := time.Date(2011, 10, 20, 0, 0, 0, 0, time.Local)
timeutil.Set(fakeNow)
defer timeutil.Unset()
- urlStr := fmt.Sprintf("/api/v1/users/%s/heatmap", normalUsername)
+ urlStr := fmt.Sprintf("/api/v1/users/%s/heatmap?token=%s", normalUsername, token)
req := NewRequest(t, "GET", urlStr)
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var heatmap []*models.UserHeatmapData
DecodeJSON(t, resp, &heatmap)
var dummyheatmap []*models.UserHeatmapData
diff --git a/integrations/integration_test.go b/integrations/integration_test.go
index 9e0445cae7..e7ceb33e96 100644
--- a/integrations/integration_test.go
+++ b/integrations/integration_test.go
@@ -359,6 +359,10 @@ func emptyTestSession(t testing.TB) *TestSession {
return &TestSession{jar: jar}
}
+func getUserToken(t testing.TB, userName string) string {
+ return getTokenForLoggedInUser(t, loginUser(t, userName))
+}
+
func loginUser(t testing.TB, userName string) *TestSession {
t.Helper()
if session, ok := loginSessionCache[userName]; ok {
diff --git a/integrations/issue_test.go b/integrations/issue_test.go
index 8a58f59baa..c6b801c9a6 100644
--- a/integrations/issue_test.go
+++ b/integrations/issue_test.go
@@ -448,27 +448,29 @@ func TestSearchIssues(t *testing.T) {
func TestSearchIssuesWithLabels(t *testing.T) {
defer prepareTestEnv(t)()
- session := loginUser(t, "user1")
+ token := getUserToken(t, "user1")
- link, _ := url.Parse("/api/v1/repos/issues/search")
+ link, _ := url.Parse("/api/v1/repos/issues/search?token=" + token)
req := NewRequest(t, "GET", link.String())
- resp := session.MakeRequest(t, req, http.StatusOK)
+ resp := MakeRequest(t, req, http.StatusOK)
var apiIssues []*api.Issue
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 10)
- query := url.Values{}
+ query := url.Values{
+ "token": []string{token},
+ }
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 10)
query.Add("labels", "label1")
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 2)
@@ -476,7 +478,7 @@ func TestSearchIssuesWithLabels(t *testing.T) {
query.Set("labels", "label1,label2")
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 2)
@@ -484,7 +486,7 @@ func TestSearchIssuesWithLabels(t *testing.T) {
query.Set("labels", "orglabel4")
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 1)
@@ -493,7 +495,7 @@ func TestSearchIssuesWithLabels(t *testing.T) {
query.Add("state", "all")
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 2)
@@ -501,7 +503,7 @@ func TestSearchIssuesWithLabels(t *testing.T) {
query.Set("labels", "label1,orglabel4")
link.RawQuery = query.Encode()
req = NewRequest(t, "GET", link.String())
- resp = session.MakeRequest(t, req, http.StatusOK)
+ resp = MakeRequest(t, req, http.StatusOK)
DecodeJSON(t, resp, &apiIssues)
assert.Len(t, apiIssues, 2)
}