Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http and insecure are mutually exclusive, when used on a registry with a non-standard port #3382

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions util/resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"path"
"testing"

"github.com/containerd/containerd/remotes/docker"
"github.com/moby/buildkit/cmd/buildkitd/config"
rconfig "github.com/moby/buildkit/util/resolver/config"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -66,3 +68,82 @@ mirrors = ["https://url/", "https://url/path/"]
}
}
}

func TestFillInsecureOptsPlainHTTPOnly(t *testing.T) {
plainHTTP := true
hosts, err := fillInsecureOpts("testhost:8000", rconfig.RegistryConfig{
PlainHTTP: &plainHTTP,
}, docker.RegistryHost{
Host: "testhost:8000",
Scheme: "https",
Path: "v2/",
})
require.NoError(t, err)

require.Equal(t, 1, len(hosts))
for _, h := range hosts {
require.Equal(t, "http", h.Scheme)
}
}

func TestFillInsecureOptsInsecureOnly(t *testing.T) {
insecure := true
hosts, err := fillInsecureOpts("testhost:8000", rconfig.RegistryConfig{
Insecure: &insecure,
}, docker.RegistryHost{
Host: "testhost:8000",
Scheme: "https",
Path: "v2/",
})
require.NoError(t, err)

require.Equal(t, 1, len(hosts))
for _, h := range hosts {
require.Equal(t, "https", h.Scheme)
}
}

func TestFillInsecureOptsPlainHTTPAndInsecureWithTheSamePort(t *testing.T) {
plainHTTP := true
insecure := true
hosts, err := fillInsecureOpts("testhost:8000", rconfig.RegistryConfig{
Insecure: &insecure,
PlainHTTP: &plainHTTP,
}, docker.RegistryHost{
Host: "testhost:8000",
Scheme: "https",
Path: "v2/",
})
require.NoError(t, err)

require.Equal(t, 2, len(hosts))

require.Equal(t, "http", hosts[0].Scheme) // THIS
require.Equal(t, "testhost:8000", hosts[0].Host)

require.Equal(t, "https", hosts[1].Scheme) // AND THIS doesn't make sense
require.Equal(t, "testhost:8000", hosts[1].Host)
// why would you ever want to configure a registry to attempt both http and insecure on the same port?
}

func TestFillInsecureOptsPlainHTTPAndInsecureWithDefaultPorts(t *testing.T) {
plainHTTP := true
insecure := true
hosts, err := fillInsecureOpts("testhost", rconfig.RegistryConfig{
Insecure: &insecure,
PlainHTTP: &plainHTTP,
}, docker.RegistryHost{
Host: "testhost",
Scheme: "https",
Path: "v2/",
})
require.NoError(t, err)

require.Equal(t, 2, len(hosts))

require.Equal(t, "http", hosts[0].Scheme)
require.Equal(t, "testhost", hosts[0].Host)

require.Equal(t, "https", hosts[1].Scheme)
require.Equal(t, "testhost", hosts[1].Host)
}