Reject non-regular explicit config files
This commit is contained in:
committed by
Brandon McGinty
parent
6da5b249f9
commit
b23afebdb3
@@ -364,8 +364,8 @@ func RequireConfigFile(fn string) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("config file %q: %w", path, err)
|
||||
}
|
||||
if info.IsDir() {
|
||||
return fmt.Errorf("config file %q is a directory", path)
|
||||
if !info.Mode().IsRegular() {
|
||||
return fmt.Errorf("config file %q is not a regular file", path)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -17,6 +17,16 @@ func TestRequireConfigFileRejectsMissingExplicitPath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequireConfigFileRejectsNonRegularFile(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "config.fifo")
|
||||
if err := os.Mkdir(path, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := RequireConfigFile(path); err == nil {
|
||||
t.Fatal("directory was accepted as an explicit config file")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigBackfillsRecordingDefaults(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
configPath := filepath.Join(dir, "barnard.toml")
|
||||
|
||||
Reference in New Issue
Block a user