vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Publish release and run artifacts as file trees
5f2a0b0a7f84ec1bb43af5213e5c788039b72222 · Keenan Nemetz · 20d ago · parent 6d574bec
Publish release and run artifacts as file trees Release pointers and run outputs are now slash-separated paths. A flat name is a one-segment path, so every existing release, pointer, URL, and workflow that uses dist/* keeps working. - metadata validates artifact paths, lists and loads them recursively, and refuses a tag that would make the tag/path boundary ambiguous - vole release attach keeps a directory's relative paths; a plain file keeps its base name - a workflow match is published relative to the declaration's static root, so dist/* stays flat while dist/*/* keeps one directory level - release and run download routes accept nested paths; Content-Disposition still saves the base name - one internal rule is shared by the pointer writer, metadata validator, run record, CLI, and routes so they cannot disagree Refs: 01M7BPH6RRPK2934FCHVJPQNGY
metadata/releases_test.go +202
| @@ -0,0 +1,202 @@ | |||
| 1 | package metadata | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | "strings" | ||
| 6 | "testing" | ||
| 7 | |||
| 8 | "rodent.software/vole/core/git" | ||
| 9 | "rodent.software/vole/core/lfs" | ||
| 10 | "rodent.software/vole/internal/artifactpath" | ||
| 11 | ) | ||
| 12 | |||
| 13 | const testOID = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" | ||
| 14 | |||
| 15 | func putReleaseBlob(t *testing.T, g *git.Repo, path string, body []byte) { | ||
| 16 | t.Helper() | ||
| 17 | if _, err := git.CommitFiles(g, Ref, func(files map[string][]byte) error { | ||
| 18 | files[path] = body | ||
| 19 | return nil | ||
| 20 | }, "release hand edit", "keenan"); err != nil { | ||
| 21 | t.Fatal(err) | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | func putReleasePointer(t *testing.T, g *git.Repo, path string, size int64) { | ||
| 26 | t.Helper() | ||
| 27 | putReleaseBlob(t, g, path, lfs.Pointer{OID: testOID, Size: size}.Encode()) | ||
| 28 | } | ||
| 29 | |||
| 30 | func TestValidArtifactPath(t *testing.T) { | ||
| 31 | t.Parallel() | ||
| 32 | longSegment := strings.Repeat("a", artifactpath.MaxSegment) | ||
| 33 | if err := ValidArtifactPath(longSegment); err != nil { | ||
| 34 | t.Fatalf("a segment at the limit was refused: %v", err) | ||
| 35 | } | ||
| 36 | deep := strings.TrimSuffix(strings.Repeat("a/", artifactpath.MaxDepth), "/") | ||
| 37 | if err := ValidArtifactPath(deep); err != nil { | ||
| 38 | t.Fatalf("a path at the depth limit was refused: %v", err) | ||
| 39 | } | ||
| 40 | |||
| 41 | valid := []string{ | ||
| 42 | "vole-linux-amd64", | ||
| 43 | "apt/Packages", | ||
| 44 | "yum/repodata/repomd.xml", | ||
| 45 | "a/.hidden", | ||
| 46 | "a/b/c/d", | ||
| 47 | longSegment, | ||
| 48 | deep, | ||
| 49 | } | ||
| 50 | for _, p := range valid { | ||
| 51 | if err := ValidArtifactPath(p); err != nil { | ||
| 52 | t.Errorf("ValidArtifactPath(%q) = %v, want nil", p, err) | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | invalid := map[string]string{ | ||
| 57 | "": "needs a path", | ||
| 58 | "/a": "empty segment", | ||
| 59 | "a/": "empty segment", | ||
| 60 | "a//b": "empty segment", | ||
| 61 | ".": "must not contain", | ||
| 62 | "..": "must not contain", | ||
| 63 | "a/./b": "must not contain", | ||
| 64 | "a/../b": "must not contain", | ||
| 65 | `a\b`: "backslash", | ||
| 66 | "a\nb": "control", | ||
| 67 | "a\tb": "control", | ||
| 68 | strings.Repeat("a", artifactpath.MaxSegment+1): "limit", | ||
| 69 | deep + "/a": "segments", | ||
| 70 | } | ||
| 71 | for p, want := range invalid { | ||
| 72 | err := ValidArtifactPath(p) | ||
| 73 | if err == nil { | ||
| 74 | t.Errorf("ValidArtifactPath(%q) = nil, want an error", p) | ||
| 75 | continue | ||
| 76 | } | ||
| 77 | if !strings.Contains(err.Error(), want) { | ||
| 78 | t.Errorf("ValidArtifactPath(%q) = %q, want it to mention %q", p, err, want) | ||
| 79 | } | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | func TestReleaseArtifactsNested(t *testing.T) { | ||
| 84 | t.Parallel() | ||
| 85 | g := writeRepo(t) | ||
| 86 | putReleasePointer(t, g, "releases/v1/vole.deb", 10) | ||
| 87 | putReleasePointer(t, g, "releases/v1/apt/Packages", 20) | ||
| 88 | putReleasePointer(t, g, "releases/v1/yum/repodata/repomd.xml", 30) | ||
| 89 | |||
| 90 | list, err := ListReleaseArtifacts(g, "v1") | ||
| 91 | if err != nil { | ||
| 92 | t.Fatal(err) | ||
| 93 | } | ||
| 94 | got := make([]string, len(list)) | ||
| 95 | for i, a := range list { | ||
| 96 | got[i] = a.Name | ||
| 97 | } | ||
| 98 | want := []string{"apt/Packages", "vole.deb", "yum/repodata/repomd.xml"} | ||
| 99 | if strings.Join(got, ",") != strings.Join(want, ",") { | ||
| 100 | t.Fatalf("artifacts = %v, want %v", got, want) | ||
| 101 | } | ||
| 102 | if list[0].Size != 20 || list[0].OID != testOID { | ||
| 103 | t.Fatalf("nested artifact = %+v", list[0]) | ||
| 104 | } | ||
| 105 | |||
| 106 | byTag, err := LoadArtifactsAt(g, Ref) | ||
| 107 | if err != nil { | ||
| 108 | t.Fatal(err) | ||
| 109 | } | ||
| 110 | if len(byTag["v1"]) != 3 { | ||
| 111 | t.Fatalf("LoadArtifactsAt = %+v, want three artifacts", byTag) | ||
| 112 | } | ||
| 113 | if !TagWithArtifacts(g, "v1") { | ||
| 114 | t.Fatal("TagWithArtifacts = false for a tag with nested artifacts") | ||
| 115 | } | ||
| 116 | if TagWithArtifacts(g, "missing") { | ||
| 117 | t.Fatal("TagWithArtifacts = true for a tag with no artifacts") | ||
| 118 | } | ||
| 119 | if missing, err := ListReleaseArtifacts(g, "missing"); err != nil || len(missing) != 0 { | ||
| 120 | t.Fatalf("missing tag = %v, %v; want an empty list", missing, err) | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | func TestReleaseProblemsNested(t *testing.T) { | ||
| 125 | t.Parallel() | ||
| 126 | g := writeRepo(t) | ||
| 127 | putReleasePointer(t, g, "releases/v1/apt/Packages", 20) | ||
| 128 | putReleasePointer(t, g, "releases/v1/yum/repodata/repomd.xml", 30) | ||
| 129 | if problems := ReleaseProblems(g, Ref); len(problems) != 0 { | ||
| 130 | t.Fatalf("nested pointers were refused: %v", problems) | ||
| 131 | } | ||
| 132 | |||
| 133 | putReleaseBlob(t, g, "releases/v1/apt/Release", []byte("not a pointer\n")) | ||
| 134 | problems := ReleaseProblems(g, Ref) | ||
| 135 | if len(problems) != 1 || !strings.Contains(problems[0], "git-lfs pointer") { | ||
| 136 | t.Fatalf("ReleaseProblems = %v, want one pointer problem", problems) | ||
| 137 | } | ||
| 138 | } | ||
| 139 | |||
| 140 | func TestReleaseProblemsRejectsBadPaths(t *testing.T) { | ||
| 141 | t.Parallel() | ||
| 142 | g := writeRepo(t) | ||
| 143 | putReleasePointer(t, g, "releases/v1/a\\b", 10) | ||
| 144 | problems := ReleaseProblems(g, Ref) | ||
| 145 | if len(problems) != 1 || !strings.Contains(problems[0], "backslash") { | ||
| 146 | t.Fatalf("ReleaseProblems = %v, want a bad-path problem", problems) | ||
| 147 | } | ||
| 148 | |||
| 149 | deep := "releases/v1/" + strings.TrimSuffix(strings.Repeat("a/", artifactpath.MaxDepth+1), "/") | ||
| 150 | putReleasePointer(t, g, deep, 10) | ||
| 151 | problems = ReleaseProblems(g, Ref) | ||
| 152 | if len(problems) != 2 { | ||
| 153 | t.Fatalf("ReleaseProblems = %v, want the backslash and depth problems", problems) | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 | func TestWriteReleasePointersValidates(t *testing.T) { | ||
| 158 | t.Parallel() | ||
| 159 | g := writeRepo(t) | ||
| 160 | art := Artifact{Name: "apt/Packages", OID: testOID, Size: 1} | ||
| 161 | if err := WriteReleasePointers(g, Ref, "release/v1", []Artifact{art}, "attach", "keenan"); err == nil { | ||
| 162 | t.Fatal("a tag containing / was accepted") | ||
| 163 | } | ||
| 164 | bad := Artifact{Name: "../escape", OID: testOID, Size: 1} | ||
| 165 | if err := WriteReleasePointers(g, Ref, "v1", []Artifact{bad}, "attach", "keenan"); err == nil { | ||
| 166 | t.Fatal("a traversal path was accepted") | ||
| 167 | } | ||
| 168 | if err := WriteReleasePointers(g, Ref, "v1", []Artifact{art}, "attach", "keenan"); err != nil { | ||
| 169 | t.Fatal(err) | ||
| 170 | } | ||
| 171 | list, err := ListReleaseArtifacts(g, "v1") | ||
| 172 | if err != nil { | ||
| 173 | t.Fatal(err) | ||
| 174 | } | ||
| 175 | if len(list) != 1 || list[0].Name != "apt/Packages" { | ||
| 176 | t.Fatalf("written artifact = %+v", list) | ||
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 180 | func TestLoadArtifactsAtIgnoresMalformedPaths(t *testing.T) { | ||
| 181 | t.Parallel() | ||
| 182 | g := writeRepo(t) | ||
| 183 | putReleasePointer(t, g, "releases/v1/a\\b", 10) | ||
| 184 | putReleasePointer(t, g, "releases/v1/vole.deb", 20) | ||
| 185 | byTag, err := LoadArtifactsAt(g, Ref) | ||
| 186 | if err != nil { | ||
| 187 | t.Fatal(err) | ||
| 188 | } | ||
| 189 | if len(byTag["v1"]) != 1 || byTag["v1"][0].Name != "vole.deb" { | ||
| 190 | t.Fatalf("LoadArtifactsAt = %+v, want only the valid path", byTag) | ||
| 191 | } | ||
| 192 | } | ||
| 193 | |||
| 194 | func ExampleValidArtifactPath() { | ||
| 195 | for _, p := range []string{"vole.deb", "apt/Packages", "yum/repodata/repomd.xml"} { | ||
| 196 | fmt.Println(ValidArtifactPath(p) == nil) | ||
| 197 | } | ||
| 198 | // Output: | ||
| 199 | // true | ||
| 200 | // true | ||
| 201 | // true | ||
| 202 | } | ||