mirror of
https://codeberg.org/forgejo-aneksajo/forgejo-aneksajo.git
synced 2025-04-21 05:36:43 +02:00
fixup! fix: return 404 for empty repositories
This commit is contained in:
parent
772c393e3c
commit
79a20ee9c0
2 changed files with 19 additions and 11 deletions
|
@ -364,8 +364,13 @@ func RepoRefForAPI(next http.Handler) http.Handler {
|
|||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
ctx := GetAPIContext(req)
|
||||
|
||||
if ctx.Repo.Repository.IsEmpty {
|
||||
ctx.NotFound(fmt.Errorf("repository is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
if ctx.Repo.GitRepo == nil {
|
||||
ctx.NotFound(fmt.Errorf("no open git repo"))
|
||||
ctx.InternalServerError(fmt.Errorf("no open git repo"))
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -137,20 +137,23 @@ func TestEmptyRepoAddFileByAPI(t *testing.T) {
|
|||
assert.Equal(t, "new_branch", apiRepo.DefaultBranch)
|
||||
}
|
||||
|
||||
func TestEmptyRepoRawAPIRequestsReturn404(t *testing.T) {
|
||||
func TestEmptyRepoAPIRequestsReturn404(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
session := loginUser(t, "user30")
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
|
||||
req := NewRequest(t, "GET", "/api/v1/repos/user30/empty/raw/main/something").AddTokenAuth(token)
|
||||
_ = session.MakeRequest(t, req, http.StatusNotFound)
|
||||
}
|
||||
|
||||
func TestEmptyRepoMediaAPIRequestsReturn404(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
t.Run("Raw", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
session := loginUser(t, "user30")
|
||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
|
||||
req := NewRequest(t, "GET", "/api/v1/repos/user30/empty/media/main/something").AddTokenAuth(token)
|
||||
_ = session.MakeRequest(t, req, http.StatusNotFound)
|
||||
req := NewRequest(t, "GET", "/api/v1/repos/user30/empty/raw/main/something").AddTokenAuth(token)
|
||||
_ = session.MakeRequest(t, req, http.StatusNotFound)
|
||||
})
|
||||
|
||||
t.Run("Media", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", "/api/v1/repos/user30/empty/media/main/something").AddTokenAuth(token)
|
||||
_ = session.MakeRequest(t, req, http.StatusNotFound)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue