From 4d31c8e69dbbd97360c6af06e1ae6d5cabbe4f1b Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Fri, 14 Jan 2022 19:57:00 +0100 Subject: [PATCH] weldr: change all OSTree related error IDs to OSTreeOptionsError These will all be reported from the same validation function. --- internal/weldr/api.go | 4 ++-- internal/weldr/api_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/weldr/api.go b/internal/weldr/api.go index dcaf8f354..f33e54381 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -2229,7 +2229,7 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request cr.OSTree.Ref = imageType.OSTreeRef() } else if !ostree.VerifyRef(cr.OSTree.Ref) { errors := responseError{ - ID: "InvalidChars", + ID: "OSTreeOptionsError", Msg: "Invalid ostree ref", } statusResponseError(writer, http.StatusBadRequest, errors) @@ -2278,7 +2278,7 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request parent, err = ostree.ResolveRef(cr.OSTree.URL, cr.OSTree.Ref) if err != nil { errors := responseError{ - ID: "OSTreeCommitError", + ID: "OSTreeOptionsError", Msg: err.Error(), } statusResponseError(writer, http.StatusBadRequest, errors) diff --git a/internal/weldr/api_test.go b/internal/weldr/api_test.go index 6758ea492..fb13de56d 100644 --- a/internal/weldr/api_test.go +++ b/internal/weldr/api_test.go @@ -819,9 +819,9 @@ func TestCompose(t *testing.T) { // Ref + URL = OK {false, "POST", "/api/v1/compose?test=2", fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"refid","parent":"","url":"http://ostree/"}}`, test_distro.TestImageTypeName), http.StatusOK, `{"status": true}`, expectedComposeOSTreeURL, []string{"build_id"}}, // Ref + invalid URL = error - {false, "POST", "/api/v1/compose", fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"refid","parent":"","url":"invalid-url"}}`, test_distro.TestImageTypeName), http.StatusBadRequest, `{"status":false,"errors":[{"id":"OSTreeCommitError","msg":"Get \"invalid-url/refs/heads/refid\": unsupported protocol scheme \"\""}]}`, nil, []string{"build_id"}}, + {false, "POST", "/api/v1/compose", fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"refid","parent":"","url":"invalid-url"}}`, test_distro.TestImageTypeName), http.StatusBadRequest, `{"status":false,"errors":[{"id":"OSTreeOptionsError","msg":"Get \"invalid-url/refs/heads/refid\": unsupported protocol scheme \"\""}]}`, nil, []string{"build_id"}}, // Bad Ref + URL = error - {false, "POST", "/api/v1/compose", fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"/bad/ref","parent":"","url":"http://ostree/"}}`, test_distro.TestImageTypeName), http.StatusBadRequest, `{"status":false,"errors":[{"id":"InvalidChars","msg":"Invalid ostree ref"}]}`, expectedComposeOSTreeURL, []string{"build_id"}}, + {false, "POST", "/api/v1/compose", fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"/bad/ref","parent":"","url":"http://ostree/"}}`, test_distro.TestImageTypeName), http.StatusBadRequest, `{"status":false,"errors":[{"id":"OSTreeOptionsError","msg":"Invalid ostree ref"}]}`, expectedComposeOSTreeURL, []string{"build_id"}}, // Ref + Parent + URL = error {false, "POST", "/api/v1/compose", fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"refid","parent":"parentid","url":"http://ostree/"}}`, test_distro.TestImageTypeName), http.StatusBadRequest, `{"status":false,"errors":[{"id":"OSTreeOptionsError","msg":"Supply at most one of Parent and URL"}]}`, expectedComposeOSTreeRef, []string{"build_id"}}, // Parent + URL = error