Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MGMT-15684: Return appropriate HTTP error code for invalid manifest file path #5634

Merged
merged 1 commit into from Oct 29, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/manifests/manifests.go
Expand Up @@ -454,16 +454,16 @@ func (m *Manifests) validateManifestFileNames(ctx context.Context, clusterID str
if strings.Contains(fileName, " ") {
return m.prepareAndLogError(
ctx,
http.StatusBadRequest,
http.StatusUnprocessableEntity,
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,
http.StatusBadRequest,
errors.Errorf("Cluster manifest %s for cluster %s should not include a directory in its name.",
http.StatusUnprocessableEntity,
errors.Errorf("Cluster manifest %s for cluster %s should not include a directory in it's name.",
fileName,
clusterID))
}
Expand Down
8 changes: 4 additions & 4 deletions internal/manifests/manifests_test.go
Expand Up @@ -271,7 +271,7 @@ var _ = Describe("ClusterManifestTests", func() {
})
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.StatusCode()).To(Equal(int32(http.StatusUnprocessableEntity)))
Expect(err.Error()).To(Equal(expectedErrorMessage))
})

Expand Down Expand Up @@ -443,8 +443,8 @@ spec:
})
Expect(response).Should(BeAssignableToTypeOf(common.NewApiError(http.StatusBadRequest, errors.New(""))))
err := response.(*common.ApiErrorResponse)
Expect(err.StatusCode()).To(Equal(int32(http.StatusBadRequest)))
Expect(err.Error()).To(ContainSubstring("Cluster manifest openshift/99-test.yaml for cluster " + clusterID.String() + " should not include a directory in its name."))
Expect(err.StatusCode()).To(Equal(int32(http.StatusUnprocessableEntity)))
Expect(err.Error()).To(ContainSubstring("Cluster manifest openshift/99-test.yaml for cluster " + clusterID.String() + " should not include a directory in it's name."))
})

It("Creation fails for a manifest file that exceeds the maximum upload size", func() {
Expand Down Expand Up @@ -864,7 +864,7 @@ invalid YAML content: {
})
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.StatusCode()).To(Equal(int32(http.StatusUnprocessableEntity)))
Expect(err.Error()).To(Equal(expectedErrorMessage))
})

Expand Down