78.4 Reset Password (#9)
This commit is contained in:
@ -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);
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user