From 9b430f4ec1083d2e73abe4269a85c8cdd91a5ade Mon Sep 17 00:00:00 2001 From: Phil Estes Date: Thu, 23 Oct 2014 13:34:06 -0400 Subject: [PATCH 1/2] Fix error string mapping to HTTP response code to ignore case Docker-DCO-1.1-Signed-off-by: Phil Estes (github: estesp) --- api/server/server.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/api/server/server.go b/api/server/server.go index a3edbdc636..ffad992caf 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -92,17 +92,18 @@ func httpError(w http.ResponseWriter, err error) { // FIXME: this is brittle and should not be necessary. // If we need to differentiate between different possible error types, we should // create appropriate error types with clearly defined meaning. - if strings.Contains(err.Error(), "no such") { + errStr := strings.ToLower(err.Error()) + if strings.Contains(errStr, "no such") { statusCode = http.StatusNotFound - } else if strings.Contains(err.Error(), "Bad parameter") { + } else if strings.Contains(errStr, "bad parameter") { statusCode = http.StatusBadRequest - } else if strings.Contains(err.Error(), "Conflict") { + } else if strings.Contains(errStr, "conflict") { statusCode = http.StatusConflict - } else if strings.Contains(err.Error(), "Impossible") { + } else if strings.Contains(errStr, "impossible") { statusCode = http.StatusNotAcceptable - } else if strings.Contains(err.Error(), "Wrong login/password") { + } else if strings.Contains(errStr, "wrong login/password") { statusCode = http.StatusUnauthorized - } else if strings.Contains(err.Error(), "hasn't been activated") { + } else if strings.Contains(errStr, "hasn't been activated") { statusCode = http.StatusForbidden } @@ -1050,7 +1051,7 @@ func postContainersCopy(eng *engine.Engine, version version.Version, w http.Resp w.Header().Set("Content-Type", "application/x-tar") if err := job.Run(); err != nil { log.Errorf("%s", err.Error()) - if strings.Contains(err.Error(), "No such container") { + if strings.Contains(strings.ToLower(err.Error()), "no such container") { w.WriteHeader(http.StatusNotFound) } else if strings.Contains(err.Error(), "no such file or directory") { return fmt.Errorf("Could not find the file %s in container %s", origResource, vars["name"]) From 6589044b5b84f82a71a756708b4a77b0bc49db42 Mon Sep 17 00:00:00 2001 From: Phil Estes Date: Thu, 23 Oct 2014 14:13:11 -0400 Subject: [PATCH 2/2] Fix volume test using "find" to properly call find with /hello path Docker-DCO-1.1-Signed-off-by: Phil Estes (github: estesp) --- integration-cli/docker_cli_run_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index c4cf8820bd..927b48e59a 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -1611,7 +1611,7 @@ func TestRunCopyVolumeContent(t *testing.T) { } // Test that the content is copied from the image to the volume - cmd := exec.Command(dockerBinary, "run", "--rm", "-v", "/hello", name, "sh", "-c", "find", "/hello") + cmd := exec.Command(dockerBinary, "run", "--rm", "-v", "/hello", name, "find", "/hello") out, _, err := runCommandWithOutput(cmd) if err != nil { t.Fatal(err, out)