78.4 Reset Password (#9)

This commit is contained in:
Art
2021-09-09 23:17:11 +03:00
parent e400f04a24
commit c399d1cf8d
2 changed files with 42 additions and 0 deletions

View File

@ -80,6 +80,17 @@ public class UserResource {
return userService.findAll();
}
@PostMapping("/resetPassword/{email}")
public HttpResponse resetPassword(@PathVariable String email) {
userService.resetPassword(email);
return HttpResponse.builder()
.httpStatusCode(OK.value())
.httpStatus(OK)
.reason(OK.getReasonPhrase())
.message("Password reset successfully. Check your email for new password")
.build();
}
private void authenticate(String username, String password) {
Authentication auth = new UsernamePasswordAuthenticationToken(username, password);
authenticationManager.authenticate(auth);

View File

@ -489,4 +489,35 @@ class UserResourceUnSecureTest extends BaseUserTest {
}
}
@Nested
class ResetPasswordTests {
@BeforeEach
void setUp() {
user = userRepository
.findAll()
.stream()
.findAny()
.orElseGet(() -> userRepository.save(createRandomUser()));
}
@Test
void resetPassword() {
//given
String email = user.getEmail();
//when
var responseEntity = restTemplate.exchange("/user/resetPassword/{email}", HttpMethod.POST, null, HttpResponse.class, email);
//then
log.debug("Response Entity: {}", responseEntity);
assertThat(responseEntity.getStatusCode()).isEqualTo(OK);
assertThat(responseEntity.getBody())
.isNotNull()
.hasNoNullFieldsOrProperties()
.hasFieldOrPropertyWithValue("httpStatus", OK)
.hasFieldOrPropertyWithValue("message", "Password reset successfully. Check your email for new password");
}
}
}