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.
Let repo create choose visibility, not an owner
d74e7e231de16fa00366dc8ccc392fc9c637b52d · Keenan Nemetz · 3d ago · parent 3455902a
Let repo create choose visibility, not an owner A repository has no owner: the argument only seeded one admin entry in the ACL store, and instance admins can already administer every repository. The create command therefore asked for a fact the repository does not keep. Replace --owner with --visibility private|public on `vole admin repo create`, the remote admin command, and the web form. The initial rule set is written once, inside the store, so a public repository is never briefly private. An admin who wants to hand a repository to someone grants a role with the acl commands, exactly as for any later access change. closes: 01M82CC7G9W46PRP89GQ5CNMDE
forge/repo/repo_test.go +60−5
| @@ -57,7 +57,7 @@ func legacyWriteACL(t *testing.T, m *Meta, a *access.ACL) { | |||
| 57 | 57 | func TestImportACLsTakesRulesFromTheOldRef(t *testing.T) { | |
| 58 | 58 | t.Parallel() | |
| 59 | 59 | st, acls := withACLs(t) | |
| 60 | m, err := st.Create("demo", "01M5OWNER0000000000000000A", "") | ||
| 60 | m, err := st.Create("demo", CreateOptions{Owner: "01M5OWNER0000000000000000A"}) | ||
| 61 | 61 | if err != nil { | |
| 62 | 62 | t.Fatal(err) | |
| 63 | 63 | } | |
| @@ -101,7 +101,7 @@ func TestImportACLsTakesRulesFromTheOldRef(t *testing.T) { | |||
| 101 | 101 | func TestImportACLsLeavesRepositoriesWithoutTheRefAlone(t *testing.T) { | |
| 102 | 102 | t.Parallel() | |
| 103 | 103 | st, acls := withACLs(t) | |
| 104 | m, err := st.Create("demo", "01M5OWNER0000000000000000A", "") | ||
| 104 | m, err := st.Create("demo", CreateOptions{Owner: "01M5OWNER0000000000000000A"}) | ||
| 105 | 105 | if err != nil { | |
| 106 | 106 | t.Fatal(err) | |
| 107 | 107 | } | |
| @@ -125,7 +125,7 @@ func TestImportACLsLeavesRepositoriesWithoutTheRefAlone(t *testing.T) { | |||
| 125 | 125 | func TestDeletingARepositoryForgetsItsRules(t *testing.T) { | |
| 126 | 126 | t.Parallel() | |
| 127 | 127 | st, acls := withACLs(t) | |
| 128 | m, err := st.Create("demo", "01M5OWNER0000000000000000A", "") | ||
| 128 | m, err := st.Create("demo", CreateOptions{Owner: "01M5OWNER0000000000000000A"}) | ||
| 129 | 129 | if err != nil { | |
| 130 | 130 | t.Fatal(err) | |
| 131 | 131 | } | |
| @@ -140,7 +140,7 @@ func TestDeletingARepositoryForgetsItsRules(t *testing.T) { | |||
| 140 | 140 | func TestDescriptionWritesAndClears(t *testing.T) { | |
| 141 | 141 | t.Parallel() | |
| 142 | 142 | st, _ := withACLs(t) | |
| 143 | m, err := st.Create("demo", "01M5OWNER0000000000000000A", "first") | ||
| 143 | m, err := st.Create("demo", CreateOptions{Owner: "01M5OWNER0000000000000000A", Description: "first"}) | ||
| 144 | 144 | if err != nil { | |
| 145 | 145 | t.Fatal(err) | |
| 146 | 146 | } | |
| @@ -181,7 +181,7 @@ func TestPublicRepositoriesAreTheOnlySitesEligibleForCertificates(t *testing.T) | |||
| 181 | 181 | if st.Public("missing") { | |
| 182 | 182 | t.Fatal("a missing repository is public") | |
| 183 | 183 | } | |
| 184 | m, err := st.Create("demo", "01M5OWNER0000000000000000A", "") | ||
| 184 | m, err := st.Create("demo", CreateOptions{Owner: "01M5OWNER0000000000000000A"}) | ||
| 185 | 185 | if err != nil { | |
| 186 | 186 | t.Fatal(err) | |
| 187 | 187 | } | |
| @@ -200,3 +200,58 @@ func TestPublicRepositoriesAreTheOnlySitesEligibleForCertificates(t *testing.T) | |||
| 200 | 200 | t.Fatal("a repository readable by default is not public") | |
| 201 | 201 | } | |
| 202 | 202 | } | |
| 203 | |||
| 204 | // Create writes the visibility into the initial rule set, so a public | ||
| 205 | // repository is never briefly private and there is no second write to fail. | ||
| 206 | func TestCreateWritesTheVisibilityItIsGiven(t *testing.T) { | ||
| 207 | t.Parallel() | ||
| 208 | st, _ := withACLs(t) | ||
| 209 | |||
| 210 | private, err := st.Create("private", CreateOptions{}) | ||
| 211 | if err != nil { | ||
| 212 | t.Fatal(err) | ||
| 213 | } | ||
| 214 | if st.Public("private") { | ||
| 215 | t.Fatal("the zero visibility created a public repository") | ||
| 216 | } | ||
| 217 | a, err := private.ACL() | ||
| 218 | if err != nil { | ||
| 219 | t.Fatal(err) | ||
| 220 | } | ||
| 221 | if a.Default != "none" || len(a.Entries) != 0 { | ||
| 222 | t.Fatalf("private repository rules = %+v", a) | ||
| 223 | } | ||
| 224 | |||
| 225 | public, err := st.Create("public", CreateOptions{Visibility: Public}) | ||
| 226 | if err != nil { | ||
| 227 | t.Fatal(err) | ||
| 228 | } | ||
| 229 | if !st.Public("public") { | ||
| 230 | t.Fatal("a public repository is not readable by default") | ||
| 231 | } | ||
| 232 | a, err = public.ACL() | ||
| 233 | if err != nil { | ||
| 234 | t.Fatal(err) | ||
| 235 | } | ||
| 236 | if a.Default != "read" || len(a.Entries) != 0 { | ||
| 237 | t.Fatalf("public repository rules = %+v", a) | ||
| 238 | } | ||
| 239 | |||
| 240 | if _, err := st.Create("unknown", CreateOptions{Visibility: "internal"}); err == nil { | ||
| 241 | t.Fatal("an unknown visibility was accepted") | ||
| 242 | } | ||
| 243 | } | ||
| 244 | |||
| 245 | func TestParseVisibilityAcceptsOnlyTheTwoWords(t *testing.T) { | ||
| 246 | t.Parallel() | ||
| 247 | for _, in := range []string{"private", " Public ", "PUBLIC"} { | ||
| 248 | if _, err := ParseVisibility(in); err != nil { | ||
| 249 | t.Fatalf("ParseVisibility(%q): %v", in, err) | ||
| 250 | } | ||
| 251 | } | ||
| 252 | for _, in := range []string{"", "none", "internal", "public-ish"} { | ||
| 253 | if _, err := ParseVisibility(in); err == nil { | ||
| 254 | t.Fatalf("ParseVisibility(%q) was accepted", in) | ||
| 255 | } | ||
| 256 | } | ||
| 257 | } | ||