This commit is contained in:
@@ -93,21 +93,21 @@ public class AuthentificationServiceTest {
|
||||
|
||||
@Test
|
||||
public void testPasswordResetWithWrongOTP() {
|
||||
// Registriere einen echten User
|
||||
|
||||
User user = validUser();
|
||||
authenticationService.registerUser(getUserRegistrationDTO(user));
|
||||
String email = user.getEmail();
|
||||
String oldPassword = user.getPassword();
|
||||
assertTrue(userRepository.findByEmail(email).isPresent());
|
||||
|
||||
// User existiert und hat Token angefordert
|
||||
|
||||
authenticationService.generateNewPasswordResetTokenForUser(user.getEmail());
|
||||
ArgumentCaptor<String> otpCaptor = ArgumentCaptor.forClass(String.class);
|
||||
verify(emailService, times(1)).sendPasswordResetEmail(eq(email), otpCaptor.capture());
|
||||
String sentOtp = otpCaptor.getValue();
|
||||
|
||||
String wrongOtpCode = Objects.equals(sentOtp, "000000") ? "000000" : "100000";
|
||||
// WHEN & THEN: Reset mit falschem Code (z.B. "000000")
|
||||
String wrongOtpCode = Objects.equals(sentOtp, "000000") ? "100000" : "00000";
|
||||
|
||||
PasswordResetDTO wrongDto = new PasswordResetDTO(wrongOtpCode, user.getEmail(), "PWPWPWPW");
|
||||
|
||||
assertThrows(InvalidTokenException.class, () -> {
|
||||
@@ -121,7 +121,6 @@ public class AuthentificationServiceTest {
|
||||
User user = validUser();
|
||||
authenticationService.registerUser(getUserRegistrationDTO(user));
|
||||
String email = user.getEmail();
|
||||
String oldPassword = user.getPassword();
|
||||
assertTrue(userRepository.findByEmail(email).isPresent());
|
||||
|
||||
// User existiert und hat Token angefordert
|
||||
@@ -130,7 +129,6 @@ public class AuthentificationServiceTest {
|
||||
verify(emailService, times(1)).sendPasswordResetEmail(eq(email), otpCaptor.capture());
|
||||
String sentOtp = otpCaptor.getValue();
|
||||
|
||||
// WHEN & THEN: Reset mit falscher email
|
||||
PasswordResetDTO wrongDto = new PasswordResetDTO(sentOtp, "wrongEmail@test.de", "PWPWPWPW");
|
||||
|
||||
assertThrows(InvalidTokenException.class, () -> {
|
||||
@@ -144,7 +142,6 @@ public class AuthentificationServiceTest {
|
||||
User user = validUser();
|
||||
authenticationService.registerUser(getUserRegistrationDTO(user));
|
||||
String email = user.getEmail();
|
||||
String oldPassword = user.getPassword();
|
||||
assertTrue(userRepository.findByEmail(email).isPresent());
|
||||
|
||||
// User existiert und hat Token angefordert
|
||||
@@ -153,7 +150,6 @@ public class AuthentificationServiceTest {
|
||||
verify(emailService, times(1)).sendPasswordResetEmail(eq(email), otpCaptor.capture());
|
||||
String sentOtp = otpCaptor.getValue();
|
||||
|
||||
// WHEN & THEN: Reset mit falscher email
|
||||
PasswordResetDTO wrongDto = new PasswordResetDTO(sentOtp, user.getEmail(), "newPw");
|
||||
|
||||
assertThrows(InvalidTokenException.class, () -> {
|
||||
|
||||
Reference in New Issue
Block a user