|
|
@ -22,7 +22,6 @@ import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"io/ioutil"
|
|
|
|
"net"
|
|
|
|
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"net/http/httptest"
|
|
|
|
"net/url"
|
|
|
|
"net/url"
|
|
|
@ -33,12 +32,12 @@ import (
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/containerd/containerd/errdefs"
|
|
|
|
"github.com/containerd/containerd/errdefs"
|
|
|
|
|
|
|
|
|
|
|
|
auth "github.com/deislabs/oras/pkg/auth/docker"
|
|
|
|
auth "github.com/deislabs/oras/pkg/auth/docker"
|
|
|
|
"github.com/docker/distribution/configuration"
|
|
|
|
"github.com/docker/distribution/configuration"
|
|
|
|
"github.com/docker/distribution/registry"
|
|
|
|
"github.com/docker/distribution/registry"
|
|
|
|
_ "github.com/docker/distribution/registry/auth/htpasswd"
|
|
|
|
_ "github.com/docker/distribution/registry/auth/htpasswd"
|
|
|
|
_ "github.com/docker/distribution/registry/storage/driver/inmemory"
|
|
|
|
_ "github.com/docker/distribution/registry/storage/driver/inmemory"
|
|
|
|
|
|
|
|
"github.com/phayes/freeport"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
|
|
|
|
|
|
|
|
|
|
@ -107,7 +106,7 @@ func (suite *RegistryClientTestSuite) SetupSuite() {
|
|
|
|
|
|
|
|
|
|
|
|
// Registry config
|
|
|
|
// Registry config
|
|
|
|
config := &configuration.Configuration{}
|
|
|
|
config := &configuration.Configuration{}
|
|
|
|
port, err := getFreePort()
|
|
|
|
port, err := freeport.GetFreePort()
|
|
|
|
suite.Nil(err, "no error finding free port for test registry")
|
|
|
|
suite.Nil(err, "no error finding free port for test registry")
|
|
|
|
suite.DockerRegistryHost = fmt.Sprintf("localhost:%d", port)
|
|
|
|
suite.DockerRegistryHost = fmt.Sprintf("localhost:%d", port)
|
|
|
|
config.HTTP.Addr = fmt.Sprintf(":%d", port)
|
|
|
|
config.HTTP.Addr = fmt.Sprintf(":%d", port)
|
|
|
@ -254,21 +253,6 @@ func TestRegistryClientTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(RegistryClientTestSuite))
|
|
|
|
suite.Run(t, new(RegistryClientTestSuite))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// borrowed from https://github.com/phayes/freeport
|
|
|
|
|
|
|
|
func getFreePort() (int, error) {
|
|
|
|
|
|
|
|
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return 0, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
l, err := net.ListenTCP("tcp", addr)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return 0, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defer l.Close()
|
|
|
|
|
|
|
|
return l.Addr().(*net.TCPAddr).Port, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func initCompromisedRegistryTestServer() string {
|
|
|
|
func initCompromisedRegistryTestServer() string {
|
|
|
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if strings.Contains(r.URL.Path, "manifests") {
|
|
|
|
if strings.Contains(r.URL.Path, "manifests") {
|
|
|
|