From b1e71bdd1d624e297509a62b072082524dc841fc Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Tue, 26 Jul 2016 08:37:30 +0000 Subject: [PATCH] Fix pkg/plugins TLSConfig panic Fix #25046 Signed-off-by: Akihiro Suda --- pkg/plugins/discovery.go | 2 +- pkg/plugins/discovery_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/pkg/plugins/discovery.go b/pkg/plugins/discovery.go index 2077f2abc5..4297612be0 100644 --- a/pkg/plugins/discovery.go +++ b/pkg/plugins/discovery.go @@ -116,7 +116,7 @@ func readPluginJSONInfo(name, path string) (*Plugin, error) { return nil, err } p.name = name - if len(p.TLSConfig.CAFile) == 0 { + if p.TLSConfig != nil && len(p.TLSConfig.CAFile) == 0 { p.TLSConfig.InsecureSkipVerify = true } p.activateWait = sync.NewCond(&sync.Mutex{}) diff --git a/pkg/plugins/discovery_test.go b/pkg/plugins/discovery_test.go index f74090ee21..203b048eed 100644 --- a/pkg/plugins/discovery_test.go +++ b/pkg/plugins/discovery_test.go @@ -117,3 +117,36 @@ func TestFileJSONSpecPlugin(t *testing.T) { t.Fatalf("Expected plugin Key `/usr/shared/docker/certs/example-key.pem`, got %s\n", plugin.TLSConfig.KeyFile) } } + +func TestFileJSONSpecPluginWithoutTLSConfig(t *testing.T) { + tmpdir, unregister := Setup(t) + defer unregister() + + p := filepath.Join(tmpdir, "example.json") + spec := `{ + "Name": "plugin-example", + "Addr": "https://example.com/docker/plugin" +}` + + if err := ioutil.WriteFile(p, []byte(spec), 0644); err != nil { + t.Fatal(err) + } + + r := newLocalRegistry() + plugin, err := r.Plugin("example") + if err != nil { + t.Fatal(err) + } + + if plugin.name != "example" { + t.Fatalf("Expected plugin `plugin-example`, got %s\n", plugin.Name) + } + + if plugin.Addr != "https://example.com/docker/plugin" { + t.Fatalf("Expected plugin addr `https://example.com/docker/plugin`, got %s\n", plugin.Addr) + } + + if plugin.TLSConfig != nil { + t.Fatalf("Expected plugin TLSConfig nil, got %v\n", plugin.TLSConfig) + } +}