diff --git a/api/sda/sda.go b/api/sda/sda.go index 614a11e..c86731f 100644 --- a/api/sda/sda.go +++ b/api/sda/sda.go @@ -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") diff --git a/api/sda/sda_test.go b/api/sda/sda_test.go index 7bc4af3..148a777 100644 --- a/api/sda/sda_test.go +++ b/api/sda/sda_test.go @@ -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) @@ -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)