|
@@ -4,7 +4,6 @@ import (
|
|
|
"net/http"
|
|
|
"net/http/httputil"
|
|
|
"os"
|
|
|
- "strings"
|
|
|
"testing"
|
|
|
|
|
|
"github.com/docker/distribution/reference"
|
|
@@ -45,98 +44,6 @@ func spawnTestRegistrySession(t *testing.T) *session {
|
|
|
return r
|
|
|
}
|
|
|
|
|
|
-func TestPingRegistryEndpoint(t *testing.T) {
|
|
|
- skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
|
|
- testPing := func(index *registry.IndexInfo, expectedStandalone bool, assertMessage string) {
|
|
|
- ep, err := newV1Endpoint(index, nil)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- regInfo, err := ep.ping()
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
-
|
|
|
- assert.Equal(t, regInfo.Standalone, expectedStandalone, assertMessage)
|
|
|
- }
|
|
|
-
|
|
|
- testPing(makeIndex("/v1/"), true, "Expected standalone to be true (default)")
|
|
|
- testPing(makeHTTPSIndex("/v1/"), true, "Expected standalone to be true (default)")
|
|
|
- testPing(makePublicIndex(), false, "Expected standalone to be false for public index")
|
|
|
-}
|
|
|
-
|
|
|
-func TestEndpoint(t *testing.T) {
|
|
|
- skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
|
|
- // Simple wrapper to fail test if err != nil
|
|
|
- expandEndpoint := func(index *registry.IndexInfo) *v1Endpoint {
|
|
|
- endpoint, err := newV1Endpoint(index, nil)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
- return endpoint
|
|
|
- }
|
|
|
-
|
|
|
- assertInsecureIndex := func(index *registry.IndexInfo) {
|
|
|
- index.Secure = true
|
|
|
- _, err := newV1Endpoint(index, nil)
|
|
|
- assert.ErrorContains(t, err, "insecure-registry", index.Name+": Expected insecure-registry error for insecure index")
|
|
|
- index.Secure = false
|
|
|
- }
|
|
|
-
|
|
|
- assertSecureIndex := func(index *registry.IndexInfo) {
|
|
|
- index.Secure = true
|
|
|
- _, err := newV1Endpoint(index, nil)
|
|
|
- assert.ErrorContains(t, err, "certificate signed by unknown authority", index.Name+": Expected cert error for secure index")
|
|
|
- index.Secure = false
|
|
|
- }
|
|
|
-
|
|
|
- index := ®istry.IndexInfo{}
|
|
|
- index.Name = makeURL("/v1/")
|
|
|
- endpoint := expandEndpoint(index)
|
|
|
- assert.Equal(t, endpoint.String(), index.Name, "Expected endpoint to be "+index.Name)
|
|
|
- assertInsecureIndex(index)
|
|
|
-
|
|
|
- index.Name = makeURL("")
|
|
|
- endpoint = expandEndpoint(index)
|
|
|
- assert.Equal(t, endpoint.String(), index.Name+"/v1/", index.Name+": Expected endpoint to be "+index.Name+"/v1/")
|
|
|
- assertInsecureIndex(index)
|
|
|
-
|
|
|
- httpURL := makeURL("")
|
|
|
- index.Name = strings.SplitN(httpURL, "://", 2)[1]
|
|
|
- endpoint = expandEndpoint(index)
|
|
|
- assert.Equal(t, endpoint.String(), httpURL+"/v1/", index.Name+": Expected endpoint to be "+httpURL+"/v1/")
|
|
|
- assertInsecureIndex(index)
|
|
|
-
|
|
|
- index.Name = makeHTTPSURL("/v1/")
|
|
|
- endpoint = expandEndpoint(index)
|
|
|
- assert.Equal(t, endpoint.String(), index.Name, "Expected endpoint to be "+index.Name)
|
|
|
- assertSecureIndex(index)
|
|
|
-
|
|
|
- index.Name = makeHTTPSURL("")
|
|
|
- endpoint = expandEndpoint(index)
|
|
|
- assert.Equal(t, endpoint.String(), index.Name+"/v1/", index.Name+": Expected endpoint to be "+index.Name+"/v1/")
|
|
|
- assertSecureIndex(index)
|
|
|
-
|
|
|
- httpsURL := makeHTTPSURL("")
|
|
|
- index.Name = strings.SplitN(httpsURL, "://", 2)[1]
|
|
|
- endpoint = expandEndpoint(index)
|
|
|
- assert.Equal(t, endpoint.String(), httpsURL+"/v1/", index.Name+": Expected endpoint to be "+httpsURL+"/v1/")
|
|
|
- assertSecureIndex(index)
|
|
|
-
|
|
|
- badEndpoints := []string{
|
|
|
- "http://127.0.0.1/v1/",
|
|
|
- "https://127.0.0.1/v1/",
|
|
|
- "http://127.0.0.1",
|
|
|
- "https://127.0.0.1",
|
|
|
- "127.0.0.1",
|
|
|
- }
|
|
|
- for _, address := range badEndpoints {
|
|
|
- index.Name = address
|
|
|
- _, err := newV1Endpoint(index, nil)
|
|
|
- assert.Check(t, err != nil, "Expected error while expanding bad endpoint: %s", address)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
func TestParseRepositoryInfo(t *testing.T) {
|
|
|
type staticRepositoryInfo struct {
|
|
|
Index *registry.IndexInfo
|