This repository has been archived by the owner on Oct 13, 2023. It is now read-only.
forked from moby/moby
-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from thaJeztah/18.09_backport_handle_invalid_…
…json [18.09 backport] API: properly handle invalid JSON to return a 400 status
- Loading branch information
Showing
11 changed files
with
248 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package container // import "github.com/docker/docker/integration/container" | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/docker/docker/internal/test/request" | ||
"gotest.tools/assert" | ||
is "gotest.tools/assert/cmp" | ||
) | ||
|
||
func TestContainerInvalidJSON(t *testing.T) { | ||
defer setupTest(t)() | ||
|
||
endpoints := []string{ | ||
"/containers/foobar/copy", | ||
"/containers/foobar/exec", | ||
"/exec/foobar/start", | ||
} | ||
|
||
for _, ep := range endpoints { | ||
t.Run(ep, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
res, body, err := request.Post(ep, request.RawString("{invalid json"), request.JSON) | ||
assert.NilError(t, err) | ||
assert.Equal(t, res.StatusCode, http.StatusBadRequest) | ||
|
||
buf, err := request.ReadBody(body) | ||
assert.NilError(t, err) | ||
assert.Check(t, is.Contains(string(buf), "invalid character 'i' looking for beginning of object key string")) | ||
|
||
res, body, err = request.Post(ep, request.JSON) | ||
assert.NilError(t, err) | ||
assert.Equal(t, res.StatusCode, http.StatusBadRequest) | ||
|
||
buf, err = request.ReadBody(body) | ||
assert.NilError(t, err) | ||
assert.Check(t, is.Contains(string(buf), "got EOF while reading request body")) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package common // import "github.com/docker/docker/integration/plugin/common" | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/docker/docker/internal/test/environment" | ||
) | ||
|
||
var testEnv *environment.Execution | ||
|
||
func TestMain(m *testing.M) { | ||
var err error | ||
testEnv, err = environment.New() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
testEnv.Print() | ||
os.Exit(m.Run()) | ||
} | ||
|
||
func setupTest(t *testing.T) func() { | ||
environment.ProtectAll(t, testEnv) | ||
return func() { testEnv.Clean(t) } | ||
} |
Oops, something went wrong.