@@ -18,6 +18,7 @@ var jsTestcases = []TestCaseInfo{
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 {}},
2020 {Path : "protocols/javascript/postgres-pass-brute.yaml" , TestCase : & javascriptPostgresPassBrute {}, DisableOn : func () bool { return osutils .IsWindows () || osutils .IsOSX () }},
21+ {Path : "protocols/javascript/mysql-connect.yaml" , TestCase : & javascriptMySQLConnect {}, DisableOn : func () bool { return osutils .IsWindows () || osutils .IsOSX () }},
2122 {Path : "protocols/javascript/multi-ports.yaml" , TestCase : & javascriptMultiPortsSSH {}},
2223 {Path : "protocols/javascript/no-port-args.yaml" , TestCase : & javascriptNoPortArgs {}},
2324}
2829 oracleResource * dockertest.Resource
2930 vncResource * dockertest.Resource
3031 postgresResource * dockertest.Resource
32+ mysqlResource * dockertest.Resource
3133 pool * dockertest.Pool
3234 defaultRetry = 3
3335)
@@ -203,6 +205,38 @@ func (j *javascriptPostgresPassBrute) Execute(filePath string) error {
203205 return multierr .Combine (errs ... )
204206}
205207
208+ type javascriptMySQLConnect struct {}
209+
210+ func (j * javascriptMySQLConnect ) Execute (filePath string ) error {
211+ if mysqlResource == nil || pool == nil {
212+ // skip test as mysql is not running
213+ return nil
214+ }
215+ tempPort := mysqlResource .GetPort ("3306/tcp" )
216+ finalURL := "localhost:" + tempPort
217+ defer purge (mysqlResource )
218+ errs := []error {}
219+ for i := 0 ; i < defaultRetry ; i ++ {
220+ results := []string {}
221+ var err error
222+ _ = pool .Retry (func () error {
223+ //let mysql server start
224+ time .Sleep (5 * time .Second )
225+ results , err = testutils .RunNucleiTemplateAndGetResults (filePath , finalURL , debug )
226+ return nil
227+ })
228+ if err != nil {
229+ return err
230+ }
231+ if err := expectResultsCount (results , 1 ); err == nil {
232+ return nil
233+ } else {
234+ errs = append (errs , err )
235+ }
236+ }
237+ return multierr .Combine (errs ... )
238+ }
239+
206240type javascriptMultiPortsSSH struct {}
207241
208242func (j * javascriptMultiPortsSSH ) Execute (filePath string ) error {
@@ -345,4 +379,22 @@ func init() {
345379 if err := postgresResource .Expire (30 ); err != nil {
346380 log .Printf ("Could not expire postgres resource: %s" , err )
347381 }
382+
383+ // setup a temporary mysql instance
384+ mysqlResource , err = pool .RunWithOptions (& dockertest.RunOptions {
385+ Repository : "mysql" ,
386+ Tag : "latest" ,
387+ Env : []string {
388+ "MYSQL_ROOT_PASSWORD=secret" ,
389+ },
390+ Platform : "linux/amd64" ,
391+ })
392+ if err != nil {
393+ log .Printf ("Could not start mysql resource: %s" , err )
394+ return
395+ }
396+ // by default expire after 30 sec
397+ if err := mysqlResource .Expire (30 ); err != nil {
398+ log .Printf ("Could not expire mysql resource: %s" , err )
399+ }
348400}
0 commit comments