-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(sdk): mirror -config, -report-config, -dashboard for SDK callers #7393
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f3308fa
feat(sdk): mirror -config, -report-config, -dashboard for SDK callers
ShubhamRasal db15637
refactor(sdk): dedupe config loaders, drop threadSafePerScan mode
ShubhamRasal 44c63a8
docs(sdk): trim PR comments, fix two review nits
ShubhamRasal 642887e
fix(runner): restore nolint on deprecated ZTLS flag binding
ShubhamRasal d5d9eed
test(sdk): drop DisableUpdateCheck() from new lib/config_test.go
ShubhamRasal f2c95ef
fix(runner): suppress redundant "upload disabled" warning on default …
ShubhamRasal 0fc90a6
docs(runner): tighten SetupPDCPUpload disabled-branch comment to one …
ShubhamRasal fbf7d00
Merge branch 'dev' into sdk-upload
ShubhamRasal f783605
revert(sdk): keep CLI untouched, restore original PDCP disabled message
ShubhamRasal 609cf3d
refactor(sdk): replace goflags overlay with RuntimeConfig struct
ShubhamRasal 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
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,116 @@ | ||
| package nuclei | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/projectdiscovery/nuclei/v3/pkg/model/types/severity" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestWithConfigFile(t *testing.T) { | ||
| dir := t.TempDir() | ||
| cfgPath := filepath.Join(dir, "nuclei.yaml") | ||
| cfg := `tags: | ||
| - cve | ||
| severity: | ||
| - high | ||
| - critical | ||
| exclude-tags: | ||
| - dos | ||
| header: | ||
| - "X-Test: 1" | ||
| ` | ||
| require.NoError(t, os.WriteFile(cfgPath, []byte(cfg), 0o600)) | ||
|
|
||
| ne, err := NewNucleiEngine(WithConfigFile(cfgPath)) | ||
| require.NoError(t, err) | ||
| defer ne.Close() | ||
|
|
||
| opts := ne.Options() | ||
| require.Contains(t, opts.Tags, "cve") | ||
| require.Contains(t, opts.ExcludeTags, "dos") | ||
| require.Contains(t, opts.CustomHeaders, "X-Test: 1") | ||
|
|
||
| got := map[severity.Severity]bool{} | ||
| for _, s := range opts.Severities { | ||
| got[s] = true | ||
| } | ||
| require.True(t, got[severity.High]) | ||
| require.True(t, got[severity.Critical]) | ||
| } | ||
|
|
||
| func TestWithConfigBytes(t *testing.T) { | ||
| cfg := []byte("tags:\n - cve\ntemplate-id:\n - CVE-2024-0001\n") | ||
|
|
||
| ne, err := NewNucleiEngine(WithConfigBytes(cfg)) | ||
| require.NoError(t, err) | ||
| defer ne.Close() | ||
|
|
||
| opts := ne.Options() | ||
| require.Contains(t, opts.Tags, "cve") | ||
| require.Contains(t, opts.IncludeIds, "CVE-2024-0001") | ||
| } | ||
|
|
||
| func TestWithConfigBytes_ScalarKnobs(t *testing.T) { | ||
| cfg := []byte("rate-limit: 99\nbulk-size: 7\nconcurrency: 42\ntimeout: 30\nretries: 5\n") | ||
|
|
||
| ne, err := NewNucleiEngine(WithConfigBytes(cfg)) | ||
| require.NoError(t, err) | ||
| defer ne.Close() | ||
|
|
||
| opts := ne.Options() | ||
| require.Equal(t, 99, opts.RateLimit) | ||
| require.Equal(t, 7, opts.BulkSize) | ||
| require.Equal(t, 42, opts.TemplateThreads) | ||
| require.Equal(t, 30, opts.Timeout) | ||
| require.Equal(t, 5, opts.Retries) | ||
| } | ||
|
|
||
| func TestWithReportingConfigFile(t *testing.T) { | ||
| dir := t.TempDir() | ||
| rcPath := filepath.Join(dir, "report.yaml") | ||
| rc := `github: | ||
| username: test-user | ||
| owner: test-owner | ||
| token: test-token | ||
| project-name: test-project | ||
| issue-label: test | ||
| ` | ||
| require.NoError(t, os.WriteFile(rcPath, []byte(rc), 0o600)) | ||
|
|
||
| ne, err := NewNucleiEngine(WithReportingConfigFile(rcPath)) | ||
| require.NoError(t, err) | ||
| defer ne.Close() | ||
|
|
||
| ropts := ne.reportingOptionsForTest() | ||
| require.NotNil(t, ropts) | ||
| require.NotNil(t, ropts.GitHub) | ||
| require.Equal(t, "test-user", ropts.GitHub.Username) | ||
| require.Equal(t, "test-owner", ropts.GitHub.Owner) | ||
| } | ||
|
|
||
| func TestWithReportingConfigBytes(t *testing.T) { | ||
| rc := []byte(`github: | ||
| username: test-user | ||
| owner: test-owner | ||
| token: test-token | ||
| project-name: test-project | ||
| `) | ||
| ne, err := NewNucleiEngine(WithReportingConfigBytes(rc)) | ||
| require.NoError(t, err) | ||
| defer ne.Close() | ||
|
|
||
| ropts := ne.reportingOptionsForTest() | ||
| require.NotNil(t, ropts) | ||
| require.NotNil(t, ropts.GitHub) | ||
| require.Equal(t, "test-user", ropts.GitHub.Username) | ||
| } | ||
|
|
||
| // Invalid YAML must return an error, not a silently empty config. | ||
| func TestWithReportingConfigBytes_InvalidYAML(t *testing.T) { | ||
| rc := []byte("this: is: not: valid: yaml: ::::\n") | ||
| _, err := NewNucleiEngine(WithReportingConfigBytes(rc)) | ||
| require.Error(t, err) | ||
| } |
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,9 @@ | ||
| package nuclei | ||
|
|
||
| import "github.com/projectdiscovery/nuclei/v3/pkg/reporting" | ||
|
|
||
| // reportingOptionsForTest exposes e.reportingOpts to same-package tests. | ||
| // In a _test.go file so it stays off the public SDK surface. | ||
| func (e *NucleiEngine) reportingOptionsForTest() *reporting.Options { | ||
| return e.reportingOpts | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.