1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix pkg/plugins TLSConfig panic

Fix #25046

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
This commit is contained in:
Akihiro Suda 2016-07-26 08:37:30 +00:00
parent 4144e11d32
commit b1e71bdd1d
2 changed files with 34 additions and 1 deletions

View file

@ -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{})

View file

@ -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)
}
}