vole
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software:2222/vole.git
A free and open-source forge that lives in your Git repo.
refactor
c5902451905acdaa478f8476844ccd4a510d9ca9 · Keenan Nemetz · 17d ago · parent ec2aba4b
internal/access/access_test.go → forge/access/store_test.go +5−13
| @@ -3,15 +3,12 @@ package access | |||
| 3 | 3 | // Access rules are one row per repository in the instance database. These tests pin the | |
| 4 | 4 | // two things the file-based version gave for free: a repository with no rules denies | |
| 5 | 5 | // everything, and a change leaves a trace. | |
| 6 | |||
| 7 | 6 | import ( | |
| 8 | 7 | "os" | |
| 9 | 8 | "path/filepath" | |
| 10 | 9 | "strings" | |
| 11 | 10 | "testing" | |
| 12 | 11 | "time" | |
| 13 | |||
| 14 | "github.com/rodent-software/vole/internal/acl" | ||
| 15 | 12 | ) | |
| 16 | 13 | ||
| 17 | 14 | func open(t *testing.T) (*Store, string) { | |
| @@ -25,15 +22,13 @@ func open(t *testing.T) (*Store, string) { | |||
| 25 | 22 | t.Cleanup(func() { s.Close() }) | |
| 26 | 23 | return s, dir | |
| 27 | 24 | } | |
| 28 | |||
| 29 | 25 | func TestRulesRoundTripAndReplace(t *testing.T) { | |
| 30 | 26 | t.Parallel() | |
| 31 | 27 | s, _ := open(t) | |
| 32 | 28 | if a, err := s.Get("repo-1"); err != nil || a != nil { | |
| 33 | 29 | t.Fatalf("a repository with no rules returned %+v, %v", a, err) | |
| 34 | 30 | } | |
| 35 | |||
| 36 | a := acl.Empty("01M5OWNER0000000000000000A") | ||
| 31 | a := Empty("01M5OWNER0000000000000000A") | ||
| 37 | 32 | if err := a.SetEntry("01M5WRITER000000000000000B", "write"); err != nil { | |
| 38 | 33 | t.Fatal(err) | |
| 39 | 34 | } | |
| @@ -42,27 +37,24 @@ func TestRulesRoundTripAndReplace(t *testing.T) { | |||
| 42 | 37 | if err := s.Set("repo-1", a, "keenan", time.Now().UTC()); err != nil { | |
| 43 | 38 | t.Fatal(err) | |
| 44 | 39 | } | |
| 45 | |||
| 46 | 40 | got, err := s.Get("repo-1") | |
| 47 | 41 | if err != nil || got == nil { | |
| 48 | 42 | t.Fatalf("get: %+v, %v", got, err) | |
| 49 | 43 | } | |
| 50 | if got.RoleFor("01M5WRITER000000000000000B") != acl.Write || | ||
| 44 | if got.RoleFor("01M5WRITER000000000000000B") != Write || | ||
| 51 | 45 | !got.CanReport("01M5RUNNER000000000000000C") || | |
| 52 | 46 | len(got.Protected) != 1 { | |
| 53 | 47 | t.Fatalf("rules came back different: %+v", got) | |
| 54 | 48 | } | |
| 55 | |||
| 56 | 49 | // A replacement is a replacement: nothing of the old list survives. | |
| 57 | next := acl.Empty("01M5OWNER0000000000000000A") | ||
| 50 | next := Empty("01M5OWNER0000000000000000A") | ||
| 58 | 51 | if err := s.Set("repo-1", next, "keenan", time.Now().UTC()); err != nil { | |
| 59 | 52 | t.Fatal(err) | |
| 60 | 53 | } | |
| 61 | 54 | got, _ = s.Get("repo-1") | |
| 62 | if got.RoleFor("01M5WRITER000000000000000B") != acl.None { | ||
| 55 | if got.RoleFor("01M5WRITER000000000000000B") != None { | ||
| 63 | 56 | t.Fatalf("the previous rule survived a replacement: %+v", got) | |
| 64 | 57 | } | |
| 65 | |||
| 66 | 58 | // Deleting the repository forgets its rules, so a new repository with a recycled id | |
| 67 | 59 | // cannot inherit them. | |
| 68 | 60 | if err := s.Delete("repo-1"); err != nil { | |
| @@ -80,7 +72,7 @@ func TestChangesAreAudited(t *testing.T) { | |||
| 80 | 72 | s, dir := open(t) | |
| 81 | 73 | audit := filepath.Join(dir, "audit.log") | |
| 82 | 74 | s.AuditPath = audit | |
| 83 | if err := s.Set("repo-1", acl.Empty("01M5OWNER0000000000000000A"), "keenan", time.Now().UTC()); err != nil { | ||
| 75 | if err := s.Set("repo-1", Empty("01M5OWNER0000000000000000A"), "keenan", time.Now().UTC()); err != nil { | ||
| 84 | 76 | t.Fatal(err) | |
| 85 | 77 | } | |
| 86 | 78 | raw, err := os.ReadFile(audit) | |