Add tests for the Change Password Endpoints

This commit is contained in:
Mohamed Karray
2018-09-19 15:54:24 +02:00
parent 2187b95ef8
commit 5c64c52a31
30 changed files with 1229 additions and 380 deletions

View File

@@ -0,0 +1,9 @@
package sonia.scm.user;
public class ChangePasswordNotAllowedException extends RuntimeException {
public ChangePasswordNotAllowedException(String message) {
super(message);
}
}

View File

@@ -0,0 +1,8 @@
package sonia.scm.user;
public class InvalidPasswordException extends RuntimeException {
public InvalidPasswordException(String message) {
super(message);
}
}

View File

@@ -38,6 +38,9 @@ package sonia.scm.user;
import sonia.scm.Manager;
import sonia.scm.search.Searchable;
import java.text.MessageFormat;
import java.util.function.Consumer;
/**
* The central class for managing {@link User} objects.
* This class is a singleton and is available via injection.
@@ -68,4 +71,22 @@ public interface UserManager
* @since 1.14
*/
public String getDefaultType();
/**
* Only account of the default type "xml" can change their password
*/
default Consumer<User> getUserTypeChecker() {
return user -> {
if (!isTypeDefault(user)) {
throw new ChangePasswordNotAllowedException(MessageFormat.format("It is not possible to change password for User of type {0}", user.getType()));
}
};
}
default boolean isTypeDefault(User user) {
return getDefaultType().equals(user.getType());
}
}