mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
migrate TestAPIImageImportBadSrc to integration test
Signed-off-by: Aditya Mishra <mishraaditya675@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"io"
|
||||
"net/http/httptest"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -189,3 +190,57 @@ func TestImportWithCustomPlatformReject(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestImageImportBadSrc(t *testing.T) {
|
||||
ctx := setupTest(t)
|
||||
apiClient := testEnv.APIClient()
|
||||
|
||||
skip.If(t, testEnv.IsRootless, "rootless daemon cannot access the test's HTTP server in the host's netns")
|
||||
|
||||
server := httptest.NewServer(nil)
|
||||
defer server.Close()
|
||||
|
||||
trimmedHTTP := strings.TrimPrefix(server.URL, "http://")
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
fromSrc string
|
||||
expectErr func(error) bool
|
||||
}{
|
||||
{
|
||||
name: "missing file via full URL",
|
||||
fromSrc: server.URL + "/nofile.tar",
|
||||
expectErr: cerrdefs.IsNotFound,
|
||||
},
|
||||
{
|
||||
name: "missing file via trimmed URL",
|
||||
fromSrc: trimmedHTTP + "/nofile.tar",
|
||||
expectErr: cerrdefs.IsNotFound,
|
||||
},
|
||||
{
|
||||
name: "encoded path via trimmed URL",
|
||||
fromSrc: trimmedHTTP + "/%2Fdata%2Ffile.tar",
|
||||
expectErr: cerrdefs.IsNotFound,
|
||||
},
|
||||
{
|
||||
name: "encoded absolute path",
|
||||
fromSrc: "%2Fdata%2Ffile.tar",
|
||||
expectErr: cerrdefs.IsInvalidArgument,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
_, err := apiClient.ImageImport(ctx,
|
||||
client.ImageImportSource{
|
||||
SourceName: tc.fromSrc,
|
||||
},
|
||||
"import-bad-src:test",
|
||||
client.ImageImportOptions{},
|
||||
)
|
||||
|
||||
assert.Check(t, tc.expectErr(err))
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user