浏览代码

Merge pull request #8049 from unclejack/fix_tag_validation

graph: validate tags properly & add unit tests
Jessie Frazelle 10 年之前
父节点
当前提交
09982d0f97
共有 2 个文件被更改,包括 19 次插入1 次删除
  1. 1 1
      graph/tags.go
  2. 18 0
      graph/tags_unit_test.go

+ 1 - 1
graph/tags.go

@@ -19,7 +19,7 @@ import (
 const DEFAULTTAG = "latest"
 const DEFAULTTAG = "latest"
 
 
 var (
 var (
-	validTagName = regexp.MustCompile(`^[\w][\w.-]{1,29}$`)
+	validTagName = regexp.MustCompile(`^[\w][\w.-]{0,29}$`)
 )
 )
 
 
 type TagStore struct {
 type TagStore struct {

+ 18 - 0
graph/tags_unit_test.go

@@ -114,3 +114,21 @@ func TestLookupImage(t *testing.T) {
 		t.Errorf("Expected 1 image, none found")
 		t.Errorf("Expected 1 image, none found")
 	}
 	}
 }
 }
+
+func TestValidTagName(t *testing.T) {
+	validTags := []string{"9", "foo", "foo-test", "bar.baz.boo"}
+	for _, tag := range validTags {
+		if err := validateTagName(tag); err != nil {
+			t.Errorf("'%s' should've been a valid tag", tag)
+		}
+	}
+}
+
+func TestInvalidTagName(t *testing.T) {
+	validTags := []string{"-9", ".foo", "-test", ".", "-"}
+	for _, tag := range validTags {
+		if err := validateTagName(tag); err == nil {
+			t.Errorf("'%s' shouldn't have been a valid tag", tag)
+		}
+	}
+}