Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

check for /files suffix in API path for dataset #333

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion api/sda/sda.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,16 @@ var getFiles = func(datasetID string, ctx *gin.Context) ([]*database.FileInfo, i
// Files serves a list of files belonging to a dataset
func Files(c *gin.Context) {

// get dataset parameter, remove / prefix and /files suffix
// get dataset parameter
dataset := c.Param("dataset")

if !strings.HasSuffix(dataset, "/files") {
c.String(http.StatusNotFound, "API path not found, maybe /files is missing")

return
}

// remove / prefix and /files suffix
dataset = strings.TrimPrefix(dataset, "/")
dataset = strings.TrimSuffix(dataset, "/files")

Expand Down
12 changes: 12 additions & 0 deletions api/sda/sda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ func TestFiles_Fail(t *testing.T) {
// Mock request and response holders
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Params = []gin.Param{
{
Key: "dataset",
Value: "dataset1/files",
},
}

// Test the outcomes of the handler
Files(c)
Expand Down Expand Up @@ -283,6 +289,12 @@ func TestFiles_Success(t *testing.T) {
// Mock request and response holders
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Params = []gin.Param{
{
Key: "dataset",
Value: "dataset1/files",
},
}

// Test the outcomes of the handler
Files(c)
Expand Down