Browse code

client: Allow hex strings as source references for ImageTag

The source of a tag operation is allowed to be a 64-character hex
string. This means it should use ParseAnyReference for validation
instead of ParseNormalizedNamed.

This fixes a regression that happened in 17.04.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>

Aaron Lehmann authored on 2017/04/12 05:37:04
Showing 2 changed files
... ...
@@ -10,7 +10,7 @@ import (
10 10
 
11 11
 // ImageTag tags an image in the docker host
12 12
 func (cli *Client) ImageTag(ctx context.Context, source, target string) error {
13
-	if _, err := reference.ParseNormalizedNamed(source); err != nil {
13
+	if _, err := reference.ParseAnyReference(source); err != nil {
14 14
 		return errors.Wrapf(err, "Error parsing reference: %q is not a valid repository/tag", source)
15 15
 	}
16 16
 
... ...
@@ -46,6 +46,17 @@ func TestImageTagInvalidSourceImageName(t *testing.T) {
46 46
 	}
47 47
 }
48 48
 
49
+func TestImageTagHexSource(t *testing.T) {
50
+	client := &Client{
51
+		client: newMockClient(errorMock(http.StatusOK, "OK")),
52
+	}
53
+
54
+	err := client.ImageTag(context.Background(), "0d409d33b27e47423b049f7f863faa08655a8c901749c2b25b93ca67d01a470d", "repo:tag")
55
+	if err != nil {
56
+		t.Fatalf("got error: %v", err)
57
+	}
58
+}
59
+
49 60
 func TestImageTag(t *testing.T) {
50 61
 	expectedURL := "/images/image_id/tag"
51 62
 	tagCases := []struct {