Browse code

Fix pkg/plugins TLSConfig panic

Fix #25046

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>

Akihiro Suda authored on 2016/07/26 17:37:30
Showing 2 changed files
... ...
@@ -116,7 +116,7 @@ func readPluginJSONInfo(name, path string) (*Plugin, error) {
116 116
 		return nil, err
117 117
 	}
118 118
 	p.name = name
119
-	if len(p.TLSConfig.CAFile) == 0 {
119
+	if p.TLSConfig != nil && len(p.TLSConfig.CAFile) == 0 {
120 120
 		p.TLSConfig.InsecureSkipVerify = true
121 121
 	}
122 122
 	p.activateWait = sync.NewCond(&sync.Mutex{})
... ...
@@ -117,3 +117,36 @@ func TestFileJSONSpecPlugin(t *testing.T) {
117 117
 		t.Fatalf("Expected plugin Key `/usr/shared/docker/certs/example-key.pem`, got %s\n", plugin.TLSConfig.KeyFile)
118 118
 	}
119 119
 }
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
+}