Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions pkg/v1/remote/transport/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ func pingSingle(ctx context.Context, reg name.Registry, t http.RoundTripper, sch
resp.Body.Close()
}()

// Check actual registry scheme detected, in case of redirecting to different scheme,
// update the scheme so subsequent logic (and the returned Challenge) reflects it.
if resp.Request != nil && resp.Request.URL != nil && resp.Request.URL.Scheme != "" {
scheme = resp.Request.URL.Scheme
}

insecure := scheme == "http"

switch resp.StatusCode {
Expand Down
30 changes: 30 additions & 0 deletions pkg/v1/remote/transport/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,36 @@
}
}

func TestPingHttpFixture(t *testing.T) {
var httpsPassed bool
server := httptest.NewServer(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Check failure on line 237 in pkg/v1/remote/transport/ping_test.go

View workflow job for this annotation

GitHub Actions / Lint

unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
httpsPassed = true
time.Sleep(time.Second * 3)
w.WriteHeader(http.StatusOK)
}))
defer server.Close()

tprt := &http.Transport{
Proxy: func(req *http.Request) (*url.URL, error) {
if httpsPassed {
return http.ProxyFromEnvironment(req)
}

return url.Parse(server.URL)
},
}

challenge, err := Ping(context.Background(), mustInsecureRegistry("us.gcr.io"), tprt)
if err != nil {
t.Fatalf("Ping(): %v", err)
}

if challenge.Insecure {
t.Fatalf("Insecure fixture is not working")
}
}

func mustRegistry(r string) name.Registry {
reg, err := name.NewRegistry(r)
if err != nil {
Expand Down
Loading