This patch simplifies the test by;
- re-using the registry-mock / handler
- skipping the last `docker build`, which was only
used to make sure a local image was present. Instead,
the daemon is started with a `busybox` image loaded.
Also added a comment, explaining why the mock always
returns a 404 (hence, error/output-string should not
be checked in the test), and made the mock return a
valid/correctly formatted error response.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -49,9 +49,14 @@ func regexpCheckUA(c *check.C, ua string) {
|
| 49 | 49 |
c.Assert(bMatchUpstreamUA, check.Equals, true, check.Commentf("(Upstream) Docker Client User-Agent malformed"))
|
| 50 | 50 |
} |
| 51 | 51 |
|
| 52 |
+// registerUserAgentHandler registers a handler for the `/v2/*` endpoint. |
|
| 53 |
+// Note that a 404 is returned to prevent the client to proceed. |
|
| 54 |
+// We are only checking if the client sent a valid User Agent string along |
|
| 55 |
+// with the request. |
|
| 52 | 56 |
func registerUserAgentHandler(reg *registry.Mock, result *string) {
|
| 53 | 57 |
reg.RegisterHandler("/v2/", func(w http.ResponseWriter, r *http.Request) {
|
| 54 | 58 |
w.WriteHeader(404) |
| 59 |
+ w.Write([]byte(`{"errors":[{"code": "UNSUPPORTED","message": "this is a mock registry"}]}`))
|
|
| 55 | 60 |
var ua string |
| 56 | 61 |
for k, v := range r.Header {
|
| 57 | 62 |
if k == "User-Agent" {
|
| ... | ... |
@@ -66,63 +71,33 @@ func registerUserAgentHandler(reg *registry.Mock, result *string) {
|
| 66 | 66 |
// a registry, the registry should see a User-Agent string of the form |
| 67 | 67 |
// [docker engine UA] UpstreamClientSTREAM-CLIENT([client UA]) |
| 68 | 68 |
func (s *DockerRegistrySuite) TestUserAgentPassThrough(c *check.C) {
|
| 69 |
- var ( |
|
| 70 |
- buildUA string |
|
| 71 |
- pullUA string |
|
| 72 |
- pushUA string |
|
| 73 |
- loginUA string |
|
| 74 |
- ) |
|
| 75 |
- |
|
| 76 |
- buildReg, err := registry.NewMock(c) |
|
| 77 |
- defer buildReg.Close() |
|
| 78 |
- c.Assert(err, check.IsNil) |
|
| 79 |
- registerUserAgentHandler(buildReg, &buildUA) |
|
| 80 |
- buildRepoName := fmt.Sprintf("%s/busybox", buildReg.URL())
|
|
| 81 |
- |
|
| 82 |
- pullReg, err := registry.NewMock(c) |
|
| 83 |
- defer pullReg.Close() |
|
| 84 |
- c.Assert(err, check.IsNil) |
|
| 85 |
- registerUserAgentHandler(pullReg, &pullUA) |
|
| 86 |
- pullRepoName := fmt.Sprintf("%s/busybox", pullReg.URL())
|
|
| 69 |
+ var ua string |
|
| 87 | 70 |
|
| 88 |
- pushReg, err := registry.NewMock(c) |
|
| 89 |
- defer pushReg.Close() |
|
| 71 |
+ reg, err := registry.NewMock(c) |
|
| 72 |
+ defer reg.Close() |
|
| 90 | 73 |
c.Assert(err, check.IsNil) |
| 91 |
- registerUserAgentHandler(pushReg, &pushUA) |
|
| 92 |
- pushRepoName := fmt.Sprintf("%s/busybox", pushReg.URL())
|
|
| 74 |
+ registerUserAgentHandler(reg, &ua) |
|
| 75 |
+ repoName := fmt.Sprintf("%s/busybox", reg.URL())
|
|
| 93 | 76 |
|
| 94 |
- loginReg, err := registry.NewMock(c) |
|
| 95 |
- defer loginReg.Close() |
|
| 96 |
- c.Assert(err, check.IsNil) |
|
| 97 |
- registerUserAgentHandler(loginReg, &loginUA) |
|
| 98 |
- |
|
| 99 |
- s.d.Start(c, |
|
| 100 |
- "--insecure-registry", buildReg.URL(), |
|
| 101 |
- "--insecure-registry", pullReg.URL(), |
|
| 102 |
- "--insecure-registry", pushReg.URL(), |
|
| 103 |
- "--insecure-registry", loginReg.URL()) |
|
| 77 |
+ s.d.StartWithBusybox(c, "--insecure-registry", reg.URL()) |
|
| 104 | 78 |
|
| 105 | 79 |
tmp, err := ioutil.TempDir("", "integration-cli-")
|
| 106 | 80 |
c.Assert(err, check.IsNil) |
| 107 | 81 |
defer os.RemoveAll(tmp) |
| 108 | 82 |
|
| 109 |
- dockerfileName, err := makefile(tmp, fmt.Sprintf("FROM %s", buildRepoName))
|
|
| 83 |
+ dockerfile, err := makefile(tmp, fmt.Sprintf("FROM %s", repoName))
|
|
| 110 | 84 |
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
| 111 | 85 |
|
| 112 |
- s.d.Cmd("build", "--file", dockerfileName, tmp)
|
|
| 113 |
- regexpCheckUA(c, buildUA) |
|
| 114 |
- |
|
| 115 |
- s.d.Cmd("login", "-u", "richard", "-p", "testtest", loginReg.URL())
|
|
| 116 |
- regexpCheckUA(c, loginUA) |
|
| 86 |
+ s.d.Cmd("build", "--file", dockerfile, tmp)
|
|
| 87 |
+ regexpCheckUA(c, ua) |
|
| 117 | 88 |
|
| 118 |
- s.d.Cmd("pull", pullRepoName)
|
|
| 119 |
- regexpCheckUA(c, pullUA) |
|
| 89 |
+ s.d.Cmd("login", "-u", "richard", "-p", "testtest", reg.URL())
|
|
| 90 |
+ regexpCheckUA(c, ua) |
|
| 120 | 91 |
|
| 121 |
- dockerfileName, err = makefile(tmp, `FROM scratch |
|
| 122 |
- ENV foo bar`) |
|
| 123 |
- c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
|
| 124 |
- s.d.Cmd("build", "-t", pushRepoName, "--file", dockerfileName, ".")
|
|
| 92 |
+ s.d.Cmd("pull", repoName)
|
|
| 93 |
+ regexpCheckUA(c, ua) |
|
| 125 | 94 |
|
| 126 |
- s.d.Cmd("push", pushRepoName)
|
|
| 127 |
- regexpCheckUA(c, pushUA) |
|
| 95 |
+ s.d.Cmd("tag", "busybox", repoName)
|
|
| 96 |
+ s.d.Cmd("push", repoName)
|
|
| 97 |
+ regexpCheckUA(c, ua) |
|
| 128 | 98 |
} |