//go:build linux package layout import ( "errors" "os" "path/filepath" "testing" "time" "golang.org/x/sys/unix" ) // TestReadJournalRefusesASymlinkAndAFIFO_FIFO is the FIFO half of // TestReadJournalRefusesASymlinkAndAFIFO: /data/layout is agent-owned, // but a flat tenant shares the agent's uid during the transition and can // plant a FIFO there in place of a journal. ReadJournal must refuse it // rather than block on the open. Run with a timeout so a regression here // fails the test instead of wedging it. func TestReadJournalRefusesASymlinkAndAFIFO_FIFO(t *testing.T) { dd := t.TempDir() dir := filepath.Join(dd, "layout") if err := os.MkdirAll(dir, 0o700); err != nil { t.Fatal(err) } if err := unix.Mkfifo(filepath.Join(dir, "h.example.com.json"), 0o600); err != nil { t.Fatalf("Mkfifo: %v", err) } done := make(chan error, 1) go func() { _, _, err := ReadJournal(dd, "h.example.com") done <- err }() select { case err := <-done: if err == nil { t.Error("a FIFO planted as a journal was read") } if errors.Is(err, os.ErrNotExist) { t.Errorf("FIFO reported as absent rather than refused: %v", err) } case <-time.After(2 * time.Second): t.Fatal("ReadJournal blocked on a FIFO instead of refusing it") } }