Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

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.

Replace the runner allowlist with a runner role

648cd81bde97042f682a528ebb9ce6353b95bf3f · Keenan Nemetz · 1d ago · parent ea92d754

server/hook/scope_test.go +56

@@ -14,6 +14,7 @@ import (
14 14 "rodent.software/vole/ci/runs"
15 15 "rodent.software/vole/core/git"
16 16 "rodent.software/vole/forge/access"
17 "rodent.software/vole/forge/identity"
17 18 "rodent.software/vole/metadata"
18 19 )
19 20
@@ -78,6 +79,22 @@ func (s *scopedFixture) metadataTip() string {
78 79 return tip
79 80 }
80 81
82 // addAccount puts a name in the roster. The hook asks the roster whether an
83 // account is active before trusting its runner role, so a test that wants a
84 // runner to count has to create the account, not only the ACL entry.
85 func (s *scopedFixture) addAccount(name string) {
86 s.t.Helper()
87 ident, err := identity.Open(s.instanceDB)
88 if err != nil {
89 s.t.Fatal(err)
90 }
91 defer ident.Close()
92 ident.AuditPath = filepath.Join(filepath.Dir(s.instanceDB), "audit.log")
93 if _, err := ident.CreateBot(name, access.None, "", "test"); err != nil {
94 s.t.Fatal(err)
95 }
96 }
97
81 98 // push runs pre-receive as the job, with the credential fingerprint the server would
82 99 // have supplied. It pushes everything since before the writer ran.
83 100 func (s *scopedFixture) push(after func()) (int, string) {
@@ -102,6 +119,45 @@ func (s *scopedFixture) pushAs(actor, keyID string, after func()) (int, string)
102 119 return code, out
103 120 }
104 121
122 // A runner attaches the artifacts its job built. The pointer lives on the issues
123 // branch under releases/, which the contributor rules otherwise refuse.
124 func TestARunnerMayAttachReleaseArtifacts(t *testing.T) {
125 t.Parallel()
126 s := newScopedFixture(t)
127 s.addAccount("release-runner")
128 s.setACL(func(a *access.ACL) { a.Entries["release-runner"] = "runner" })
129 code, out := s.pushAs("release-runner", "", func() {
130 if err := metadata.WriteReleasePointers(s.m.Git(), metadata.Ref, "v1",
131 []metadata.Artifact{{Name: "tool", OID: strings.Repeat("a", 64), Size: 10}},
132 "attach", "release-runner"); err != nil {
133 t.Fatal(err)
134 }
135 })
136 if code != 0 {
137 t.Fatalf("a runner could not attach a release artifact: %s", out)
138 }
139 }
140
141 // The same path is not a contributor's to write: the role is the grant, not the
142 // ability to reach the metadata branch.
143 func TestAContributorCannotAttachReleaseArtifacts(t *testing.T) {
144 t.Parallel()
145 s := newScopedFixture(t)
146 code, out := s.pushAs("contributor", "", func() {
147 if err := metadata.WriteReleasePointers(s.m.Git(), metadata.Ref, "v1",
148 []metadata.Artifact{{Name: "tool", OID: strings.Repeat("a", 64), Size: 10}},
149 "attach", "contributor"); err != nil {
150 t.Fatal(err)
151 }
152 })
153 if code == 0 {
154 t.Fatal("a contributor attached a release artifact")
155 }
156 if !strings.Contains(out, "may not attach release artifacts") {
157 t.Fatalf("the refusal does not name the rule: %s", out)
158 }
159 }
160
105 161 func TestAJobMayAddItsOwnComment(t *testing.T) {
106 162 t.Parallel()
107 163 s := newScopedFixture(t)