forked from TrueCloudLab/distribution
Fixed mocked registry
This commit is contained in:
parent
14cc9fcfda
commit
3ca4529fbe
1 changed files with 10 additions and 4 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -69,7 +70,7 @@ var (
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
testRepositories = map[string]map[string]string{
|
testRepositories = map[string]map[string]string{
|
||||||
"foo/bar": {
|
"foo42/bar": {
|
||||||
"latest": "42d718c941f5c532ac049bf0b0ab53f0062f09a03afd4aa4a02c098e46032b9d",
|
"latest": "42d718c941f5c532ac049bf0b0ab53f0062f09a03afd4aa4a02c098e46032b9d",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -84,7 +85,7 @@ func init() {
|
||||||
r.HandleFunc("/v1/repositories/{repository:.+}/tags/{tag:.+}", handlerGetTag).Methods("GET")
|
r.HandleFunc("/v1/repositories/{repository:.+}/tags/{tag:.+}", handlerGetTag).Methods("GET")
|
||||||
r.HandleFunc("/v1/repositories/{repository:.+}/tags/{tag:.+}", handlerPutTag).Methods("PUT")
|
r.HandleFunc("/v1/repositories/{repository:.+}/tags/{tag:.+}", handlerPutTag).Methods("PUT")
|
||||||
r.HandleFunc("/v1/users{null:.*}", handlerUsers).Methods("GET", "POST", "PUT")
|
r.HandleFunc("/v1/users{null:.*}", handlerUsers).Methods("GET", "POST", "PUT")
|
||||||
r.HandleFunc("/v1/repositories/{repository:.+}{action:/images|/}", handlerImages).Method("GET", "PUT", "DELETE")
|
r.HandleFunc("/v1/repositories/{repository:.+}{action:/images|/}", handlerImages).Methods("GET", "PUT", "DELETE")
|
||||||
r.HandleFunc("/v1/repositories/{repository:.+}/auth", handlerAuth).Methods("PUT")
|
r.HandleFunc("/v1/repositories/{repository:.+}/auth", handlerAuth).Methods("PUT")
|
||||||
r.HandleFunc("/v1/search", handlerSearch).Methods("GET")
|
r.HandleFunc("/v1/search", handlerSearch).Methods("GET")
|
||||||
testHttpServer = httptest.NewServer(r)
|
testHttpServer = httptest.NewServer(r)
|
||||||
|
@ -103,6 +104,8 @@ func writeHeaders(w http.ResponseWriter) {
|
||||||
h.Add("Cache-Control", "no-cache")
|
h.Add("Cache-Control", "no-cache")
|
||||||
h.Add("X-Docker-Registry-Version", "0.0.0")
|
h.Add("X-Docker-Registry-Version", "0.0.0")
|
||||||
h.Add("X-Docker-Registry-Config", "mock")
|
h.Add("X-Docker-Registry-Config", "mock")
|
||||||
|
u, _ := url.Parse(testHttpServer.URL)
|
||||||
|
h.Add("X-Docker-Endpoints", u.Host)
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeResponse(w http.ResponseWriter, message interface{}, code int) {
|
func writeResponse(w http.ResponseWriter, message interface{}, code int) {
|
||||||
|
@ -146,6 +149,9 @@ func requiresAuth(w http.ResponseWriter, r *http.Request) bool {
|
||||||
value := fmt.Sprintf("FAKE-SESSION-%d", time.Now().UnixNano())
|
value := fmt.Sprintf("FAKE-SESSION-%d", time.Now().UnixNano())
|
||||||
cookie := &http.Cookie{Name: "session", Value: value, MaxAge: 3600}
|
cookie := &http.Cookie{Name: "session", Value: value, MaxAge: 3600}
|
||||||
http.SetCookie(w, cookie)
|
http.SetCookie(w, cookie)
|
||||||
|
//FIXME(sam): this should be sent only on Index routes
|
||||||
|
value = fmt.Sprintf("FAKE-TOKEN-%d", time.Now().UnixNano())
|
||||||
|
w.Header().Add("X-Docker-Token", value)
|
||||||
}
|
}
|
||||||
if len(r.Cookies()) > 0 {
|
if len(r.Cookies()) > 0 {
|
||||||
writeCookie()
|
writeCookie()
|
||||||
|
@ -281,12 +287,12 @@ func handlerImages(w http.ResponseWriter, r *http.Request) {
|
||||||
writeResponse(w, "", 204)
|
writeResponse(w, "", 204)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
images := make([]map[string]string)
|
images := []map[string]string{}
|
||||||
for image_id, layer := range testLayers {
|
for image_id, layer := range testLayers {
|
||||||
image := make(map[string]string)
|
image := make(map[string]string)
|
||||||
image["id"] = image_id
|
image["id"] = image_id
|
||||||
image["checksum"] = layer["checksum_tarsum"]
|
image["checksum"] = layer["checksum_tarsum"]
|
||||||
append(images, image)
|
images = append(images, image)
|
||||||
}
|
}
|
||||||
writeResponse(w, images, 200)
|
writeResponse(w, images, 200)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue