-
Notifications
You must be signed in to change notification settings - Fork 161
fix: create default provider config on first run instead of fatal error (fixes #487) #542
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
Merged
Mzack9999
merged 12 commits into
projectdiscovery:dev
from
XananasX7:fix/create-default-config-on-first-run
Jun 19, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
287e398
Update README.md
iambouali d0180b1
support-slack-username
gabrielsoltz 220a2e5
support-slack-icon-emoji
gabrielsoltz a9a1587
Merge pull request #459 from iambouali/patch-1
dogancanbakir c788b27
close response body after http request
dogancanbakir 1b1f424
Merge branch 'main' into implement-slack-username
dogancanbakir 2d6ef20
Merge pull request #504 from gabrielsoltz/implement-slack-username
dogancanbakir c3de69b
fix: create default provider config on first run instead of fatal err…
XananasX7 7238daa
fix: distinguish default vs user-specified config path; handle all-co…
XananasX7 b79507f
add tests
Mzack9999 bb56deb
skip secrets
Mzack9999 18d6e92
Merge remote-tracking branch 'origin/dev' into pr-542
Mzack9999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package runner | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "runtime" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/projectdiscovery/notify/pkg/types" | ||
| ) | ||
|
|
||
| // On first run with no -pc flag, NewRunner should create the default provider | ||
| // config (directory + commented template) instead of failing fatally (#487). | ||
| func TestNewRunner_FirstRunCreatesDefaultProviderConfig(t *testing.T) { | ||
| tmpHome := t.TempDir() | ||
| // os.UserHomeDir uses $HOME on unix and %USERPROFILE% on Windows. | ||
| t.Setenv("HOME", tmpHome) | ||
| t.Setenv("USERPROFILE", tmpHome) | ||
|
|
||
| options := &types.Options{} // empty ProviderConfig => default path | ||
| runner, err := NewRunner(options) | ||
| if err != nil { | ||
| t.Fatalf("NewRunner returned error on first run: %v", err) | ||
| } | ||
| if runner == nil { | ||
| t.Fatal("NewRunner returned nil runner") | ||
| } | ||
|
|
||
| want := filepath.Join(tmpHome, types.DefaultProviderConfigLocation) | ||
| if options.ProviderConfig != want { | ||
| t.Fatalf("ProviderConfig = %q, want %q", options.ProviderConfig, want) | ||
| } | ||
|
|
||
| info, statErr := os.Stat(options.ProviderConfig) | ||
| if statErr != nil { | ||
| t.Fatalf("default provider config was not created: %v", statErr) | ||
| } | ||
| if runtime.GOOS != "windows" { | ||
| if perm := info.Mode().Perm(); perm != 0o600 { | ||
| t.Errorf("config file perms = %o, want 0600", perm) | ||
| } | ||
| } | ||
|
|
||
| data, readErr := os.ReadFile(options.ProviderConfig) | ||
| if readErr != nil { | ||
| t.Fatalf("read created config: %v", readErr) | ||
| } | ||
| if !strings.Contains(string(data), "notify provider configuration") { | ||
| t.Errorf("created config missing template banner, got:\n%s", data) | ||
| } | ||
| } | ||
|
|
||
| // An explicitly supplied -pc path that does not exist must error, not silently | ||
| // create a template. | ||
| func TestNewRunner_ExplicitMissingConfigReturnsError(t *testing.T) { | ||
| missing := filepath.Join(t.TempDir(), "nope", "provider-config.yaml") | ||
| _, err := NewRunner(&types.Options{ProviderConfig: missing}) | ||
| if err == nil { | ||
| t.Fatal("expected error for missing explicit config path, got nil") | ||
| } | ||
| if !strings.Contains(err.Error(), "provider config file not found") { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if _, statErr := os.Stat(missing); !os.IsNotExist(statErr) { | ||
| t.Error("explicit missing path should not have been created") | ||
| } | ||
| } | ||
|
|
||
| // An empty / comment-only config (e.g. the freshly created template) must not | ||
| // block startup. | ||
| func TestNewRunner_CommentOnlyConfigIsTolerated(t *testing.T) { | ||
| path := filepath.Join(t.TempDir(), "provider-config.yaml") | ||
| if err := os.WriteFile(path, []byte("# only comments, no providers\n"), 0o600); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| runner, err := NewRunner(&types.Options{ProviderConfig: path}) | ||
| if err != nil { | ||
| t.Fatalf("comment-only config should be tolerated, got: %v", err) | ||
| } | ||
| if runner == nil { | ||
| t.Fatal("NewRunner returned nil runner") | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Add directory permission check to validate 0700 on the parent directory.
The implementation creates the parent directory with
0700permissions (as shown in context snippet runner.go:54), but the test only verifies file permissions. Directory permissions should also be validated since they're part of the security posture.🔒 Proposed addition to verify directory permissions
if runtime.GOOS != "windows" { if perm := info.Mode().Perm(); perm != 0o600 { t.Errorf("config file perms = %o, want 0600", perm) } + dirInfo, dirStatErr := os.Stat(filepath.Dir(options.ProviderConfig)) + if dirStatErr != nil { + t.Fatalf("stat config directory: %v", dirStatErr) + } + if dirPerm := dirInfo.Mode().Perm(); dirPerm != 0o700 { + t.Errorf("config directory perms = %o, want 0700", dirPerm) + } }📝 Committable suggestion
🤖 Prompt for AI Agents