Skip to content

Commit d512cd0

Browse files
author
OpenShift Bot
committed
Merge pull request #5676 from smarterclayton/fix_backward_docker
Merged by openshift-bot
2 parents cb9efc2 + 2de8fcf commit d512cd0

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

pkg/dockerregistry/client.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,12 @@ func (c *connection) checkV2() (bool, error) {
312312
case code >= 300 || resp.StatusCode < 200:
313313
return false, nil
314314
}
315+
if len(resp.Header.Get("Docker-Distribution-API-Version")) == 0 {
316+
glog.V(5).Infof("Registry v2 API at %s did not have a Docker-Distribution-API-Version header", base.String())
317+
return false, nil
318+
}
319+
315320
glog.V(5).Infof("Found registry v2 API at %s", base.String())
316-
// TODO: check Docker-Distribution-API-Version?
317321
return true, nil
318322
}
319323

pkg/dockerregistry/client_test.go

+55
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func TestV2Check(t *testing.T) {
4343
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
4444
called <- struct{}{}
4545
if strings.HasSuffix(r.URL.Path, "/v2/") {
46+
w.Header().Set("Docker-Distribution-API-Version", "registry/2.0")
4647
w.WriteHeader(http.StatusOK)
4748
return
4849
}
@@ -73,6 +74,60 @@ func TestV2Check(t *testing.T) {
7374
<-called
7475
}
7576

77+
func TestV2CheckNoDistributionHeader(t *testing.T) {
78+
called := make(chan struct{}, 3)
79+
var uri *url.URL
80+
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
81+
called <- struct{}{}
82+
if strings.HasSuffix(r.URL.Path, "/v2/") {
83+
w.Header().Set("Docker-Distribution-API-Version", "")
84+
w.WriteHeader(http.StatusOK)
85+
return
86+
}
87+
w.Header().Set("X-Docker-Endpoints", uri.Host)
88+
89+
// Images
90+
if strings.HasSuffix(r.URL.Path, "/images") {
91+
return
92+
}
93+
94+
// ImageTags
95+
if strings.HasSuffix(r.URL.Path, "/tags") {
96+
fmt.Fprintln(w, `{"tag1":"image1"}`)
97+
return
98+
}
99+
100+
// get tag->image id
101+
if strings.HasSuffix(r.URL.Path, "latest") {
102+
fmt.Fprintln(w, `"image1"`)
103+
return
104+
}
105+
106+
// get image json
107+
if strings.HasSuffix(r.URL.Path, "json") {
108+
fmt.Fprintln(w, `{"id":"image1"}`)
109+
return
110+
}
111+
t.Fatalf("unexpected request: %s %s", r.Method, r.URL.RequestURI())
112+
}))
113+
uri, _ = url.Parse(server.URL)
114+
conn, err := NewClient().Connect(uri.Host, true)
115+
if err != nil {
116+
t.Fatal(err)
117+
}
118+
tags, err := conn.ImageTags("foo", "bar")
119+
if err != nil {
120+
t.Fatal(err)
121+
}
122+
if tags["tag1"] != "image1" {
123+
t.Errorf("unexpected tags: %#v", tags)
124+
}
125+
126+
<-called
127+
<-called
128+
<-called
129+
}
130+
76131
func TestInsecureHTTPS(t *testing.T) {
77132
called := make(chan struct{}, 2)
78133
var uri *url.URL

test/integration/dockerregistryclient_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ func TestRegistryClientQuayIOImage(t *testing.T) {
129129
t.Fatal(err)
130130
}
131131

132-
_, err = conn.ImageByTag("coreos", "etcd", "latest")
133-
if err != nil {
134-
t.Skip("SKIPPING: unexpected error from quay.io: %v", err)
135-
//t.Errorf("unexpected error: %v", err)
132+
if _, err := conn.ImageByTag("coreos", "etcd", "latest"); err != nil {
133+
t.Errorf("unexpected error: %v", err)
136134
}
137135
}

0 commit comments

Comments
 (0)