2525import org .springframework .boot .test .mock .mockito .SpyBean ;
2626import org .springframework .security .test .context .support .WithAnonymousUser ;
2727import org .springframework .test .web .servlet .MvcResult ;
28+ import org .webtree .mystuff .model .domain .AuthDetails ;
2829import org .webtree .mystuff .model .domain .Category ;
2930import org .webtree .mystuff .model .domain .Stuff ;
3031import org .webtree .mystuff .model .domain .User ;
@@ -141,11 +142,14 @@ public void whenDeleteStuff_shouldNotReturnItForUser() throws Exception {
141142 @ WithAnonymousUser
142143 public void whenAddExistingStuff_shouldReturnForBothUsers () throws Exception {
143144 Stuff stuff = stuffService .save (buildNewStuff (NAME , USER_1 ));
145+ AuthDetails authDetails = new AuthDetails ();
146+ authDetails .setUsername (USER_2 );
147+ authDetails .setPassword ("pass" );
144148 User user2 = userService .add (User .Builder .create ().withUsername (USER_2 ).withPassword ("pass" ).build ());
145149 MvcResult mvcResult = mockMvc .perform (
146150 post ("/rest/token/new" )
147151 .contentType (APPLICATION_JSON )
148- .content (objectMapper .writeValueAsString (user2 ))
152+ .content (objectMapper .writeValueAsString (authDetails ))
149153 )
150154 .andExpect (status ().isOk ())
151155 .andExpect (jsonPath ("$.errors" ).doesNotExist ())
@@ -243,6 +247,16 @@ public void whenAddExistingCategory_shouldReturnIt_andDonNotTryToCreate() throws
243247 verify (categoryService , never ()).save (any ());
244248 }
245249
250+ @ Test // bug #32
251+ public void whenGetStuff_shouldNotReturnUserPassword () throws Exception {
252+ Stuff stuff = stuffService .save (buildNewStuffWithStaffCategory (NAME , USER_1 , buildNewStaffCategories (CATEGORY1 )));
253+ mockMvc .perform (get ("/rest/stuff/" + stuff .getId ()).contentType (APPLICATION_JSON ))
254+ .andExpect (status ().isOk ())
255+ .andExpect (jsonPath ("$.creator" ).isNotEmpty ())
256+ .andExpect (jsonPath ("$.creator.username" ).value (USER_1 ))
257+ .andExpect (jsonPath ("$.creator.password" ).doesNotExist ());
258+ }
259+
246260 private Stuff buildNewStuff (String name , String username ) {
247261 return Stuff .Builder .create ().withUsers (buildNewUsers (username )).withName (name ).build ();
248262 }
@@ -263,12 +277,13 @@ private User addUser() {
263277 }
264278
265279 private Set <User > buildNewUsers (String username ) {
266- return Sets .newHashSet (userService .add (User .Builder .create ().withUsername (username ).build ()));
280+ return Sets .newHashSet (userService .add (User .Builder .create ().withUsername (username ).withPassword ( "qweasd" ). build ()));
267281 }
268282
269283
270284 private Stuff buildNewStuffWithStaffCategory (String name , String username , Set <Category > categories ) {
271- return Stuff .Builder .create ().withUsers (buildNewUsers (username )).withName (name )
285+ Set <User > users = buildNewUsers (username );
286+ return Stuff .Builder .create ().withCreator (users .iterator ().next ()).withUsers (users ).withName (name )
272287 .withCategories (categories ).build ();
273288 }
274289
0 commit comments