2018-02-05 16:05:59 -05:00
|
|
|
package registry // import "github.com/docker/docker/registry"
|
2013-05-08 13:21:21 -04:00
|
|
|
|
2013-07-31 13:07:31 -04:00
|
|
|
import (
|
2014-06-05 14:37:37 -04:00
|
|
|
"net/http"
|
2015-06-20 08:28:18 -04:00
|
|
|
"net/http/httputil"
|
2018-04-20 05:59:08 -04:00
|
|
|
"os"
|
2013-07-31 13:07:31 -04:00
|
|
|
"strings"
|
|
|
|
"testing"
|
2014-06-05 14:37:37 -04:00
|
|
|
|
2017-01-11 16:54:52 -05:00
|
|
|
"github.com/docker/distribution/reference"
|
2015-05-17 05:07:48 -04:00
|
|
|
"github.com/docker/distribution/registry/client/transport"
|
2022-02-26 13:13:43 -05:00
|
|
|
"github.com/docker/docker/api/types/registry"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2022-02-26 16:53:06 -05:00
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/skip"
|
2013-07-31 13:07:31 -04:00
|
|
|
)
|
2013-07-31 13:12:40 -04:00
|
|
|
|
2022-02-25 19:05:27 -05:00
|
|
|
func spawnTestRegistrySession(t *testing.T) *session {
|
2022-03-03 04:32:29 -05:00
|
|
|
authConfig := ®istry.AuthConfig{}
|
2022-02-25 18:02:37 -05:00
|
|
|
endpoint, err := newV1Endpoint(makeIndex("/v1/"), "", nil)
|
2014-08-26 19:21:04 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-01-04 13:36:01 -05:00
|
|
|
userAgent := "docker test client"
|
2022-02-25 17:58:25 -05:00
|
|
|
var tr http.RoundTripper = debugTransport{newTransport(nil), t.Log}
|
2022-03-18 08:52:20 -04:00
|
|
|
tr = transport.NewTransport(newAuthTransport(tr, authConfig, false), Headers(userAgent, nil)...)
|
2022-02-25 17:58:25 -05:00
|
|
|
client := httpClient(tr)
|
2022-02-25 19:05:27 -05:00
|
|
|
|
|
|
|
if err := authorizeClient(client, authConfig, endpoint); err != nil {
|
2013-07-31 13:07:31 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-02-25 19:05:27 -05:00
|
|
|
r := newSession(client, endpoint)
|
|
|
|
|
2015-05-14 10:12:54 -04:00
|
|
|
// In a normal scenario for the v1 registry, the client should send a `X-Docker-Token: true`
|
|
|
|
// header while authenticating, in order to retrieve a token that can be later used to
|
|
|
|
// perform authenticated actions.
|
|
|
|
//
|
|
|
|
// The mock v1 registry does not support that, (TODO(tiborvass): support it), instead,
|
|
|
|
// it will consider authenticated any request with the header `X-Docker-Token: fake-token`.
|
|
|
|
//
|
|
|
|
// Because we know that the client's transport is an `*authTransport` we simply cast it,
|
|
|
|
// in order to set the internal cached token to the fake token, and thus send that fake token
|
|
|
|
// upon every subsequent requests.
|
2020-10-28 08:46:00 -04:00
|
|
|
r.client.Transport.(*authTransport).token = []string{"fake-token"}
|
2013-07-31 13:07:31 -04:00
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPingRegistryEndpoint(t *testing.T) {
|
2018-04-20 05:59:08 -04:00
|
|
|
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
2022-02-26 13:13:43 -05:00
|
|
|
testPing := func(index *registry.IndexInfo, expectedStandalone bool, assertMessage string) {
|
2022-02-25 18:02:37 -05:00
|
|
|
ep, err := newV1Endpoint(index, "", nil)
|
2014-10-06 21:54:52 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-02-25 18:08:20 -05:00
|
|
|
regInfo, err := ep.ping()
|
2014-10-06 21:54:52 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2022-02-26 16:53:06 -05:00
|
|
|
assert.Equal(t, regInfo.Standalone, expectedStandalone, assertMessage)
|
2014-08-26 19:21:04 -04:00
|
|
|
}
|
2014-10-06 21:54:52 -04:00
|
|
|
|
|
|
|
testPing(makeIndex("/v1/"), true, "Expected standalone to be true (default)")
|
2015-07-21 15:40:36 -04:00
|
|
|
testPing(makeHTTPSIndex("/v1/"), true, "Expected standalone to be true (default)")
|
2014-10-06 21:54:52 -04:00
|
|
|
testPing(makePublicIndex(), false, "Expected standalone to be false for public index")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEndpoint(t *testing.T) {
|
2018-04-20 05:59:08 -04:00
|
|
|
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
2014-10-06 21:54:52 -04:00
|
|
|
// Simple wrapper to fail test if err != nil
|
2022-02-26 13:13:43 -05:00
|
|
|
expandEndpoint := func(index *registry.IndexInfo) *v1Endpoint {
|
2022-02-25 18:02:37 -05:00
|
|
|
endpoint, err := newV1Endpoint(index, "", nil)
|
2014-10-06 21:54:52 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
return endpoint
|
|
|
|
}
|
|
|
|
|
2022-02-26 13:13:43 -05:00
|
|
|
assertInsecureIndex := func(index *registry.IndexInfo) {
|
2014-10-06 21:54:52 -04:00
|
|
|
index.Secure = true
|
2022-02-25 18:02:37 -05:00
|
|
|
_, err := newV1Endpoint(index, "", nil)
|
2022-02-26 16:53:06 -05:00
|
|
|
assert.ErrorContains(t, err, "insecure-registry", index.Name+": Expected insecure-registry error for insecure index")
|
2014-10-06 21:54:52 -04:00
|
|
|
index.Secure = false
|
|
|
|
}
|
|
|
|
|
2022-02-26 13:13:43 -05:00
|
|
|
assertSecureIndex := func(index *registry.IndexInfo) {
|
2014-10-06 21:54:52 -04:00
|
|
|
index.Secure = true
|
2022-02-25 18:02:37 -05:00
|
|
|
_, err := newV1Endpoint(index, "", nil)
|
2022-02-26 16:53:06 -05:00
|
|
|
assert.ErrorContains(t, err, "certificate signed by unknown authority", index.Name+": Expected cert error for secure index")
|
2014-10-06 21:54:52 -04:00
|
|
|
index.Secure = false
|
|
|
|
}
|
|
|
|
|
2022-02-26 13:13:43 -05:00
|
|
|
index := ®istry.IndexInfo{}
|
2014-10-06 21:54:52 -04:00
|
|
|
index.Name = makeURL("/v1/")
|
|
|
|
endpoint := expandEndpoint(index)
|
2022-02-26 16:53:06 -05:00
|
|
|
assert.Equal(t, endpoint.String(), index.Name, "Expected endpoint to be "+index.Name)
|
2014-10-06 21:54:52 -04:00
|
|
|
assertInsecureIndex(index)
|
|
|
|
|
|
|
|
index.Name = makeURL("")
|
|
|
|
endpoint = expandEndpoint(index)
|
2022-02-26 16:53:06 -05:00
|
|
|
assert.Equal(t, endpoint.String(), index.Name+"/v1/", index.Name+": Expected endpoint to be "+index.Name+"/v1/")
|
2014-10-06 21:54:52 -04:00
|
|
|
assertInsecureIndex(index)
|
|
|
|
|
|
|
|
httpURL := makeURL("")
|
|
|
|
index.Name = strings.SplitN(httpURL, "://", 2)[1]
|
|
|
|
endpoint = expandEndpoint(index)
|
2022-02-26 16:53:06 -05:00
|
|
|
assert.Equal(t, endpoint.String(), httpURL+"/v1/", index.Name+": Expected endpoint to be "+httpURL+"/v1/")
|
2014-10-06 21:54:52 -04:00
|
|
|
assertInsecureIndex(index)
|
|
|
|
|
2015-07-21 15:40:36 -04:00
|
|
|
index.Name = makeHTTPSURL("/v1/")
|
2014-10-06 21:54:52 -04:00
|
|
|
endpoint = expandEndpoint(index)
|
2022-02-26 16:53:06 -05:00
|
|
|
assert.Equal(t, endpoint.String(), index.Name, "Expected endpoint to be "+index.Name)
|
2014-10-06 21:54:52 -04:00
|
|
|
assertSecureIndex(index)
|
|
|
|
|
2015-07-21 15:40:36 -04:00
|
|
|
index.Name = makeHTTPSURL("")
|
2014-10-06 21:54:52 -04:00
|
|
|
endpoint = expandEndpoint(index)
|
2022-02-26 16:53:06 -05:00
|
|
|
assert.Equal(t, endpoint.String(), index.Name+"/v1/", index.Name+": Expected endpoint to be "+index.Name+"/v1/")
|
2014-10-06 21:54:52 -04:00
|
|
|
assertSecureIndex(index)
|
|
|
|
|
2015-07-21 15:40:36 -04:00
|
|
|
httpsURL := makeHTTPSURL("")
|
2014-10-06 21:54:52 -04:00
|
|
|
index.Name = strings.SplitN(httpsURL, "://", 2)[1]
|
|
|
|
endpoint = expandEndpoint(index)
|
2022-02-26 16:53:06 -05:00
|
|
|
assert.Equal(t, endpoint.String(), httpsURL+"/v1/", index.Name+": Expected endpoint to be "+httpsURL+"/v1/")
|
2014-10-06 21:54:52 -04:00
|
|
|
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
|
2022-02-25 18:02:37 -05:00
|
|
|
_, err := newV1Endpoint(index, "", nil)
|
2022-02-26 16:53:06 -05:00
|
|
|
assert.Check(t, err != nil, "Expected error while expanding bad endpoint: %s", address)
|
2013-07-31 13:07:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-06 21:54:52 -04:00
|
|
|
func TestParseRepositoryInfo(t *testing.T) {
|
2015-12-11 14:00:13 -05:00
|
|
|
type staticRepositoryInfo struct {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index *registry.IndexInfo
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName string
|
|
|
|
CanonicalName string
|
|
|
|
LocalName string
|
|
|
|
Official bool
|
2015-11-18 17:20:54 -05:00
|
|
|
}
|
|
|
|
|
2015-12-11 14:00:13 -05:00
|
|
|
expectedRepoInfos := map[string]staticRepositoryInfo{
|
2014-10-06 21:54:52 -04:00
|
|
|
"fooo/bar": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2015-07-21 15:40:36 -04:00
|
|
|
Name: IndexName,
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "fooo/bar",
|
|
|
|
LocalName: "fooo/bar",
|
|
|
|
CanonicalName: "docker.io/fooo/bar",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: false,
|
|
|
|
},
|
|
|
|
"library/ubuntu": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2015-07-21 15:40:36 -04:00
|
|
|
Name: IndexName,
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "library/ubuntu",
|
|
|
|
LocalName: "ubuntu",
|
|
|
|
CanonicalName: "docker.io/library/ubuntu",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
},
|
|
|
|
"nonlibrary/ubuntu": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2015-07-21 15:40:36 -04:00
|
|
|
Name: IndexName,
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "nonlibrary/ubuntu",
|
|
|
|
LocalName: "nonlibrary/ubuntu",
|
|
|
|
CanonicalName: "docker.io/nonlibrary/ubuntu",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: false,
|
|
|
|
},
|
|
|
|
"ubuntu": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2015-07-21 15:40:36 -04:00
|
|
|
Name: IndexName,
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "library/ubuntu",
|
|
|
|
LocalName: "ubuntu",
|
|
|
|
CanonicalName: "docker.io/library/ubuntu",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
},
|
|
|
|
"other/library": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2015-07-21 15:40:36 -04:00
|
|
|
Name: IndexName,
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "other/library",
|
|
|
|
LocalName: "other/library",
|
|
|
|
CanonicalName: "docker.io/other/library",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: false,
|
|
|
|
},
|
|
|
|
"127.0.0.1:8000/private/moonbase": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2014-10-06 21:54:52 -04:00
|
|
|
Name: "127.0.0.1:8000",
|
|
|
|
Official: false,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "private/moonbase",
|
|
|
|
LocalName: "127.0.0.1:8000/private/moonbase",
|
|
|
|
CanonicalName: "127.0.0.1:8000/private/moonbase",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: false,
|
|
|
|
},
|
|
|
|
"127.0.0.1:8000/privatebase": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2014-10-06 21:54:52 -04:00
|
|
|
Name: "127.0.0.1:8000",
|
|
|
|
Official: false,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "privatebase",
|
|
|
|
LocalName: "127.0.0.1:8000/privatebase",
|
|
|
|
CanonicalName: "127.0.0.1:8000/privatebase",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: false,
|
|
|
|
},
|
|
|
|
"localhost:8000/private/moonbase": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2014-10-06 21:54:52 -04:00
|
|
|
Name: "localhost:8000",
|
|
|
|
Official: false,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "private/moonbase",
|
|
|
|
LocalName: "localhost:8000/private/moonbase",
|
|
|
|
CanonicalName: "localhost:8000/private/moonbase",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: false,
|
|
|
|
},
|
|
|
|
"localhost:8000/privatebase": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2014-10-06 21:54:52 -04:00
|
|
|
Name: "localhost:8000",
|
|
|
|
Official: false,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "privatebase",
|
|
|
|
LocalName: "localhost:8000/privatebase",
|
|
|
|
CanonicalName: "localhost:8000/privatebase",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: false,
|
|
|
|
},
|
|
|
|
"example.com/private/moonbase": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2014-10-06 21:54:52 -04:00
|
|
|
Name: "example.com",
|
|
|
|
Official: false,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "private/moonbase",
|
|
|
|
LocalName: "example.com/private/moonbase",
|
|
|
|
CanonicalName: "example.com/private/moonbase",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: false,
|
|
|
|
},
|
|
|
|
"example.com/privatebase": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2014-10-06 21:54:52 -04:00
|
|
|
Name: "example.com",
|
|
|
|
Official: false,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "privatebase",
|
|
|
|
LocalName: "example.com/privatebase",
|
|
|
|
CanonicalName: "example.com/privatebase",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: false,
|
|
|
|
},
|
|
|
|
"example.com:8000/private/moonbase": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2014-10-06 21:54:52 -04:00
|
|
|
Name: "example.com:8000",
|
|
|
|
Official: false,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "private/moonbase",
|
|
|
|
LocalName: "example.com:8000/private/moonbase",
|
|
|
|
CanonicalName: "example.com:8000/private/moonbase",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: false,
|
|
|
|
},
|
|
|
|
"example.com:8000/privatebase": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2014-10-06 21:54:52 -04:00
|
|
|
Name: "example.com:8000",
|
|
|
|
Official: false,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "privatebase",
|
|
|
|
LocalName: "example.com:8000/privatebase",
|
|
|
|
CanonicalName: "example.com:8000/privatebase",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: false,
|
|
|
|
},
|
|
|
|
"localhost/private/moonbase": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2014-10-06 21:54:52 -04:00
|
|
|
Name: "localhost",
|
|
|
|
Official: false,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "private/moonbase",
|
|
|
|
LocalName: "localhost/private/moonbase",
|
|
|
|
CanonicalName: "localhost/private/moonbase",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: false,
|
|
|
|
},
|
|
|
|
"localhost/privatebase": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2014-10-06 21:54:52 -04:00
|
|
|
Name: "localhost",
|
|
|
|
Official: false,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "privatebase",
|
|
|
|
LocalName: "localhost/privatebase",
|
|
|
|
CanonicalName: "localhost/privatebase",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: false,
|
|
|
|
},
|
2015-07-21 15:40:36 -04:00
|
|
|
IndexName + "/public/moonbase": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2015-07-21 15:40:36 -04:00
|
|
|
Name: IndexName,
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "public/moonbase",
|
|
|
|
LocalName: "public/moonbase",
|
|
|
|
CanonicalName: "docker.io/public/moonbase",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: false,
|
|
|
|
},
|
2015-07-21 15:40:36 -04:00
|
|
|
"index." + IndexName + "/public/moonbase": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2015-07-21 15:40:36 -04:00
|
|
|
Name: IndexName,
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "public/moonbase",
|
|
|
|
LocalName: "public/moonbase",
|
|
|
|
CanonicalName: "docker.io/public/moonbase",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: false,
|
|
|
|
},
|
|
|
|
"ubuntu-12.04-base": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2015-07-21 15:40:36 -04:00
|
|
|
Name: IndexName,
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "library/ubuntu-12.04-base",
|
|
|
|
LocalName: "ubuntu-12.04-base",
|
|
|
|
CanonicalName: "docker.io/library/ubuntu-12.04-base",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
},
|
2015-07-21 15:40:36 -04:00
|
|
|
IndexName + "/ubuntu-12.04-base": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2015-07-21 15:40:36 -04:00
|
|
|
Name: IndexName,
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "library/ubuntu-12.04-base",
|
|
|
|
LocalName: "ubuntu-12.04-base",
|
|
|
|
CanonicalName: "docker.io/library/ubuntu-12.04-base",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
},
|
2015-07-21 15:40:36 -04:00
|
|
|
"index." + IndexName + "/ubuntu-12.04-base": {
|
2022-02-26 13:13:43 -05:00
|
|
|
Index: ®istry.IndexInfo{
|
2015-07-21 15:40:36 -04:00
|
|
|
Name: IndexName,
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
},
|
2015-12-11 14:00:13 -05:00
|
|
|
RemoteName: "library/ubuntu-12.04-base",
|
|
|
|
LocalName: "ubuntu-12.04-base",
|
|
|
|
CanonicalName: "docker.io/library/ubuntu-12.04-base",
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for reposName, expectedRepoInfo := range expectedRepoInfos {
|
2017-01-11 16:54:52 -05:00
|
|
|
named, err := reference.ParseNormalizedNamed(reposName)
|
2015-11-18 17:20:54 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
repoInfo, err := ParseRepositoryInfo(named)
|
2014-10-06 21:54:52 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
} else {
|
2022-02-26 16:53:06 -05:00
|
|
|
assert.Check(t, is.Equal(repoInfo.Index.Name, expectedRepoInfo.Index.Name), reposName)
|
|
|
|
assert.Check(t, is.Equal(reference.Path(repoInfo.Name), expectedRepoInfo.RemoteName), reposName)
|
|
|
|
assert.Check(t, is.Equal(reference.FamiliarName(repoInfo.Name), expectedRepoInfo.LocalName), reposName)
|
|
|
|
assert.Check(t, is.Equal(repoInfo.Name.Name(), expectedRepoInfo.CanonicalName), reposName)
|
|
|
|
assert.Check(t, is.Equal(repoInfo.Index.Official, expectedRepoInfo.Index.Official), reposName)
|
|
|
|
assert.Check(t, is.Equal(repoInfo.Official, expectedRepoInfo.Official), reposName)
|
2014-10-06 21:54:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewIndexInfo(t *testing.T) {
|
2022-02-26 13:13:43 -05:00
|
|
|
testIndexInfo := func(config *serviceConfig, expectedIndexInfos map[string]*registry.IndexInfo) {
|
2014-10-06 21:54:52 -04:00
|
|
|
for indexName, expectedIndexInfo := range expectedIndexInfos {
|
2015-12-11 21:14:52 -05:00
|
|
|
index, err := newIndexInfo(config, indexName)
|
2014-10-06 21:54:52 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
} else {
|
2022-02-26 16:53:06 -05:00
|
|
|
assert.Check(t, is.Equal(index.Name, expectedIndexInfo.Name), indexName+" name")
|
|
|
|
assert.Check(t, is.Equal(index.Official, expectedIndexInfo.Official), indexName+" is official")
|
|
|
|
assert.Check(t, is.Equal(index.Secure, expectedIndexInfo.Secure), indexName+" is secure")
|
|
|
|
assert.Check(t, is.Equal(len(index.Mirrors), len(expectedIndexInfo.Mirrors)), indexName+" mirrors")
|
2014-10-06 21:54:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-01 10:35:04 -04:00
|
|
|
config := emptyServiceConfig
|
2018-05-19 07:38:54 -04:00
|
|
|
var noMirrors []string
|
2022-02-26 13:13:43 -05:00
|
|
|
expectedIndexInfos := map[string]*registry.IndexInfo{
|
2015-07-21 15:40:36 -04:00
|
|
|
IndexName: {
|
|
|
|
Name: IndexName,
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
Secure: true,
|
|
|
|
Mirrors: noMirrors,
|
|
|
|
},
|
2015-07-21 15:40:36 -04:00
|
|
|
"index." + IndexName: {
|
|
|
|
Name: IndexName,
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
Secure: true,
|
|
|
|
Mirrors: noMirrors,
|
|
|
|
},
|
|
|
|
"example.com": {
|
|
|
|
Name: "example.com",
|
|
|
|
Official: false,
|
|
|
|
Secure: true,
|
|
|
|
Mirrors: noMirrors,
|
|
|
|
},
|
|
|
|
"127.0.0.1:5000": {
|
|
|
|
Name: "127.0.0.1:5000",
|
|
|
|
Official: false,
|
|
|
|
Secure: false,
|
|
|
|
Mirrors: noMirrors,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
testIndexInfo(config, expectedIndexInfos)
|
|
|
|
|
|
|
|
publicMirrors := []string{"http://mirror1.local", "http://mirror2.local"}
|
2017-09-01 10:35:04 -04:00
|
|
|
var err error
|
|
|
|
config, err = makeServiceConfig(publicMirrors, []string{"example.com"})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-10-06 21:54:52 -04:00
|
|
|
|
2022-02-26 13:13:43 -05:00
|
|
|
expectedIndexInfos = map[string]*registry.IndexInfo{
|
2015-07-21 15:40:36 -04:00
|
|
|
IndexName: {
|
|
|
|
Name: IndexName,
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
Secure: true,
|
|
|
|
Mirrors: publicMirrors,
|
|
|
|
},
|
2015-07-21 15:40:36 -04:00
|
|
|
"index." + IndexName: {
|
|
|
|
Name: IndexName,
|
2014-10-06 21:54:52 -04:00
|
|
|
Official: true,
|
|
|
|
Secure: true,
|
|
|
|
Mirrors: publicMirrors,
|
|
|
|
},
|
|
|
|
"example.com": {
|
|
|
|
Name: "example.com",
|
|
|
|
Official: false,
|
|
|
|
Secure: false,
|
|
|
|
Mirrors: noMirrors,
|
|
|
|
},
|
|
|
|
"example.com:5000": {
|
|
|
|
Name: "example.com:5000",
|
|
|
|
Official: false,
|
|
|
|
Secure: true,
|
|
|
|
Mirrors: noMirrors,
|
|
|
|
},
|
|
|
|
"127.0.0.1": {
|
|
|
|
Name: "127.0.0.1",
|
|
|
|
Official: false,
|
|
|
|
Secure: false,
|
|
|
|
Mirrors: noMirrors,
|
|
|
|
},
|
|
|
|
"127.0.0.1:5000": {
|
|
|
|
Name: "127.0.0.1:5000",
|
|
|
|
Official: false,
|
|
|
|
Secure: false,
|
|
|
|
Mirrors: noMirrors,
|
|
|
|
},
|
|
|
|
"other.com": {
|
|
|
|
Name: "other.com",
|
|
|
|
Official: false,
|
|
|
|
Secure: true,
|
|
|
|
Mirrors: noMirrors,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
testIndexInfo(config, expectedIndexInfos)
|
|
|
|
|
2017-09-01 10:35:04 -04:00
|
|
|
config, err = makeServiceConfig(nil, []string{"42.42.0.0/16"})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-02-26 13:13:43 -05:00
|
|
|
expectedIndexInfos = map[string]*registry.IndexInfo{
|
2014-10-06 21:54:52 -04:00
|
|
|
"example.com": {
|
|
|
|
Name: "example.com",
|
|
|
|
Official: false,
|
|
|
|
Secure: false,
|
|
|
|
Mirrors: noMirrors,
|
|
|
|
},
|
|
|
|
"example.com:5000": {
|
|
|
|
Name: "example.com:5000",
|
|
|
|
Official: false,
|
|
|
|
Secure: false,
|
|
|
|
Mirrors: noMirrors,
|
|
|
|
},
|
|
|
|
"127.0.0.1": {
|
|
|
|
Name: "127.0.0.1",
|
|
|
|
Official: false,
|
|
|
|
Secure: false,
|
|
|
|
Mirrors: noMirrors,
|
|
|
|
},
|
|
|
|
"127.0.0.1:5000": {
|
|
|
|
Name: "127.0.0.1:5000",
|
|
|
|
Official: false,
|
|
|
|
Secure: false,
|
|
|
|
Mirrors: noMirrors,
|
|
|
|
},
|
|
|
|
"other.com": {
|
|
|
|
Name: "other.com",
|
|
|
|
Official: false,
|
|
|
|
Secure: true,
|
|
|
|
Mirrors: noMirrors,
|
|
|
|
},
|
2014-04-14 19:15:38 -04:00
|
|
|
}
|
2014-10-06 21:54:52 -04:00
|
|
|
testIndexInfo(config, expectedIndexInfos)
|
2013-07-31 13:07:31 -04:00
|
|
|
}
|
|
|
|
|
2015-08-06 21:21:02 -04:00
|
|
|
func TestMirrorEndpointLookup(t *testing.T) {
|
2018-04-20 05:59:08 -04:00
|
|
|
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
|
2015-08-06 21:21:02 -04:00
|
|
|
containsMirror := func(endpoints []APIEndpoint) bool {
|
|
|
|
for _, pe := range endpoints {
|
2016-02-17 19:53:25 -05:00
|
|
|
if pe.URL.Host == "my.mirror" {
|
2015-08-06 21:21:02 -04:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2017-09-01 10:35:04 -04:00
|
|
|
cfg, err := makeServiceConfig([]string{"https://my.mirror"}, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2022-02-25 17:45:49 -05:00
|
|
|
s := defaultService{config: cfg}
|
2015-08-06 21:21:02 -04:00
|
|
|
|
2015-11-18 17:20:54 -05:00
|
|
|
imageName, err := reference.WithName(IndexName + "/test/image")
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2017-01-11 16:54:52 -05:00
|
|
|
pushAPIEndpoints, err := s.LookupPushEndpoints(reference.Domain(imageName))
|
2015-08-06 21:21:02 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if containsMirror(pushAPIEndpoints) {
|
|
|
|
t.Fatal("Push endpoint should not contain mirror")
|
|
|
|
}
|
|
|
|
|
2017-01-11 16:54:52 -05:00
|
|
|
pullAPIEndpoints, err := s.LookupPullEndpoints(reference.Domain(imageName))
|
2015-08-06 21:21:02 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !containsMirror(pullAPIEndpoints) {
|
|
|
|
t.Fatal("Pull endpoint should contain mirror")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-31 13:07:31 -04:00
|
|
|
func TestSearchRepositories(t *testing.T) {
|
2014-08-07 10:43:06 -04:00
|
|
|
r := spawnTestRegistrySession(t)
|
2022-02-25 19:05:27 -05:00
|
|
|
results, err := r.searchRepositories("fakequery", 25)
|
2013-07-31 13:07:31 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if results == nil {
|
|
|
|
t.Fatal("Expected non-nil SearchResults object")
|
|
|
|
}
|
2022-02-26 16:53:06 -05:00
|
|
|
assert.Equal(t, results.NumResults, 1, "Expected 1 search results")
|
|
|
|
assert.Equal(t, results.Query, "fakequery", "Expected 'fakequery' as query")
|
|
|
|
assert.Equal(t, results.Results[0].StarCount, 42, "Expected 'fakeimage' to have 42 stars")
|
2013-07-31 13:12:40 -04:00
|
|
|
}
|
2013-09-19 23:25:00 -04:00
|
|
|
|
2014-06-05 14:37:37 -04:00
|
|
|
func TestTrustedLocation(t *testing.T) {
|
2014-09-23 19:18:09 -04:00
|
|
|
for _, url := range []string{"http://example.com", "https://example.com:7777", "http://docker.io", "http://test.docker.com", "https://fakedocker.com"} {
|
2019-10-12 14:42:44 -04:00
|
|
|
req, _ := http.NewRequest(http.MethodGet, url, nil)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, !trustedLocation(req))
|
2014-06-05 14:37:37 -04:00
|
|
|
}
|
|
|
|
|
2014-09-23 19:18:09 -04:00
|
|
|
for _, url := range []string{"https://docker.io", "https://test.docker.com:80"} {
|
2019-10-12 14:42:44 -04:00
|
|
|
req, _ := http.NewRequest(http.MethodGet, url, nil)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, trustedLocation(req))
|
2014-06-05 14:37:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddRequiredHeadersToRedirectedRequests(t *testing.T) {
|
|
|
|
for _, urls := range [][]string{
|
|
|
|
{"http://docker.io", "https://docker.com"},
|
|
|
|
{"https://foo.docker.io:7777", "http://bar.docker.com"},
|
|
|
|
{"https://foo.docker.io", "https://example.com"},
|
|
|
|
} {
|
2019-10-12 14:42:44 -04:00
|
|
|
reqFrom, _ := http.NewRequest(http.MethodGet, urls[0], nil)
|
2014-06-05 14:37:37 -04:00
|
|
|
reqFrom.Header.Add("Content-Type", "application/json")
|
|
|
|
reqFrom.Header.Add("Authorization", "super_secret")
|
2019-10-12 14:42:44 -04:00
|
|
|
reqTo, _ := http.NewRequest(http.MethodGet, urls[1], nil)
|
2014-06-05 14:37:37 -04:00
|
|
|
|
2022-02-26 16:53:06 -05:00
|
|
|
_ = addRequiredHeadersToRedirectedRequests(reqTo, []*http.Request{reqFrom})
|
2014-06-05 14:37:37 -04:00
|
|
|
|
|
|
|
if len(reqTo.Header) != 1 {
|
2014-06-12 01:15:53 -04:00
|
|
|
t.Fatalf("Expected 1 headers, got %d", len(reqTo.Header))
|
2014-06-05 14:37:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if reqTo.Header.Get("Content-Type") != "application/json" {
|
|
|
|
t.Fatal("'Content-Type' should be 'application/json'")
|
|
|
|
}
|
|
|
|
|
|
|
|
if reqTo.Header.Get("Authorization") != "" {
|
|
|
|
t.Fatal("'Authorization' should be empty")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, urls := range [][]string{
|
|
|
|
{"https://docker.io", "https://docker.com"},
|
|
|
|
{"https://foo.docker.io:7777", "https://bar.docker.com"},
|
|
|
|
} {
|
2019-10-12 14:42:44 -04:00
|
|
|
reqFrom, _ := http.NewRequest(http.MethodGet, urls[0], nil)
|
2014-06-05 14:37:37 -04:00
|
|
|
reqFrom.Header.Add("Content-Type", "application/json")
|
|
|
|
reqFrom.Header.Add("Authorization", "super_secret")
|
2019-10-12 14:42:44 -04:00
|
|
|
reqTo, _ := http.NewRequest(http.MethodGet, urls[1], nil)
|
2014-06-05 14:37:37 -04:00
|
|
|
|
2022-02-26 16:53:06 -05:00
|
|
|
_ = addRequiredHeadersToRedirectedRequests(reqTo, []*http.Request{reqFrom})
|
2014-06-05 14:37:37 -04:00
|
|
|
|
|
|
|
if len(reqTo.Header) != 2 {
|
2014-06-12 01:15:53 -04:00
|
|
|
t.Fatalf("Expected 2 headers, got %d", len(reqTo.Header))
|
2014-06-05 14:37:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if reqTo.Header.Get("Content-Type") != "application/json" {
|
|
|
|
t.Fatal("'Content-Type' should be 'application/json'")
|
|
|
|
}
|
|
|
|
|
|
|
|
if reqTo.Header.Get("Authorization") != "super_secret" {
|
|
|
|
t.Fatal("'Authorization' should be 'super_secret'")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-11 14:01:49 -05:00
|
|
|
|
2017-05-09 17:00:31 -04:00
|
|
|
func TestAllowNondistributableArtifacts(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
addr string
|
|
|
|
registries []string
|
|
|
|
expected bool
|
|
|
|
}{
|
|
|
|
{IndexName, nil, false},
|
|
|
|
{"example.com", []string{}, false},
|
|
|
|
{"example.com", []string{"example.com"}, true},
|
|
|
|
{"localhost", []string{"localhost:5000"}, false},
|
|
|
|
{"localhost:5000", []string{"localhost:5000"}, true},
|
|
|
|
{"localhost", []string{"example.com"}, false},
|
|
|
|
{"127.0.0.1:5000", []string{"127.0.0.1:5000"}, true},
|
|
|
|
{"localhost", nil, false},
|
|
|
|
{"localhost:5000", nil, false},
|
|
|
|
{"127.0.0.1", nil, false},
|
|
|
|
{"localhost", []string{"example.com"}, false},
|
|
|
|
{"127.0.0.1", []string{"example.com"}, false},
|
|
|
|
{"example.com", nil, false},
|
|
|
|
{"example.com", []string{"example.com"}, true},
|
|
|
|
{"127.0.0.1", []string{"example.com"}, false},
|
|
|
|
{"127.0.0.1:5000", []string{"example.com"}, false},
|
|
|
|
{"example.com:5000", []string{"42.42.0.0/16"}, true},
|
|
|
|
{"example.com", []string{"42.42.0.0/16"}, true},
|
|
|
|
{"example.com:5000", []string{"42.42.42.42/8"}, true},
|
|
|
|
{"127.0.0.1:5000", []string{"127.0.0.0/8"}, true},
|
|
|
|
{"42.42.42.42:5000", []string{"42.1.1.1/8"}, true},
|
2021-04-02 08:06:27 -04:00
|
|
|
{"invalid.example.com", []string{"42.42.0.0/16"}, false},
|
|
|
|
{"invalid.example.com", []string{"invalid.example.com"}, true},
|
|
|
|
{"invalid.example.com:5000", []string{"invalid.example.com"}, false},
|
|
|
|
{"invalid.example.com:5000", []string{"invalid.example.com:5000"}, true},
|
2017-05-09 17:00:31 -04:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
2017-09-01 10:35:04 -04:00
|
|
|
config, err := newServiceConfig(ServiceOptions{
|
2017-05-09 17:00:31 -04:00
|
|
|
AllowNondistributableArtifacts: tt.registries,
|
|
|
|
})
|
2017-09-01 10:35:04 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-02-27 07:03:54 -05:00
|
|
|
if v := config.allowNondistributableArtifacts(tt.addr); v != tt.expected {
|
2017-05-09 17:00:31 -04:00
|
|
|
t.Errorf("allowNondistributableArtifacts failed for %q %v, expected %v got %v", tt.addr, tt.registries, tt.expected, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-06 21:54:52 -04:00
|
|
|
func TestIsSecureIndex(t *testing.T) {
|
2014-11-11 14:01:49 -05:00
|
|
|
tests := []struct {
|
|
|
|
addr string
|
|
|
|
insecureRegistries []string
|
|
|
|
expected bool
|
|
|
|
}{
|
2015-07-21 15:40:36 -04:00
|
|
|
{IndexName, nil, true},
|
2014-11-11 14:01:49 -05:00
|
|
|
{"example.com", []string{}, true},
|
|
|
|
{"example.com", []string{"example.com"}, false},
|
2014-11-12 12:08:45 -05:00
|
|
|
{"localhost", []string{"localhost:5000"}, false},
|
2014-11-11 14:01:49 -05:00
|
|
|
{"localhost:5000", []string{"localhost:5000"}, false},
|
2014-11-12 12:08:45 -05:00
|
|
|
{"localhost", []string{"example.com"}, false},
|
2014-11-11 14:01:49 -05:00
|
|
|
{"127.0.0.1:5000", []string{"127.0.0.1:5000"}, false},
|
2014-11-11 16:31:15 -05:00
|
|
|
{"localhost", nil, false},
|
|
|
|
{"localhost:5000", nil, false},
|
|
|
|
{"127.0.0.1", nil, false},
|
2014-11-12 12:08:45 -05:00
|
|
|
{"localhost", []string{"example.com"}, false},
|
|
|
|
{"127.0.0.1", []string{"example.com"}, false},
|
2014-11-11 16:31:15 -05:00
|
|
|
{"example.com", nil, true},
|
2014-10-31 16:00:49 -04:00
|
|
|
{"example.com", []string{"example.com"}, false},
|
2014-11-12 12:08:45 -05:00
|
|
|
{"127.0.0.1", []string{"example.com"}, false},
|
|
|
|
{"127.0.0.1:5000", []string{"example.com"}, false},
|
2014-11-11 16:31:15 -05:00
|
|
|
{"example.com:5000", []string{"42.42.0.0/16"}, false},
|
|
|
|
{"example.com", []string{"42.42.0.0/16"}, false},
|
|
|
|
{"example.com:5000", []string{"42.42.42.42/8"}, false},
|
|
|
|
{"127.0.0.1:5000", []string{"127.0.0.0/8"}, false},
|
|
|
|
{"42.42.42.42:5000", []string{"42.1.1.1/8"}, false},
|
2021-04-02 08:06:27 -04:00
|
|
|
{"invalid.example.com", []string{"42.42.0.0/16"}, true},
|
|
|
|
{"invalid.example.com", []string{"invalid.example.com"}, false},
|
|
|
|
{"invalid.example.com:5000", []string{"invalid.example.com"}, true},
|
|
|
|
{"invalid.example.com:5000", []string{"invalid.example.com:5000"}, false},
|
2014-10-31 16:00:49 -04:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
2017-09-01 10:35:04 -04:00
|
|
|
config, err := makeServiceConfig(nil, tt.insecureRegistries)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2022-02-27 07:03:54 -05:00
|
|
|
if sec := config.isSecureIndex(tt.addr); sec != tt.expected {
|
2014-10-06 21:54:52 -04:00
|
|
|
t.Errorf("isSecureIndex failed for %q %v, expected %v got %v", tt.addr, tt.insecureRegistries, tt.expected, sec)
|
2014-10-31 16:00:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-20 08:28:18 -04:00
|
|
|
|
|
|
|
type debugTransport struct {
|
|
|
|
http.RoundTripper
|
|
|
|
log func(...interface{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tr debugTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
|
|
dump, err := httputil.DumpRequestOut(req, false)
|
|
|
|
if err != nil {
|
|
|
|
tr.log("could not dump request")
|
|
|
|
}
|
|
|
|
tr.log(string(dump))
|
|
|
|
resp, err := tr.RoundTripper.RoundTrip(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
dump, err = httputil.DumpResponse(resp, false)
|
|
|
|
if err != nil {
|
|
|
|
tr.log("could not dump response")
|
|
|
|
}
|
|
|
|
tr.log(string(dump))
|
|
|
|
return resp, err
|
|
|
|
}
|