diff --git a/internal/manifests/manifests.go b/internal/manifests/manifests.go index 9b43bafc74..ebf9c2c646 100644 --- a/internal/manifests/manifests.go +++ b/internal/manifests/manifests.go @@ -451,6 +451,15 @@ func (m *Manifests) fetchManifestContent(ctx context.Context, clusterID strfmt.U func (m *Manifests) validateManifestFileNames(ctx context.Context, clusterID strfmt.UUID, fileNames []string) error { for _, fileName := range fileNames { + fileNameWithoutExtension := strings.TrimSuffix(fileName, filepath.Ext(fileName)) + if len(strings.TrimSpace(fileNameWithoutExtension)) == 0 { + return m.prepareAndLogError( + ctx, + http.StatusUnprocessableEntity, + errors.Errorf("Cluster manifest %s for cluster %s has an invalid filename.", + fileName, + clusterID)) + } if strings.Contains(fileName, " ") { return m.prepareAndLogError( ctx, diff --git a/internal/manifests/manifests_test.go b/internal/manifests/manifests_test.go index 4341c24dda..be52183a36 100644 --- a/internal/manifests/manifests_test.go +++ b/internal/manifests/manifests_test.go @@ -258,6 +258,23 @@ var _ = Describe("ClusterManifestTests", func() { return fmt.Sprintf("{\"data\":\"%s\"}", largeElementBuilder.String()) } + It("Does not accept a filename that does not contain a name before the extension", func() { + clusterID := registerCluster().ID + content := "{}" + fileName := ".yaml" + response := manifestsAPI.V2CreateClusterManifest(ctx, operations.V2CreateClusterManifestParams{ + ClusterID: *clusterID, + CreateManifestParams: &models.CreateManifestParams{ + Content: &content, + FileName: &fileName, + }, + }) + err := response.(*common.ApiErrorResponse) + expectedErrorMessage := fmt.Sprintf("Cluster manifest %s for cluster %s has an invalid filename.", fileName, clusterID) + Expect(err.StatusCode()).To(Equal(int32(http.StatusUnprocessableEntity))) + Expect(err.Error()).To(Equal(expectedErrorMessage)) + }) + It("Does not accept a filename that contains spaces", func() { clusterID := registerCluster().ID content := "{}"