Files
gitea/tests/integration/api_repo_secrets_test.go
T
silverwind 159e6d7e75 test(actions): run repo Actions API tests as a non-owner repo admin (#40183)
The repo-level runner, secret and variable API tests ran as the repo
owner, who bypasses the repo admin check. That's how the regression
fixed in https://github.com/go-gitea/gitea/pull/40174 slipped through.
As suggested in
https://github.com/go-gitea/gitea/pull/40174#issuecomment-6591991824,
they now run as an admin collaborator, which replaces the duplicate
subtest added there.

The tests are also trimmed to one case per status code, because
`services/secrets/validation_test.go` already unit tests name
validation.
2026-11-04 17:34:29 +00:00

37 lines
1.3 KiB
Go

// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package integration
import (
"fmt"
"net/http"
"testing"
auth_model "gitea.dev/models/auth"
repo_model "gitea.dev/models/repo"
"gitea.dev/models/unittest"
api "gitea.dev/modules/structs"
"gitea.dev/tests"
)
func TestAPIRepoSecrets(t *testing.T) {
defer tests.PrepareTestEnv(t)()
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
token := getTokenForLoggedInUser(t, loginRepoAdmin(t, repo), auth_model.AccessTokenScopeWriteRepository)
secretsURL := fmt.Sprintf("/api/v1/repos/%s/actions/secrets", repo.FullName())
putSecret := func(name string, expectedStatus int) {
option := api.CreateOrUpdateSecretOption{Data: "data", Description: "description"}
MakeRequest(t, NewRequestWithJSON(t, "PUT", secretsURL+"/"+name, option).AddTokenAuth(token), expectedStatus)
}
MakeRequest(t, NewRequest(t, "GET", secretsURL).AddTokenAuth(token), http.StatusOK)
putSecret("", http.StatusMethodNotAllowed)
putSecret("-", http.StatusBadRequest)
putSecret("secret", http.StatusCreated)
putSecret("secret", http.StatusNoContent)
MakeRequest(t, NewRequest(t, "DELETE", secretsURL+"/secret").AddTokenAuth(token), http.StatusNoContent)
MakeRequest(t, NewRequest(t, "DELETE", secretsURL+"/secret").AddTokenAuth(token), http.StatusNotFound)
}