| 175 | } |
| 176 | |
| 177 | func initCompromisedRegistryTestServer() string { |
| 178 | s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 179 | if strings.Contains(r.URL.Path, "manifests") { |
| 180 | w.Header().Set("Content-Type", "application/vnd.oci.image.manifest.v1+json") |
| 181 | w.WriteHeader(http.StatusOK) |
| 182 | |
| 183 | _, _ = fmt.Fprintf(w, `{ "schemaVersion": 2, "config": { |
| 184 | "mediaType": "%s", |
| 185 | "digest": "sha256:a705ee2789ab50a5ba20930f246dbd5cc01ff9712825bb98f57ee8414377f133", |
| 186 | "size": 181 |
| 187 | }, |
| 188 | "layers": [ |
| 189 | { |
| 190 | "mediaType": "%s", |
| 191 | "digest": "sha256:ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb", |
| 192 | "size": 1 |
| 193 | } |
| 194 | ] |
| 195 | }`, ConfigMediaType, ChartLayerMediaType) |
| 196 | } else if r.URL.Path == "/v2/testrepo/supposedlysafechart/blobs/sha256:a705ee2789ab50a5ba20930f246dbd5cc01ff9712825bb98f57ee8414377f133" { |
| 197 | w.Header().Set("Content-Type", "application/json") |
| 198 | w.WriteHeader(http.StatusOK) |
| 199 | _, _ = w.Write([]byte("{\"name\":\"mychart\",\"version\":\"0.1.0\",\"description\":\"A Helm chart for Kubernetes\\n" + |
| 200 | "an 'application' or a 'library' chart.\",\"apiVersion\":\"v2\",\"appVersion\":\"1.16.0\",\"type\":" + |
| 201 | "\"application\"}")) |
| 202 | } else if r.URL.Path == "/v2/testrepo/supposedlysafechart/blobs/sha256:ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb" { |
| 203 | w.Header().Set("Content-Type", ChartLayerMediaType) |
| 204 | w.WriteHeader(http.StatusOK) |
| 205 | _, _ = w.Write([]byte("b")) |
| 206 | } else { |
| 207 | w.WriteHeader(http.StatusInternalServerError) |
| 208 | } |
| 209 | })) |
| 210 | |
| 211 | u, _ := url.Parse(s.URL) |
| 212 | return "localhost:" + u.Port() |
| 213 | } |
| 214 | |
| 215 | func initFakeRegistryTestServer() string { |
| 216 | s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |