Skip to content

Commit e0fa9e7

Browse files
committed
Add test for private repository issues with public only token
1 parent 3b96731 commit e0fa9e7

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/integration/api_issue_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,34 @@ func TestAPIListIssues(t *testing.T) {
7575
}
7676
}
7777

78+
func TestAPIListIssuesPublicOnly(t *testing.T) {
79+
defer tests.PrepareTestEnv(t)()
80+
81+
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
82+
owner1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo1.OwnerID})
83+
84+
session := loginUser(t, owner1.Name)
85+
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue)
86+
link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/issues", owner1.Name, repo1.Name))
87+
link.RawQuery = url.Values{"state": {"all"}}.Encode()
88+
req := NewRequest(t, "GET", link.String()).AddTokenAuth(token)
89+
MakeRequest(t, req, http.StatusOK)
90+
91+
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
92+
owner2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo2.OwnerID})
93+
94+
session = loginUser(t, owner2.Name)
95+
token = getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue)
96+
link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/issues", owner2.Name, repo2.Name))
97+
link.RawQuery = url.Values{"state": {"all"}}.Encode()
98+
req = NewRequest(t, "GET", link.String()).AddTokenAuth(token)
99+
MakeRequest(t, req, http.StatusOK)
100+
101+
publicOnlyToken := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadIssue, auth_model.AccessTokenScopePublicOnly)
102+
req = NewRequest(t, "GET", link.String()).AddTokenAuth(publicOnlyToken)
103+
MakeRequest(t, req, http.StatusForbidden)
104+
}
105+
78106
func TestAPICreateIssue(t *testing.T) {
79107
defer tests.PrepareTestEnv(t)()
80108
const body, title = "apiTestBody", "apiTestTitle"

0 commit comments

Comments
 (0)