Skip to content

Commit

Permalink
MGMT-14726: Ensure that manifest filename does not contain spaces.
Browse files Browse the repository at this point in the history
Ensure that in any cases where we are writing or updating a manifest
file that the filename does not contain any spaces.
  • Loading branch information
paul-maidment committed Jul 6, 2023
1 parent fcc7514 commit 4a4e906
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/manifests/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,14 @@ 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 {
if strings.Contains(fileName, " ") {
return m.prepareAndLogError(
ctx,
http.StatusBadRequest,
errors.Errorf("Cluster manifest %s for cluster %s should not include a space in its name.",
fileName,
clusterID))
}
if strings.ContainsRune(fileName, os.PathSeparator) {
return m.prepareAndLogError(
ctx,
Expand Down
36 changes: 36 additions & 0 deletions internal/manifests/manifests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,23 @@ var _ = Describe("ClusterManifestTests", func() {
return fmt.Sprintf("{\"data\":\"%s\"}", largeElementBuilder.String())
}

It("Does not accept a filename that contains spaces", func() {
clusterID := registerCluster().ID
content := "{}"
fileName := "dest FileName"
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 should not include a space in its name.", fileName, clusterID)
Expect(err.StatusCode()).To(Equal(int32(http.StatusBadRequest)))
Expect(err.Error()).To(Equal(expectedErrorMessage))
})

It("accepts manifest in json format and .json extension", func() {
clusterID := registerCluster().ID
jsonContent := encodeToBase64(contentAsJSON)
Expand Down Expand Up @@ -637,6 +654,25 @@ spec:
})

Context("UpdateClusterManifest", func() {
It("Does not accept a filename that contains spaces", func() {
clusterID := registerCluster().ID
destFolder := "manifests"
destFileName := "dest FileName"
response := manifestsAPI.V2UpdateClusterManifest(ctx, operations.V2UpdateClusterManifestParams{
ClusterID: *clusterID,
UpdateManifestParams: &models.UpdateManifestParams{
FileName: fileNameYaml,
Folder: defaultFolder,
UpdatedFolder: &destFolder,
UpdatedFileName: &destFileName,
},
})
err := response.(*common.ApiErrorResponse)
expectedErrorMessage := fmt.Sprintf("Cluster manifest %s for cluster %s should not include a space in its name.", destFileName, clusterID)
Expect(err.StatusCode()).To(Equal(int32(http.StatusBadRequest)))
Expect(err.Error()).To(Equal(expectedErrorMessage))
})

It("moves existing file from one path to another", func() {
clusterID := registerCluster().ID
destFolder := "manifests"
Expand Down

0 comments on commit 4a4e906

Please sign in to comment.