-
Notifications
You must be signed in to change notification settings - Fork 1
Harden config directory creation permissions to 0700
#25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c6b79fc
893ae59
7b879c0
c41a4d3
7972728
0352c61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,8 @@ package config | |
|
|
||
| import ( | ||
| "os" | ||
| path "path/filepath" | ||
| "path/filepath" | ||
| "runtime" | ||
| "testing" | ||
|
|
||
| "github.com/BurntSushi/toml" | ||
|
|
@@ -11,7 +12,7 @@ import ( | |
|
|
||
| func TestLoadConfig_ValidConfig(t *testing.T) { | ||
| tempDir := t.TempDir() | ||
| configPath := path.Join(tempDir, "config.toml") | ||
| configPath := filepath.Join(tempDir, "config.toml") | ||
| expectedCfg := Config{ | ||
| Main: main{ | ||
| Prompt: "\\u@\\h:\\d> ", | ||
|
|
@@ -36,7 +37,7 @@ func TestLoadConfig_MissingFile(t *testing.T) { | |
|
|
||
| func TestSaveConfig(t *testing.T) { | ||
| tempDir := t.TempDir() | ||
| configPath := path.Join(tempDir, "config.toml") | ||
| configPath := filepath.Join(tempDir, "config.toml") | ||
|
|
||
| err := SaveConfig(configPath) | ||
| assert.NoError(t, err) | ||
|
|
@@ -47,6 +48,22 @@ func TestSaveConfig(t *testing.T) { | |
| assert.Equal(t, "default", loadedCfg.Main.HistoryFile) | ||
| } | ||
|
|
||
| func TestSaveConfig_CreatesDirWithRestrictivePermission(t *testing.T) { | ||
| if runtime.GOOS == "windows" { | ||
| t.Skip("directory permission bits are not reliable on Windows") | ||
| } | ||
|
|
||
| tempDir := t.TempDir() | ||
| configPath := filepath.Join(tempDir, "nested", "config.toml") | ||
|
|
||
| err := SaveConfig(configPath) | ||
| assert.NoError(t, err) | ||
|
|
||
| info, err := os.Stat(filepath.Dir(configPath)) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, os.FileMode(0o700), info.Mode().Perm()) | ||
| } | ||
|
Comment on lines
+51
to
+65
|
||
|
|
||
| func TestMergeConfig(t *testing.T) { | ||
| testCase := []struct { | ||
| name string | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the import alias
pathfor thepath/filepathpackage (and then callingpath.Join/path.Dir) is easy to confuse with the standard librarypathpackage, especially as this file grows. Consider importingpath/filepathasfilepath(or without an alias) for clarity.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I replaced the
path/filepathalias withfilepathand updated usages ininternal/config/config_test.gofor clarity. Commit:7972728.