Skip to content

Commit b1e71bd

Browse files
committed
Fix pkg/plugins TLSConfig panic
Fix moby#25046 Signed-off-by: Akihiro Suda <[email protected]>
1 parent 4144e11 commit b1e71bd

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

pkg/plugins/discovery.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func readPluginJSONInfo(name, path string) (*Plugin, error) {
116116
return nil, err
117117
}
118118
p.name = name
119-
if len(p.TLSConfig.CAFile) == 0 {
119+
if p.TLSConfig != nil && len(p.TLSConfig.CAFile) == 0 {
120120
p.TLSConfig.InsecureSkipVerify = true
121121
}
122122
p.activateWait = sync.NewCond(&sync.Mutex{})

pkg/plugins/discovery_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,36 @@ func TestFileJSONSpecPlugin(t *testing.T) {
117117
t.Fatalf("Expected plugin Key `/usr/shared/docker/certs/example-key.pem`, got %s\n", plugin.TLSConfig.KeyFile)
118118
}
119119
}
120+
121+
func TestFileJSONSpecPluginWithoutTLSConfig(t *testing.T) {
122+
tmpdir, unregister := Setup(t)
123+
defer unregister()
124+
125+
p := filepath.Join(tmpdir, "example.json")
126+
spec := `{
127+
"Name": "plugin-example",
128+
"Addr": "https://example.com/docker/plugin"
129+
}`
130+
131+
if err := ioutil.WriteFile(p, []byte(spec), 0644); err != nil {
132+
t.Fatal(err)
133+
}
134+
135+
r := newLocalRegistry()
136+
plugin, err := r.Plugin("example")
137+
if err != nil {
138+
t.Fatal(err)
139+
}
140+
141+
if plugin.name != "example" {
142+
t.Fatalf("Expected plugin `plugin-example`, got %s\n", plugin.Name)
143+
}
144+
145+
if plugin.Addr != "https://example.com/docker/plugin" {
146+
t.Fatalf("Expected plugin addr `https://example.com/docker/plugin`, got %s\n", plugin.Addr)
147+
}
148+
149+
if plugin.TLSConfig != nil {
150+
t.Fatalf("Expected plugin TLSConfig nil, got %v\n", plugin.TLSConfig)
151+
}
152+
}

0 commit comments

Comments
 (0)