@@ -17,17 +17,19 @@ var jsTestcases = []TestCaseInfo{
1717 {Path : "protocols/javascript/net-https.yaml" , TestCase : & javascriptNetHttps {}},
1818 {Path : "protocols/javascript/oracle-auth-test.yaml" , TestCase : & javascriptOracleAuthTest {}, DisableOn : func () bool { return osutils .IsWindows () || osutils .IsOSX () }},
1919 {Path : "protocols/javascript/vnc-pass-brute.yaml" , TestCase : & javascriptVncPassBrute {}},
20+ {Path : "protocols/javascript/postgres-pass-brute.yaml" , TestCase : & javascriptPostgresPassBrute {}, DisableOn : func () bool { return osutils .IsWindows () || osutils .IsOSX () }},
2021 {Path : "protocols/javascript/multi-ports.yaml" , TestCase : & javascriptMultiPortsSSH {}},
2122 {Path : "protocols/javascript/no-port-args.yaml" , TestCase : & javascriptNoPortArgs {}},
2223}
2324
2425var (
25- redisResource * dockertest.Resource
26- sshResource * dockertest.Resource
27- oracleResource * dockertest.Resource
28- vncResource * dockertest.Resource
29- pool * dockertest.Pool
30- defaultRetry = 3
26+ redisResource * dockertest.Resource
27+ sshResource * dockertest.Resource
28+ oracleResource * dockertest.Resource
29+ vncResource * dockertest.Resource
30+ postgresResource * dockertest.Resource
31+ pool * dockertest.Pool
32+ defaultRetry = 3
3133)
3234
3335type javascriptNetHttps struct {}
@@ -169,6 +171,38 @@ func (j *javascriptVncPassBrute) Execute(filePath string) error {
169171 return multierr .Combine (errs ... )
170172}
171173
174+ type javascriptPostgresPassBrute struct {}
175+
176+ func (j * javascriptPostgresPassBrute ) Execute (filePath string ) error {
177+ if postgresResource == nil || pool == nil {
178+ // skip test as postgres is not running
179+ return nil
180+ }
181+ tempPort := postgresResource .GetPort ("5432/tcp" )
182+ finalURL := "localhost:" + tempPort
183+ defer purge (postgresResource )
184+ errs := []error {}
185+ for i := 0 ; i < defaultRetry ; i ++ {
186+ results := []string {}
187+ var err error
188+ _ = pool .Retry (func () error {
189+ //let postgres server start
190+ time .Sleep (3 * time .Second )
191+ results , err = testutils .RunNucleiTemplateAndGetResults (filePath , finalURL , debug )
192+ return nil
193+ })
194+ if err != nil {
195+ return err
196+ }
197+ if err := expectResultsCount (results , 1 ); err == nil {
198+ return nil
199+ } else {
200+ errs = append (errs , err )
201+ }
202+ }
203+ return multierr .Combine (errs ... )
204+ }
205+
172206type javascriptMultiPortsSSH struct {}
173207
174208func (j * javascriptMultiPortsSSH ) Execute (filePath string ) error {
@@ -292,4 +326,23 @@ func init() {
292326 if err := vncResource .Expire (30 ); err != nil {
293327 log .Printf ("Could not expire resource: %s" , err )
294328 }
329+
330+ // setup a temporary postgres instance
331+ postgresResource , err = pool .RunWithOptions (& dockertest.RunOptions {
332+ Repository : "postgres" ,
333+ Tag : "latest" ,
334+ Env : []string {
335+ "POSTGRES_PASSWORD=postgres" ,
336+ "POSTGRES_USER=postgres" ,
337+ },
338+ Platform : "linux/amd64" ,
339+ })
340+ if err != nil {
341+ log .Printf ("Could not start postgres resource: %s" , err )
342+ return
343+ }
344+ // by default expire after 30 sec
345+ if err := postgresResource .Expire (30 ); err != nil {
346+ log .Printf ("Could not expire postgres resource: %s" , err )
347+ }
295348}
0 commit comments