summaryrefslogtreecommitdiffstats
path: root/integrations
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-04-15 06:18:51 +0100
committerGitHub <noreply@github.com>2020-04-15 02:18:51 -0300
commit2e85ad665acad1cc96b45d6b1f9032fc4982c3e7 (patch)
treecbbfe18044271a59fd5d2e757ea3e3a86fd46ad2 /integrations
parent7c8e116987895bf9c67dc133f8aa04a799170a2e (diff)
downloadgitea-2e85ad665acad1cc96b45d6b1f9032fc4982c3e7.tar.gz
gitea-2e85ad665acad1cc96b45d6b1f9032fc4982c3e7.zip
Contents API should return 404 on not exist (#10323)
* Return 404 on not exist * swagger update and use git.IsErrNotExist * Handle delete too * Handle delete too x2 * Fix pr 10323 (#3) * fix TESTS * leafe a note for fututre * placate golangci-lint Signed-off-by: Andrew Thornton <art27@cantab.net> * Update integrations/api_repo_file_delete_test.go Co-Authored-By: 6543 <6543@obermui.de> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Diffstat (limited to 'integrations')
-rw-r--r--integrations/api_repo_file_delete_test.go12
-rw-r--r--integrations/api_repo_get_contents_list_test.go10
-rw-r--r--integrations/api_repo_get_contents_test.go10
3 files changed, 3 insertions, 29 deletions
diff --git a/integrations/api_repo_file_delete_test.go b/integrations/api_repo_file_delete_test.go
index 59b3ff91b6..178aec6f5b 100644
--- a/integrations/api_repo_file_delete_test.go
+++ b/integrations/api_repo_file_delete_test.go
@@ -11,8 +11,6 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -109,18 +107,10 @@ func TestAPIDeleteFile(t *testing.T) {
treePath = fmt.Sprintf("delete/file%d.txt", fileID)
createFile(user2, repo1, treePath)
deleteFileOptions = getDeleteFileOptions()
- correctSHA := deleteFileOptions.SHA
deleteFileOptions.SHA = "badsha"
url = fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo1.Name, treePath, token2)
req = NewRequestWithJSON(t, "DELETE", url, &deleteFileOptions)
- resp = session.MakeRequest(t, req, http.StatusInternalServerError)
- expectedAPIError := context.APIError{
- Message: "sha does not match [given: " + deleteFileOptions.SHA + ", expected: " + correctSHA + "]",
- URL: setting.API.SwaggerURL,
- }
- var apiError context.APIError
- DecodeJSON(t, resp, &apiError)
- assert.Equal(t, expectedAPIError, apiError)
+ resp = session.MakeRequest(t, req, http.StatusBadRequest)
// Test creating a file in repo16 by user4 who does not have write access
fileID++
diff --git a/integrations/api_repo_get_contents_list_test.go b/integrations/api_repo_get_contents_list_test.go
index abc4f42cf4..ddbd877a40 100644
--- a/integrations/api_repo_get_contents_list_test.go
+++ b/integrations/api_repo_get_contents_list_test.go
@@ -11,7 +11,6 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
@@ -139,14 +138,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
// Test file contents a file with a bad ref
ref = "badref"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref)
- resp = session.MakeRequest(t, req, http.StatusInternalServerError)
- expectedAPIError := context.APIError{
- Message: "object does not exist [id: " + ref + ", rel_path: ]",
- URL: setting.API.SwaggerURL,
- }
- var apiError context.APIError
- DecodeJSON(t, resp, &apiError)
- assert.Equal(t, expectedAPIError, apiError)
+ resp = session.MakeRequest(t, req, http.StatusNotFound)
// Test accessing private ref with user token that does not have access - should fail
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo16.Name, treePath, token4)
diff --git a/integrations/api_repo_get_contents_test.go b/integrations/api_repo_get_contents_test.go
index 184e76831b..3d4a31be81 100644
--- a/integrations/api_repo_get_contents_test.go
+++ b/integrations/api_repo_get_contents_test.go
@@ -10,7 +10,6 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
@@ -141,14 +140,7 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
// Test file contents a file with a bad ref
ref = "badref"
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?ref=%s", user2.Name, repo1.Name, treePath, ref)
- resp = session.MakeRequest(t, req, http.StatusInternalServerError)
- expectedAPIError := context.APIError{
- Message: "object does not exist [id: " + ref + ", rel_path: ]",
- URL: setting.API.SwaggerURL,
- }
- var apiError context.APIError
- DecodeJSON(t, resp, &apiError)
- assert.Equal(t, expectedAPIError, apiError)
+ resp = session.MakeRequest(t, req, http.StatusNotFound)
// Test accessing private ref with user token that does not have access - should fail
req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/contents/%s?token=%s", user2.Name, repo16.Name, treePath, token4)