mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-11 00:10:38 -05:00
fix(api): enforce mustNotBeArchived on repo topics routes (#39260)
Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
committed by
GitHub
parent
df8e7db02f
commit
8b6ad49a5f
@@ -186,3 +186,30 @@ func TestAPIRepoTopic(t *testing.T) {
|
||||
AddTokenAuth(token4)
|
||||
MakeRequest(t, req, http.StatusForbidden)
|
||||
}
|
||||
|
||||
func TestAPIRepoTopicArchived(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 30}) // owner of the archived repo51
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 51})
|
||||
assert.True(t, repo.IsArchived)
|
||||
token := getUserToken(t, user.Name, auth_model.AccessTokenScopeWriteRepository)
|
||||
|
||||
// writing topics on an archived repo must be rejected, matching the web UI
|
||||
req := NewRequestf(t, "PUT", "/api/v1/repos/%s/%s/topics/%s", user.Name, repo.Name, "archivedtopic").
|
||||
AddTokenAuth(token)
|
||||
MakeRequest(t, req, http.StatusLocked)
|
||||
|
||||
req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/topics/%s", user.Name, repo.Name, "archivedtopic").
|
||||
AddTokenAuth(token)
|
||||
MakeRequest(t, req, http.StatusLocked)
|
||||
|
||||
req = NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/topics", user.Name, repo.Name),
|
||||
&api.RepoTopicOptions{Topics: []string{"archivedtopic"}}).AddTokenAuth(token)
|
||||
MakeRequest(t, req, http.StatusLocked)
|
||||
|
||||
// reading topics stays allowed on an archived repo
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/topics", user.Name, repo.Name)).
|
||||
AddTokenAuth(token)
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user