Browse code

tests: add plugin install test w/ digest

Adds a test case for installing a plugin from a remote in the form
of `plugin-content-trust@sha256:d98f2f8061...`, which is currently
causing the daemon to panic, as we found while running the CLI e2e
tests:

```
docker plugin install registry:5000/plugin-content-trust@sha256:d98f2f806144bf4ba62d4ecaf78fec2f2fe350df5a001f6e3b491c393326aedb
```

Signed-off-by: Laura Brehm <laurabrehm@hey.com>

Laura Brehm authored on 2024/02/02 01:31:08
Showing 1 changed files
... ...
@@ -124,6 +124,49 @@ func TestPluginInstall(t *testing.T) {
124 124
 		assert.NilError(t, err)
125 125
 	})
126 126
 
127
+	t.Run("with digest", func(t *testing.T) {
128
+		ctx := setupTest(t)
129
+
130
+		reg := registry.NewV2(t)
131
+		defer reg.Close()
132
+
133
+		name := "test-" + strings.ToLower(t.Name())
134
+		repo := path.Join(registry.DefaultURL, name+":latest")
135
+		err := plugin.Create(ctx, client, repo)
136
+		assert.NilError(t, err)
137
+
138
+		rdr, err := client.PluginPush(ctx, repo, "")
139
+		assert.NilError(t, err)
140
+		defer rdr.Close()
141
+
142
+		buf := &strings.Builder{}
143
+		assert.NilError(t, err)
144
+		var digest string
145
+		assert.NilError(t, jsonmessage.DisplayJSONMessagesStream(rdr, buf, 0, false, func(j jsonmessage.JSONMessage) {
146
+			if j.Aux != nil {
147
+				var r types.PushResult
148
+				assert.NilError(t, json.Unmarshal(*j.Aux, &r))
149
+				digest = r.Digest
150
+			}
151
+		}), buf)
152
+
153
+		err = client.PluginRemove(ctx, repo, types.PluginRemoveOptions{Force: true})
154
+		assert.NilError(t, err)
155
+
156
+		rdr, err = client.PluginInstall(ctx, repo, types.PluginInstallOptions{
157
+			Disabled:  true,
158
+			RemoteRef: repo + "@" + digest,
159
+		})
160
+		assert.NilError(t, err)
161
+		defer rdr.Close()
162
+
163
+		_, err = io.Copy(io.Discard, rdr)
164
+		assert.NilError(t, err)
165
+
166
+		_, _, err = client.PluginInspectWithRaw(ctx, repo)
167
+		assert.NilError(t, err)
168
+	})
169
+
127 170
 	t.Run("with htpasswd", func(t *testing.T) {
128 171
 		ctx := setupTest(t)
129 172