Files
sqlite/ramfs_darwin_test.go
zooqueenandHanzo Dev 3af61e415c darwin verifies RAM-backed scratch the way Linux does
macOS ships a native tmpfs (mount_tmpfs), and statfs names the filesystem
type, so the envelope's fail-closed guard can now say yes to a real tmpfs
mount on darwin instead of refusing the platform outright. Until now every
encrypted store was untestable on a Mac: isRAMBacked was hard false off
Linux, so cek-backed suites failed on any commit and that noise is where
real failures go to hide.

A RAM disk image still fails closed — statfs cannot tell its HFS+/APFS
volume from a real disk, and the guard only accepts what it can verify.
The positive test binds to any tmpfs already mounted and skips otherwise,
since creating one needs root.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-04 18:16:43 -07:00

45 lines
1.4 KiB
Go

//go:build darwin
package sqlite
import (
"testing"
"golang.org/x/sys/unix"
)
// TestRAMBackedRefusesTheSystemVolume pins the fail-closed side on darwin: the
// sealed system volume is APFS by construction, never tmpfs, so it must never be
// accepted as scratch for a decrypted database.
func TestRAMBackedRefusesTheSystemVolume(t *testing.T) {
if isRAMBacked("/") {
t.Fatal("isRAMBacked accepted the APFS system volume — plaintext scratch would reach persistent storage")
}
}
// TestRAMBackedRecognisesTmpfs proves the positive side against a real mount: if
// this machine has a tmpfs mounted anywhere, its mountpoint must be accepted.
// With no tmpfs present the test skips — creating one needs root
// (sudo mount_tmpfs <dir>), which a test must not assume.
func TestRAMBackedRecognisesTmpfs(t *testing.T) {
n, err := unix.Getfsstat(nil, unix.MNT_NOWAIT)
if err != nil {
t.Fatalf("Getfsstat count: %v", err)
}
mounts := make([]unix.Statfs_t, n)
if _, err := unix.Getfsstat(mounts, unix.MNT_NOWAIT); err != nil {
t.Fatalf("Getfsstat: %v", err)
}
for _, m := range mounts {
if unix.ByteSliceToString(m.Fstypename[:]) != "tmpfs" {
continue
}
dir := unix.ByteSliceToString(m.Mntonname[:])
if !isRAMBacked(dir) {
t.Fatalf("isRAMBacked refused the tmpfs mount at %s", dir)
}
return
}
t.Skip("no tmpfs mounted; create one with: sudo mount_tmpfs <dir>")
}