|
|
|
@ -35,6 +35,7 @@ import (
|
|
|
|
"github.com/distribution/distribution/v3/registry"
|
|
|
|
"github.com/distribution/distribution/v3/registry"
|
|
|
|
_ "github.com/distribution/distribution/v3/registry/auth/htpasswd"
|
|
|
|
_ "github.com/distribution/distribution/v3/registry/auth/htpasswd"
|
|
|
|
_ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
|
|
|
|
_ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
|
|
|
|
|
|
|
|
|
|
|
@ -68,13 +69,13 @@ type TestRegistry struct {
|
|
|
|
|
|
|
|
|
|
|
|
func setup(suite *TestRegistry, tlsEnabled, insecure bool) {
|
|
|
|
func setup(suite *TestRegistry, tlsEnabled, insecure bool) {
|
|
|
|
suite.WorkspaceDir = testWorkspaceDir
|
|
|
|
suite.WorkspaceDir = testWorkspaceDir
|
|
|
|
os.RemoveAll(suite.WorkspaceDir)
|
|
|
|
err := os.RemoveAll(suite.WorkspaceDir)
|
|
|
|
os.Mkdir(suite.WorkspaceDir, 0700)
|
|
|
|
require.NoError(suite.T(), err, "no error removing test workspace dir")
|
|
|
|
|
|
|
|
err = os.Mkdir(suite.WorkspaceDir, 0700)
|
|
|
|
|
|
|
|
require.NoError(suite.T(), err, "no error creating test workspace dir")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var out bytes.Buffer
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
|
|
out bytes.Buffer
|
|
|
|
|
|
|
|
err error
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
suite.Out = &out
|
|
|
|
suite.Out = &out
|
|
|
|
credentialsFile := filepath.Join(suite.WorkspaceDir, CredentialsFileBasename)
|
|
|
|
credentialsFile := filepath.Join(suite.WorkspaceDir, CredentialsFileBasename)
|
|
|
|
|
|
|
|
|
|
|
|
@ -124,7 +125,7 @@ func setup(suite *TestRegistry, tlsEnabled, insecure bool) {
|
|
|
|
config := &configuration.Configuration{}
|
|
|
|
config := &configuration.Configuration{}
|
|
|
|
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
|
|
|
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
|
|
|
suite.Nil(err, "no error finding free port for test registry")
|
|
|
|
suite.Nil(err, "no error finding free port for test registry")
|
|
|
|
defer ln.Close()
|
|
|
|
defer func() { _ = ln.Close() }()
|
|
|
|
|
|
|
|
|
|
|
|
// Change the registry host to another host which is not localhost.
|
|
|
|
// Change the registry host to another host which is not localhost.
|
|
|
|
// This is required because Docker enforces HTTP if the registry
|
|
|
|
// This is required because Docker enforces HTTP if the registry
|
|
|
|
@ -176,7 +177,7 @@ func initCompromisedRegistryTestServer() string {
|
|
|
|
w.Header().Set("Content-Type", "application/vnd.oci.image.manifest.v1+json")
|
|
|
|
w.Header().Set("Content-Type", "application/vnd.oci.image.manifest.v1+json")
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
|
|
|
|
|
|
|
|
fmt.Fprintf(w, `{ "schemaVersion": 2, "config": {
|
|
|
|
_, _ = fmt.Fprintf(w, `{ "schemaVersion": 2, "config": {
|
|
|
|
"mediaType": "%s",
|
|
|
|
"mediaType": "%s",
|
|
|
|
"digest": "sha256:a705ee2789ab50a5ba20930f246dbd5cc01ff9712825bb98f57ee8414377f133",
|
|
|
|
"digest": "sha256:a705ee2789ab50a5ba20930f246dbd5cc01ff9712825bb98f57ee8414377f133",
|
|
|
|
"size": 181
|
|
|
|
"size": 181
|
|
|
|
@ -192,13 +193,13 @@ func initCompromisedRegistryTestServer() string {
|
|
|
|
} else if r.URL.Path == "/v2/testrepo/supposedlysafechart/blobs/sha256:a705ee2789ab50a5ba20930f246dbd5cc01ff9712825bb98f57ee8414377f133" {
|
|
|
|
} else if r.URL.Path == "/v2/testrepo/supposedlysafechart/blobs/sha256:a705ee2789ab50a5ba20930f246dbd5cc01ff9712825bb98f57ee8414377f133" {
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
w.Write([]byte("{\"name\":\"mychart\",\"version\":\"0.1.0\",\"description\":\"A Helm chart for Kubernetes\\n" +
|
|
|
|
_, _ = w.Write([]byte("{\"name\":\"mychart\",\"version\":\"0.1.0\",\"description\":\"A Helm chart for Kubernetes\\n" +
|
|
|
|
"an 'application' or a 'library' chart.\",\"apiVersion\":\"v2\",\"appVersion\":\"1.16.0\",\"type\":" +
|
|
|
|
"an 'application' or a 'library' chart.\",\"apiVersion\":\"v2\",\"appVersion\":\"1.16.0\",\"type\":" +
|
|
|
|
"\"application\"}"))
|
|
|
|
"\"application\"}"))
|
|
|
|
} else if r.URL.Path == "/v2/testrepo/supposedlysafechart/blobs/sha256:ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb" {
|
|
|
|
} else if r.URL.Path == "/v2/testrepo/supposedlysafechart/blobs/sha256:ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb" {
|
|
|
|
w.Header().Set("Content-Type", ChartLayerMediaType)
|
|
|
|
w.Header().Set("Content-Type", ChartLayerMediaType)
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
w.Write([]byte("b"))
|
|
|
|
_, _ = w.Write([]byte("b"))
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|