Skip to content

Commit

Permalink
Merge component 'engine' from [email protected]:moby/moby master
Browse files Browse the repository at this point in the history
  • Loading branch information
GordonTheTurtle committed Apr 21, 2020
2 parents e12d3f8 + 0ddb019 commit 8e57874
Show file tree
Hide file tree
Showing 13 changed files with 911 additions and 525 deletions.
4 changes: 4 additions & 0 deletions components/engine/integration/plugin/common/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import (
"os"
"testing"

"github.com/docker/docker/pkg/reexec"
"github.com/docker/docker/testutil/environment"
)

var testEnv *environment.Execution

func TestMain(m *testing.M) {
if reexec.Init() {
return
}
var err error
testEnv, err = environment.New()
if err != nil {
Expand Down
121 changes: 121 additions & 0 deletions components/engine/integration/plugin/common/plugin_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
package common // import "github.com/docker/docker/integration/plugin/common"

import (
"context"
"encoding/base64"
"encoding/json"
"io"
"io/ioutil"
"net"
"net/http"
"path"
"strings"
"testing"

"github.com/docker/docker/api/types"
"github.com/docker/docker/testutil/daemon"
"github.com/docker/docker/testutil/fixtures/plugin"
"github.com/docker/docker/testutil/registry"
"github.com/docker/docker/testutil/request"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/skip"
)

func TestPluginInvalidJSON(t *testing.T) {
Expand Down Expand Up @@ -36,3 +49,111 @@ func TestPluginInvalidJSON(t *testing.T) {
})
}
}

func TestPluginInstall(t *testing.T) {
skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
skip.If(t, testEnv.OSType == "windows")
skip.If(t, testEnv.IsRootless, "rootless mode has different view of localhost")

ctx := context.Background()
client := testEnv.APIClient()

t.Run("no auth", func(t *testing.T) {
defer setupTest(t)()

reg := registry.NewV2(t)
defer reg.Close()

name := "test-" + strings.ToLower(t.Name())
repo := path.Join(registry.DefaultURL, name+":latest")
assert.NilError(t, plugin.CreateInRegistry(ctx, repo, nil))

rdr, err := client.PluginInstall(ctx, repo, types.PluginInstallOptions{Disabled: true, RemoteRef: repo})
assert.NilError(t, err)
defer rdr.Close()

_, err = io.Copy(ioutil.Discard, rdr)
assert.NilError(t, err)

_, _, err = client.PluginInspectWithRaw(ctx, repo)
assert.NilError(t, err)
})

t.Run("with htpasswd", func(t *testing.T) {
defer setupTest(t)()

reg := registry.NewV2(t, registry.Htpasswd)
defer reg.Close()

name := "test-" + strings.ToLower(t.Name())
repo := path.Join(registry.DefaultURL, name+":latest")
auth := &types.AuthConfig{ServerAddress: registry.DefaultURL, Username: "testuser", Password: "testpassword"}
assert.NilError(t, plugin.CreateInRegistry(ctx, repo, auth))

authEncoded, err := json.Marshal(auth)
assert.NilError(t, err)

rdr, err := client.PluginInstall(ctx, repo, types.PluginInstallOptions{
RegistryAuth: base64.URLEncoding.EncodeToString(authEncoded),
Disabled: true,
RemoteRef: repo,
})
assert.NilError(t, err)
defer rdr.Close()

_, err = io.Copy(ioutil.Discard, rdr)
assert.NilError(t, err)

_, _, err = client.PluginInspectWithRaw(ctx, repo)
assert.NilError(t, err)
})
t.Run("with insecure", func(t *testing.T) {
skip.If(t, !testEnv.IsLocalDaemon())

addrs, err := net.InterfaceAddrs()
assert.NilError(t, err)

var bindTo string
for _, addr := range addrs {
ip, ok := addr.(*net.IPNet)
if !ok {
continue
}
if ip.IP.IsLoopback() || ip.IP.To4() == nil {
continue
}
bindTo = ip.IP.String()
}

if bindTo == "" {
t.Skip("No suitable interface to bind registry to")
}

regURL := bindTo + ":5000"

d := daemon.New(t)
defer d.Stop(t)

d.Start(t, "--insecure-registry="+regURL)
defer d.Stop(t)

reg := registry.NewV2(t, registry.URL(regURL))
defer reg.Close()

name := "test-" + strings.ToLower(t.Name())
repo := path.Join(regURL, name+":latest")
assert.NilError(t, plugin.CreateInRegistry(ctx, repo, nil, plugin.WithInsecureRegistry(regURL)))

client := d.NewClientT(t)
rdr, err := client.PluginInstall(ctx, repo, types.PluginInstallOptions{Disabled: true, RemoteRef: repo})
assert.NilError(t, err)
defer rdr.Close()

_, err = io.Copy(ioutil.Discard, rdr)
assert.NilError(t, err)

_, _, err = client.PluginInspectWithRaw(ctx, repo)
assert.NilError(t, err)
})
// TODO: test insecure registry with https
}
Loading

0 comments on commit 8e57874

Please sign in to comment.