Reject special files before preparing inputs
This commit is contained in:
@@ -276,8 +276,8 @@ func requireInspectionFile(path, label string) error {
|
||||
}
|
||||
return fmt.Errorf("stat %s %q: %w", label, path, err)
|
||||
}
|
||||
if info.IsDir() {
|
||||
return fmt.Errorf("%s %q is a directory", label, path)
|
||||
if !info.Mode().IsRegular() {
|
||||
return fmt.Errorf("%s %q is not a regular file", label, path)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
34
internal/app/operator_inspection_fifo_test.go
Normal file
34
internal/app/operator_inspection_fifo_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
//go:build unix
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func TestInspectStableInputsRejectsSpellCatalogFIFO(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
sourcePath := filepath.Join(root, "spells.fifo")
|
||||
if err := unix.Mkfifo(sourcePath, 0o644); err != nil {
|
||||
t.Fatalf("Mkfifo() error = %v", err)
|
||||
}
|
||||
|
||||
cfg := &config.Config{StableInputs: config.ResolvedStableInputs{
|
||||
SpellCatalogFile: config.ResolvedInputFile{Path: sourcePath, ConfigPath: filepath.Join(root, "campaign.yml")},
|
||||
}}
|
||||
for _, check := range inspectStableInputs(cfg) {
|
||||
if check.Name != "spell_catalog" {
|
||||
continue
|
||||
}
|
||||
if check.Err == nil || !strings.Contains(check.Err.Error(), "not a regular file") {
|
||||
t.Fatalf("spell catalog check = %#v, want regular-file rejection", check)
|
||||
}
|
||||
return
|
||||
}
|
||||
t.Fatal("spell catalog inspection result was not reported")
|
||||
}
|
||||
Reference in New Issue
Block a user