55import com .mongodb .client .MongoCollection ;
66import org .bson .Document ;
77import org .bson .types .ObjectId ;
8- import org .evomaster .client .java .controller .AuthUtils ;
98import org .evomaster .client .java .controller .EmbeddedSutController ;
109import org .evomaster .client .java .controller .InstrumentedSutStarter ;
1110import org .evomaster .client .java .controller .api .dto .AuthenticationDto ;
@@ -54,18 +53,18 @@ public static void main(String[] args) {
5453 private static final String MONGODB_DATABASE_NAME = "reservations-api" ;
5554
5655 // docker run -p 27017:27017 -e MONGODB_REPLICA_SET_MODE=primary -e ALLOW_EMPTY_PASSWORD=yes bitnami/mongodb:4.4
57- // /bitnami/mongodb
5856 // https://hub.docker.com/r/bitnami/mongodb
57+ // cannot use standard Mongo image, due ridiculous handling of transaction that requires a cluster...
5958
6059 private static final GenericContainer mongodbContainer = new GenericContainer ("bitnami/mongodb:" + MONGODB_VERSION )
6160 .withTmpFs (Collections .singletonMap ("/bitnami/mongodb" , "rw" ))
62- .withEnv ("MONGODB_REPLICA_SET_MODE" ,"primary" )
63- .withEnv ("ALLOW_EMPTY_PASSWORD" ,"yes" )
61+ .withEnv ("MONGODB_REPLICA_SET_MODE" , "primary" )
62+ .withEnv ("ALLOW_EMPTY_PASSWORD" , "yes" )
6463 .withExposedPorts (MONGODB_PORT );
6564
66- // private static final GenericContainer mongodbContainer = new GenericContainer("mongo:" + MONGODB_VERSION)
67- // .withTmpFs(Collections.singletonMap("/data/db", "rw"))
68- // .withExposedPorts(MONGODB_PORT) ;
65+
66+ private static final String rawPassword = "bar123" ;
67+ private static final String hashedPassword = "$2a$10$nEDY5j731yXGnQHyM39PWurJWr1FukegmKYYarK5WOoAMmgDs6D3u" ;
6968
7069 private String mongoDbUrl ;
7170
@@ -87,13 +86,10 @@ public String startSut() {
8786 mongoDbUrl = "mongodb://" + mongodbContainer .getContainerIpAddress () + ":" + mongodbContainer .getMappedPort (MONGODB_PORT ) + "/" + MONGODB_DATABASE_NAME ;
8887 mongoClient = MongoClients .create (mongoDbUrl );
8988
90- //from command line:
91- //--databaseUrl=mongodb://localhost:27017/Reservations --app.jwt.secret=abcdef0123456789
92-
9389 ctx = SpringApplication .run (ReservationsApi .class ,
9490 new String []{"--server.port=0" ,
95- "--databaseUrl=" + mongoDbUrl ,
96- "--spring.data.mongodb.uri=" + mongoDbUrl ,
91+ "--databaseUrl=" + mongoDbUrl ,
92+ "--spring.data.mongodb.uri=" + mongoDbUrl ,
9793 "--spring.cache.type=NONE" ,
9894 "--app.jwt.secret=abcdef012345678901234567890123456789abcdef012345678901234567890123456789"
9995 });
@@ -131,7 +127,6 @@ public void resetStateOfSUT() {
131127 mongoClient .getDatabase (MONGODB_DATABASE_NAME ).drop ();
132128
133129
134-
135130 // "bar123"
136131 // YmFyMTIz
137132 // $2a$10$b/SjlT3jexPDGci3EtmzpOnYwmjXrtzCQq5dn8rbMCgz7UZ/saylm
@@ -144,22 +139,21 @@ public void resetStateOfSUT() {
144139 .append ("_class" , "sk.cyrilgavala.reservationsApi.model.User" )
145140 .append ("username" , "foo" )
146141 .append ("email" , "foo@foo.com" )
147- .append ("password" , "$2a$10$b/SjlT3jexPDGci3EtmzpOnYwmjXrtzCQq5dn8rbMCgz7UZ/saylm" )
142+ .append ("password" , hashedPassword )
148143 .append ("role" , "USER" ),
149144 new Document ()
150145 .append ("_id" , new ObjectId ())
151146 .append ("_class" , "sk.cyrilgavala.reservationsApi.model.User" )
152147 .append ("username" , "bar" )
153148 .append ("email" , "bar@foo.com" )
154- .append ("password" , "$2a$10$b/SjlT3jexPDGci3EtmzpOnYwmjXrtzCQq5dn8rbMCgz7UZ/saylm" )
149+ .append ("password" , hashedPassword )
155150 .append ("role" , "USER" ),
156151 new Document ()
157152 .append ("_id" , new ObjectId ())
158153 .append ("_class" , "sk.cyrilgavala.reservationsApi.model.User" )
159154 .append ("username" , "admin" )
160155 .append ("email" , "admin@foo.com" )
161- .append ("password" ,"$2a$10$nEDY5j731yXGnQHyM39PWurJWr1FukegmKYYarK5WOoAMmgDs6D3u" )
162- //.append("password", "$2a$10$b/SjlT3jexPDGci3EtmzpOnYwmjXrtzCQq5dn8rbMCgz7UZ/saylm")
156+ .append ("password" , hashedPassword )
163157 .append ("role" , "ADMIN" )
164158 ));
165159
@@ -176,22 +170,40 @@ public List<DbSpecification> getDbSpecifications() {
176170 public List <AuthenticationDto > getInfoForAuthentication () {
177171
178172 return Arrays .asList (
179- new AuthenticationDto () {{
180- name = "admin" ;
181- jsonTokenPostLogin = new JsonTokenPostLoginDto (){{
182- userId = "admin" ;
183- endpoint ="/api/user/login" ;
184- jsonPayload = "{\" username\" :\" admin\" , \" password\" :\" bar123\" }" ;
185- extractTokenField ="/accessToken" ;
186- headerPrefix = "Bearer " ;
187- }};
173+ new AuthenticationDto () {{
174+ name = "admin" ;
175+ jsonTokenPostLogin = new JsonTokenPostLoginDto () {{
176+ userId = "admin" ;
177+ endpoint = "/api/user/login" ;
178+ jsonPayload = "{\" username\" :\" admin\" , \" password\" :\" " +rawPassword +"\" }" ;
179+ extractTokenField = "/accessToken" ;
180+ headerPrefix = "Bearer " ;
181+ }};
182+ }},
183+ new AuthenticationDto () {{
184+ name = "foo" ;
185+ jsonTokenPostLogin = new JsonTokenPostLoginDto () {{
186+ userId = "foo" ;
187+ endpoint = "/api/user/login" ;
188+ jsonPayload = "{\" username\" :\" foo\" , \" password\" :\" " +rawPassword +"\" }" ;
189+ extractTokenField = "/accessToken" ;
190+ headerPrefix = "Bearer " ;
191+ }};
192+ }},
193+ new AuthenticationDto () {{
194+ name = "bar" ;
195+ jsonTokenPostLogin = new JsonTokenPostLoginDto () {{
196+ userId = "bar" ;
197+ endpoint = "/api/user/login" ;
198+ jsonPayload = "{\" username\" :\" bar\" , \" password\" :\" " +rawPassword +"\" }" ;
199+ extractTokenField = "/accessToken" ;
200+ headerPrefix = "Bearer " ;
201+ }};
188202 }}
189203 );
190204 }
191205
192206
193-
194-
195207 @ Override
196208 public ProblemInfo getProblemInfo () {
197209 return new RestProblem (
@@ -206,6 +218,8 @@ public SutInfoDto.OutputFormat getPreferredOutputFormat() {
206218 }
207219
208220 @ Override
209- public Object getMongoConnection () {return mongoClient ;}
221+ public Object getMongoConnection () {
222+ return mongoClient ;
223+ }
210224
211225}
0 commit comments