Skip to content

Commit

Permalink
Merge pull request #5676 from smarterclayton/fix_backward_docker
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed Nov 4, 2015
2 parents cb9efc2 + 2de8fcf commit d512cd0
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
6 changes: 5 additions & 1 deletion pkg/dockerregistry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,12 @@ func (c *connection) checkV2() (bool, error) {
case code >= 300 || resp.StatusCode < 200:
return false, nil
}
if len(resp.Header.Get("Docker-Distribution-API-Version")) == 0 {
glog.V(5).Infof("Registry v2 API at %s did not have a Docker-Distribution-API-Version header", base.String())
return false, nil
}

glog.V(5).Infof("Found registry v2 API at %s", base.String())
// TODO: check Docker-Distribution-API-Version?
return true, nil
}

Expand Down
55 changes: 55 additions & 0 deletions pkg/dockerregistry/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestV2Check(t *testing.T) {
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
called <- struct{}{}
if strings.HasSuffix(r.URL.Path, "/v2/") {
w.Header().Set("Docker-Distribution-API-Version", "registry/2.0")
w.WriteHeader(http.StatusOK)
return
}
Expand Down Expand Up @@ -73,6 +74,60 @@ func TestV2Check(t *testing.T) {
<-called
}

func TestV2CheckNoDistributionHeader(t *testing.T) {
called := make(chan struct{}, 3)
var uri *url.URL
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
called <- struct{}{}
if strings.HasSuffix(r.URL.Path, "/v2/") {
w.Header().Set("Docker-Distribution-API-Version", "")
w.WriteHeader(http.StatusOK)
return
}
w.Header().Set("X-Docker-Endpoints", uri.Host)

// Images
if strings.HasSuffix(r.URL.Path, "/images") {
return
}

// ImageTags
if strings.HasSuffix(r.URL.Path, "/tags") {
fmt.Fprintln(w, `{"tag1":"image1"}`)
return
}

// get tag->image id
if strings.HasSuffix(r.URL.Path, "latest") {
fmt.Fprintln(w, `"image1"`)
return
}

// get image json
if strings.HasSuffix(r.URL.Path, "json") {
fmt.Fprintln(w, `{"id":"image1"}`)
return
}
t.Fatalf("unexpected request: %s %s", r.Method, r.URL.RequestURI())
}))
uri, _ = url.Parse(server.URL)
conn, err := NewClient().Connect(uri.Host, true)
if err != nil {
t.Fatal(err)
}
tags, err := conn.ImageTags("foo", "bar")
if err != nil {
t.Fatal(err)
}
if tags["tag1"] != "image1" {
t.Errorf("unexpected tags: %#v", tags)
}

<-called
<-called
<-called
}

func TestInsecureHTTPS(t *testing.T) {
called := make(chan struct{}, 2)
var uri *url.URL
Expand Down
6 changes: 2 additions & 4 deletions test/integration/dockerregistryclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ func TestRegistryClientQuayIOImage(t *testing.T) {
t.Fatal(err)
}

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

0 comments on commit d512cd0

Please sign in to comment.