Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions components/image-builder-bob/pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func rewriteDockerAPIURL(u *url.URL, fromRepo, toRepo, host, tag string) {
from = "/v2/" + strings.Trim(fromRepo, "/") + "/"
to = "/v2/" + strings.Trim(toRepo, "/") + "/"
)
u.Path = to + strings.TrimPrefix(u.Path, from)
u.Path = to + strings.TrimPrefix(strings.TrimPrefix(u.Path, from), "/")

// we reset the escaped encoding hint, because EscapedPath will produce a valid encoding.
u.RawPath = ""
Expand Down Expand Up @@ -95,7 +95,7 @@ func rewriteNonDockerAPIURL(u *url.URL, fromPrefix, toPrefix, host string) {
if toPrefix == "" {
to = "/"
}
u.Path = to + strings.TrimPrefix(u.Path, from)
u.Path = to + strings.TrimPrefix(strings.TrimPrefix(u.Path, from), "/")

// we reset the escaped encoding hint, because EscapedPath will produce a valid encoding.
u.RawPath = ""
Expand Down
33 changes: 33 additions & 0 deletions components/image-builder-bob/pkg/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ func TestRewriteNonDockerAPIURL(t *testing.T) {
Path: "/to/some/random/path",
},
},
{
Name: "fromPrefix and toPrefix are not empty and origin url is not start with fromPrefix",
in: input{
fromPrefix: "from",
toPrefix: "to",
host: "localhost.com",
u: url.URL{
Host: "example.com",
Path: "/other-string/some/random/path",
},
},
u: url.URL{
Host: "localhost.com",
Path: "/to/other-string/some/random/path",
},
},
{
Name: "fromPrefix and toPrefix are empty",
in: input{
Expand Down Expand Up @@ -134,6 +150,23 @@ func TestRewriteDockerAPIURL(t *testing.T) {
Path: "/v2/base/some/random/path",
},
},
{
Name: "remote to localhost without repo",
in: input{
fromRepo: "base-images",
toRepo: "base",
host: "localhost.com",
tag: "",
u: url.URL{
Host: "prince.azurecr.io",
Path: "/v2/other-string/some/random/path",
},
},
u: url.URL{
Host: "localhost.com",
Path: "/v2/base/v2/other-string/some/random/path",
},
},
{
Name: "localhost to remote",
in: input{
Expand Down
Loading