...
|
...
|
@@ -8,6 +8,7 @@ import (
|
8
|
8
|
"io/ioutil"
|
9
|
9
|
"net/http"
|
10
|
10
|
"net/http/httptest"
|
|
11
|
+ "net/url"
|
11
|
12
|
"testing"
|
12
|
13
|
"time"
|
13
|
14
|
)
|
...
|
...
|
@@ -69,7 +70,7 @@ var (
|
69
|
69
|
},
|
70
|
70
|
}
|
71
|
71
|
testRepositories = map[string]map[string]string{
|
72
|
|
- "foo/bar": {
|
|
72
|
+ "foo42/bar": {
|
73
|
73
|
"latest": "42d718c941f5c532ac049bf0b0ab53f0062f09a03afd4aa4a02c098e46032b9d",
|
74
|
74
|
},
|
75
|
75
|
}
|
...
|
...
|
@@ -84,7 +85,7 @@ func init() {
|
84
|
84
|
r.HandleFunc("/v1/repositories/{repository:.+}/tags/{tag:.+}", handlerGetTag).Methods("GET")
|
85
|
85
|
r.HandleFunc("/v1/repositories/{repository:.+}/tags/{tag:.+}", handlerPutTag).Methods("PUT")
|
86
|
86
|
r.HandleFunc("/v1/users{null:.*}", handlerUsers).Methods("GET", "POST", "PUT")
|
87
|
|
- r.HandleFunc("/v1/repositories/{repository:.+}{action:/images|/}", handlerImages).Method("GET", "PUT", "DELETE")
|
|
87
|
+ r.HandleFunc("/v1/repositories/{repository:.+}{action:/images|/}", handlerImages).Methods("GET", "PUT", "DELETE")
|
88
|
88
|
r.HandleFunc("/v1/repositories/{repository:.+}/auth", handlerAuth).Methods("PUT")
|
89
|
89
|
r.HandleFunc("/v1/search", handlerSearch).Methods("GET")
|
90
|
90
|
testHttpServer = httptest.NewServer(r)
|
...
|
...
|
@@ -103,6 +104,8 @@ func writeHeaders(w http.ResponseWriter) {
|
103
|
103
|
h.Add("Cache-Control", "no-cache")
|
104
|
104
|
h.Add("X-Docker-Registry-Version", "0.0.0")
|
105
|
105
|
h.Add("X-Docker-Registry-Config", "mock")
|
|
106
|
+ u, _ := url.Parse(testHttpServer.URL)
|
|
107
|
+ h.Add("X-Docker-Endpoints", u.Host)
|
106
|
108
|
}
|
107
|
109
|
|
108
|
110
|
func writeResponse(w http.ResponseWriter, message interface{}, code int) {
|
...
|
...
|
@@ -146,6 +149,9 @@ func requiresAuth(w http.ResponseWriter, r *http.Request) bool {
|
146
|
146
|
value := fmt.Sprintf("FAKE-SESSION-%d", time.Now().UnixNano())
|
147
|
147
|
cookie := &http.Cookie{Name: "session", Value: value, MaxAge: 3600}
|
148
|
148
|
http.SetCookie(w, cookie)
|
|
149
|
+ //FIXME(sam): this should be sent only on Index routes
|
|
150
|
+ value = fmt.Sprintf("FAKE-TOKEN-%d", time.Now().UnixNano())
|
|
151
|
+ w.Header().Add("X-Docker-Token", value)
|
149
|
152
|
}
|
150
|
153
|
if len(r.Cookies()) > 0 {
|
151
|
154
|
writeCookie()
|
...
|
...
|
@@ -281,12 +287,12 @@ func handlerImages(w http.ResponseWriter, r *http.Request) {
|
281
|
281
|
writeResponse(w, "", 204)
|
282
|
282
|
return
|
283
|
283
|
}
|
284
|
|
- images := make([]map[string]string)
|
|
284
|
+ images := []map[string]string{}
|
285
|
285
|
for image_id, layer := range testLayers {
|
286
|
286
|
image := make(map[string]string)
|
287
|
287
|
image["id"] = image_id
|
288
|
288
|
image["checksum"] = layer["checksum_tarsum"]
|
289
|
|
- append(images, image)
|
|
289
|
+ images = append(images, image)
|
290
|
290
|
}
|
291
|
291
|
writeResponse(w, images, 200)
|
292
|
292
|
}
|