11package em .embedded .webgoat ;
22
3+ import org .evomaster .client .java .controller .AuthUtils ;
34import org .evomaster .client .java .controller .EmbeddedSutController ;
45import org .evomaster .client .java .controller .InstrumentedSutStarter ;
56import org .evomaster .client .java .controller .api .dto .auth .AuthenticationDto ;
67import org .evomaster .client .java .controller .api .dto .SutInfoDto ;
8+ import org .evomaster .client .java .controller .api .dto .database .schema .DatabaseType ;
79import org .evomaster .client .java .sql .DbSpecification ;
810import org .evomaster .client .java .controller .problem .ProblemInfo ;
911import org .evomaster .client .java .controller .problem .RestProblem ;
1012import org .owasp .webgoat .server .StartWebGoat ;
11- import org .springframework .boot .SpringApplication ;
1213import org .springframework .context .ConfigurableApplicationContext ;
14+ import java .sql .Connection ;
15+ import org .springframework .jdbc .core .JdbcTemplate ;
1316
14- import java .util .Collections ;
17+ import java .sql .SQLException ;
18+ import java .util .Arrays ;
1519import java .util .List ;
1620import java .util .Map ;
1721
@@ -36,6 +40,8 @@ public static void main(String[] args) {
3640
3741
3842 private ConfigurableApplicationContext ctx ;
43+ private Connection sqlConnection ;
44+ private List <DbSpecification > dbSpecification ;
3945
4046
4147 public EmbeddedEvoMasterController () {
@@ -53,12 +59,38 @@ public String startSut() {
5359
5460 app .main (new String []{
5561 "--server.port=0" ,
56- "--spring.profiles.active=dev"
62+ "--spring.profiles.active=dev" ,
63+ "--spring.datasource.driver-class-name=org.h2.Driver" ,
64+ "--spring.datasource.url=jdbc:h2:mem:testdb;INIT=CREATE SCHEMA IF NOT EXISTS CONTAINER;DB_CLOSE_DELAY=-1;" ,
65+ "--spring.jpa.database-platform=org.hibernate.dialect.H2Dialect" ,
66+ "--spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true" ,
67+ "--spring.datasource.username=sa" ,
68+ "--spring.datasource.password" ,
69+ "--spring.jpa.properties.jakarta.persistence.schema-generation.scripts.action=none" ,
70+ "--spring.sql.init.mode=never"
5771 });
5872
5973
6074 ctx = (ConfigurableApplicationContext ) app .getApplicationContext ();
6175
76+ if (sqlConnection != null ) {
77+ try {
78+ sqlConnection .close ();
79+ } catch (SQLException e ) {
80+ e .printStackTrace ();
81+ }
82+ }
83+ JdbcTemplate jdbc = ctx .getBean (JdbcTemplate .class );
84+
85+ try {
86+ sqlConnection = jdbc .getDataSource ().getConnection ();
87+ } catch (SQLException e ) {
88+ e .printStackTrace ();
89+ }
90+ dbSpecification = Arrays .asList (new DbSpecification (DatabaseType .H2 , sqlConnection )
91+ .withInitSqlOnResourcePath ("/data.sql" ));
92+
93+
6294 return "http://localhost:" + getSutPort ();
6395 }
6496
@@ -93,16 +125,21 @@ public void resetStateOfSUT() {
93125
94126 @ Override
95127 public List <DbSpecification > getDbSpecifications () {
96- return null ;
128+ return dbSpecification ;
97129 }
98130
99131
132+
100133 @ Override
101134 public List <AuthenticationDto > getInfoForAuthentication () {
102- return null ;
135+
136+ return Arrays .asList (
137+ AuthUtils .getForDefaultSpringFormLogin ("user1" , "testuser" , "testuser" , "/WebGoat/login" ),
138+ AuthUtils .getForDefaultSpringFormLogin ("user2" , "testuser2" , "testuser" , "/WebGoat/login" ));
103139 }
104140
105141
142+
106143 @ Override
107144 public ProblemInfo getProblemInfo () {
108145 return new RestProblem (
0 commit comments