@@ -3,10 +3,12 @@ package nuclei_test
33import (
44 "context"
55 "log"
6+ "os"
67 "testing"
78 "time"
89
910 nuclei "github.com/projectdiscovery/nuclei/v3/lib"
11+ "github.com/projectdiscovery/nuclei/v3/pkg/types"
1012 "github.com/stretchr/testify/require"
1113)
1214
@@ -55,3 +57,49 @@ func TestHeadlessOptionInitialization(t *testing.T) {
5557
5658 defer ne .Close ()
5759}
60+
61+ func TestThreadSafeNucleiEngineWithNoHostErrors (t * testing.T ) {
62+ tmpDir , err := os .MkdirTemp ("" , "nuclei-test-no-host-errors-*" )
63+ require .NoError (t , err )
64+
65+ tempTemplate , err := os .CreateTemp (tmpDir , "thread-safe-no-host-errors.*.yaml" )
66+ require .NoError (t , err )
67+
68+ _ , err = tempTemplate .WriteString (`id: thread-safe-no-host-errors
69+ info:
70+ name: Thread Safe (NoHostErrors)
71+ author: nuclei-sdk-test
72+ severity: info
73+ http:
74+ - method: GET
75+ path:
76+ - "{{BaseURL}}/"
77+ matchers:
78+ - type: word
79+ words:
80+ - "ok"` )
81+ require .NoError (t , err )
82+ require .NoError (t , tempTemplate .Close ())
83+
84+ options := types .DefaultOptions ().Copy ()
85+ options .NoHostErrors = true
86+ options .Timeout = 2
87+ options .Retries = 0
88+ options .BulkSize = 1
89+ options .TemplateThreads = 1
90+ options .Templates = append (options .Templates , tempTemplate .Name ())
91+
92+ ne , err := nuclei .NewThreadSafeNucleiEngineCtx (context .TODO (), nuclei .WithOptions (options ))
93+ require .NoError (t , err , "could not create nuclei engine" )
94+
95+ defer func () {
96+ ne .Close ()
97+ _ = os .RemoveAll (tmpDir )
98+ }()
99+
100+ err = ne .GlobalLoadAllTemplates ()
101+ require .NoError (t , err , "could not load templates" )
102+
103+ err = ne .ExecuteNucleiWithOptsCtx (context .TODO (), []string {"scanme.sh" })
104+ require .NoError (t , err , "nuclei execution should not return an error" )
105+ }
0 commit comments