Skip to content

Commit

Permalink
Merge pull request docker#155 from GordonTheTurtle/sync-with-upstream…
Browse files Browse the repository at this point in the history
…-19.03-a63faebcf13973933a3ae646e5a9e5befaad42fd

[19.03] sync to upstream 19.03 a63faeb
  • Loading branch information
thaJeztah authored Jun 9, 2019
2 parents cd24d7c + a63faeb commit 51be736
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 5 deletions.
13 changes: 10 additions & 3 deletions cli/context/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func importTar(name string, s Writer, reader io.Reader) error {
tlsData := ContextTLSData{
Endpoints: map[string]EndpointTLSData{},
}

var importedMetaFile bool
for {
hdr, err := tr.Next()
if err == io.EOF {
Expand All @@ -325,6 +325,7 @@ func importTar(name string, s Writer, reader io.Reader) error {
if err := s.CreateOrUpdate(meta); err != nil {
return err
}
importedMetaFile = true
} else if strings.HasPrefix(hdr.Name, "tls/") {
data, err := ioutil.ReadAll(tr)
if err != nil {
Expand All @@ -335,7 +336,9 @@ func importTar(name string, s Writer, reader io.Reader) error {
}
}
}

if !importedMetaFile {
return errdefs.InvalidParameter(errors.New("invalid context: no metadata found"))
}
return s.ResetTLSMaterial(name, &tlsData)
}

Expand All @@ -352,6 +355,7 @@ func importZip(name string, s Writer, reader io.Reader) error {
Endpoints: map[string]EndpointTLSData{},
}

var importedMetaFile bool
for _, zf := range zr.File {
fi := zf.FileInfo()
if fi.IsDir() {
Expand All @@ -376,6 +380,7 @@ func importZip(name string, s Writer, reader io.Reader) error {
if err := s.CreateOrUpdate(meta); err != nil {
return err
}
importedMetaFile = true
} else if strings.HasPrefix(zf.Name, "tls/") {
f, err := zf.Open()
if err != nil {
Expand All @@ -392,7 +397,9 @@ func importZip(name string, s Writer, reader io.Reader) error {
}
}
}

if !importedMetaFile {
return errdefs.InvalidParameter(errors.New("invalid context: no metadata found"))
}
return s.ResetTLSMaterial(name, &tlsData)
}

Expand Down
62 changes: 62 additions & 0 deletions cli/context/store/store_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package store

import (
"archive/tar"
"archive/zip"
"bufio"
"bytes"
Expand Down Expand Up @@ -144,6 +145,39 @@ func TestDetectImportContentType(t *testing.T) {
assert.Assert(t, zipType != ct)
}

func TestImportTarInvalid(t *testing.T) {
testDir, err := ioutil.TempDir("", t.Name())
assert.NilError(t, err)
defer os.RemoveAll(testDir)

tf := path.Join(testDir, "test.context")

f, err := os.Create(tf)
defer f.Close()
assert.NilError(t, err)

tw := tar.NewWriter(f)
hdr := &tar.Header{
Name: "dummy-file",
Mode: 0600,
Size: int64(len("hello world")),
}
err = tw.WriteHeader(hdr)
assert.NilError(t, err)
_, err = tw.Write([]byte("hello world"))
assert.NilError(t, err)
err = tw.Close()
assert.NilError(t, err)

source, err := os.Open(tf)
assert.NilError(t, err)
defer source.Close()
var r io.Reader = source
s := New(testDir, testCfg)
err = Import("tarInvalid", s, r)
assert.ErrorContains(t, err, "invalid context: no metadata found")
}

func TestImportZip(t *testing.T) {
testDir, err := ioutil.TempDir("", t.Name())
assert.NilError(t, err)
Expand Down Expand Up @@ -194,3 +228,31 @@ func TestImportZip(t *testing.T) {
err = Import("zipTest", s, r)
assert.NilError(t, err)
}

func TestImportZipInvalid(t *testing.T) {
testDir, err := ioutil.TempDir("", t.Name())
assert.NilError(t, err)
defer os.RemoveAll(testDir)

zf := path.Join(testDir, "test.zip")

f, err := os.Create(zf)
defer f.Close()
assert.NilError(t, err)
w := zip.NewWriter(f)

df, err := w.Create("dummy-file")
assert.NilError(t, err)
_, err = df.Write([]byte("hello world"))
assert.NilError(t, err)
err = w.Close()
assert.NilError(t, err)

source, err := os.Open(zf)
assert.NilError(t, err)
defer source.Close()
var r io.Reader = source
s := New(testDir, testCfg)
err = Import("zipInvalid", s, r)
assert.ErrorContains(t, err, "invalid context: no metadata found")
}
2 changes: 1 addition & 1 deletion docker.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ifeq ($(DOCKER_CLI_GO_BUILD_CACHE),y)
DOCKER_CLI_MOUNTS += -v "$(CACHE_VOLUME_NAME):/root/.cache/go-build"
endif
VERSION = $(shell cat VERSION)
ENVVARS = -e VERSION=$(VERSION) -e GITCOMMIT -e PLATFORM -e TESTFLAGS -e TESTDIRS
ENVVARS = -e VERSION=$(VERSION) -e GITCOMMIT -e PLATFORM -e TESTFLAGS -e TESTDIRS -e GOOS -e GOARCH -e GOARM

# build docker image (dockerfiles/Dockerfile.build)
.PHONY: build_docker_image
Expand Down
15 changes: 14 additions & 1 deletion scripts/build/.variables
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,18 @@ export LDFLAGS="\

GOOS="${GOOS:-$(go env GOHOSTOS)}"
GOARCH="${GOARCH:-$(go env GOHOSTARCH)}"
export TARGET="build/docker-$GOOS-$GOARCH"
if [ "${GOARCH}" = "arm" ]; then
GOARM="${GOARM:-$(go env GOHOSTARM)}"
fi

TARGET="build/docker-$GOOS-$GOARCH"
if [ "${GOARCH}" = "arm" ] && [ -n "${GOARM}" ]; then
TARGET="${TARGET}-v${GOARM}"
fi

if [ "${GOOS}" = "windows" ]; then
TARGET="${TARGET}.exe"
fi
export TARGET

export SOURCE="github.com/docker/cli/cmd/docker"

0 comments on commit 51be736

Please sign in to comment.