H2 owner-pass-with-units-stopped: a row gives the directory back to the earlier account, the owner read stubbed

Builds: design 47 H2 H-A-602 (the pass back), AC-H2a, AC-H3
This commit is contained in:
2026-11-25 18:50:26 +01:00
parent 180d57fe16
commit d4fb8ef371
2 changed files with 17 additions and 4 deletions
+4 -1
View File
@@ -61,7 +61,7 @@ func giveContents(dir string, from, to [2]int, placed map[string]bool) (int, err
if err != nil {
return err
}
uid, gid, ok := statOwner(info)
uid, gid, ok := ownerRead(info)
if !ok || uid != from[0] {
return skip()
}
@@ -97,6 +97,9 @@ var journal = func(line string) { fmt.Fprintf(os.Stderr, "mesh-host: %s\n", line
// lchownContent owns one entry as itself, a link as a link; a variable so a test sees what was given without being root.
var lchownContent = os.Lchown
// ownerRead reads an entry's owner; a variable so a test shows entries owned by an account it is not without being root.
var ownerRead = statOwner
// placedPaths is every path the resources place, cleaned: what giveContents leaves to its own resource.
func placedPaths(resources ...[]declaration.Resource) map[string]bool {
out := map[string]bool{}
+13 -3
View File
@@ -26,6 +26,7 @@ func TestADirectoryGivesItsContentsTheNewOwner(t *testing.T) {
placed func(root string) []string
other string // a directory the stand-in deviceOf says is on another file system
group int // the group an entry keeps, when not to's
back bool // the pass back (H-A-602): the directory goes from to's account back to from's, the owner read stubbed
linked bool // token has a second name, token.again (H-A-579 (2))
want []string
}{
@@ -41,6 +42,8 @@ func TestADirectoryGivesItsContentsTheNewOwner(t *testing.T) {
want: []string{"data", "data/repo", "link", "token"}},
{name: "an entry with two hard links is left with its owner, and said", from: [2]int{me, myGroup}, linked: true,
want: []string{"data", "data/repo", "kept", "kept/webhook.secret", "link"}},
{name: "given back to the earlier account it keeps the same three: the user, the group only where it was the new one's, the rest left",
from: [2]int{me, myGroup}, back: true, want: []string{"data", "data/repo", "kept", "kept/webhook.secret", "link", "token"}},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
@@ -73,12 +76,19 @@ func TestADirectoryGivesItsContentsTheNewOwner(t *testing.T) {
t.Cleanup(func() { lchownContent, deviceOf, journal = wasChown, wasDevice, wasJournal })
journal = func(line string) { said = append(said, line) }
wantGroup := to[1]
from, target := c.from, to
if c.back {
// What the pass gave is now owned by the new account: every entry reads as to's, and goes back to c.from.
from, target, wantGroup = to, c.from, c.from[1]
ownerRead = func(os.FileInfo) (int, int, bool) { return to[0], to[1], true }
defer func() { ownerRead = statOwner }()
}
if c.group != 0 {
wantGroup = c.group
}
lchownContent = func(path string, uid, gid int) error {
if uid != to[0] || gid != wantGroup {
t.Errorf("%s given to %d:%d, want %d:%d", path, uid, gid, to[0], wantGroup)
if uid != target[0] || gid != wantGroup {
t.Errorf("%s given to %d:%d, want %d:%d", path, uid, gid, target[0], wantGroup)
}
rel, _ := filepath.Rel(root, path)
given = append(given, rel)
@@ -96,7 +106,7 @@ func TestADirectoryGivesItsContentsTheNewOwner(t *testing.T) {
placed[filepath.Clean(p)] = true
}
}
n, err := giveContents(root, c.from, to, placed)
n, err := giveContents(root, from, target, placed)
if err != nil {
t.Fatal(err)
}