Browse code

Add default `serveraddress` value in remote API `/auth`

This fix tries to address the issue in #22244 where the remote
API `/auth` will not set the default value of `serveraddress`
if not provided. This behavior happens after only in 1.11.0
and is a regression as in 1.10.3 `serveraddress` will be assigned
with `IndexServer` if no value is provided.

The default value `IndexServer` is assigned to `serveraddress` if
no value provided in this fix.

An integration test `TestAuthApi` has been added to cover this change

This fix fixes #22244.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

Yong Tang authored on 2016/04/23 12:00:47
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,23 @@
0
+package main
1
+
2
+import (
3
+	"net/http"
4
+
5
+	"github.com/docker/docker/pkg/integration/checker"
6
+	"github.com/docker/engine-api/types"
7
+	"github.com/go-check/check"
8
+)
9
+
10
+// Test case for #22244
11
+func (s *DockerSuite) TestAuthApi(c *check.C) {
12
+	config := types.AuthConfig{
13
+		Username: "no-user",
14
+		Password: "no-password",
15
+	}
16
+
17
+	expected := "Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password\n"
18
+	status, body, err := sockRequest("POST", "/auth", config)
19
+	c.Assert(err, check.IsNil)
20
+	c.Assert(status, check.Equals, http.StatusUnauthorized)
21
+	c.Assert(string(body), checker.Contains, expected, check.Commentf("Expected: %v, got: %v", expected, string(body)))
22
+}
... ...
@@ -37,6 +37,9 @@ func (s *Service) ServiceConfig() *registrytypes.ServiceConfig {
37 37
 // It can be used to verify the validity of a client's credentials.
38 38
 func (s *Service) Auth(authConfig *types.AuthConfig, userAgent string) (status, token string, err error) {
39 39
 	serverAddress := authConfig.ServerAddress
40
+	if serverAddress == "" {
41
+		serverAddress = IndexServer
42
+	}
40 43
 	if !strings.HasPrefix(serverAddress, "https://") && !strings.HasPrefix(serverAddress, "http://") {
41 44
 		serverAddress = "https://" + serverAddress
42 45
 	}