FINERACT-2081: Update password policy

This commit is contained in:
leksinomi
2024-11-11 10:29:36 +01:00
committed by Arnold Gálovics
parent 975a176610
commit 832b84f574
19 changed files with 191 additions and 25 deletions
@@ -64,7 +64,7 @@ public class AuthenticationIntegrationTest {
AccountHelper accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
String username = Utils.uniqueRandomStringGenerator("user", 8);
UserHelper.createUser(this.requestSpec, this.responseSpec, 1, staffId, username, "P4ssw0rd", "resourceId");
UserHelper.createUser(this.requestSpec, this.responseSpec, 1, staffId, username, "A1b2c3d4e5f$", "resourceId");
Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
Integer loanProductID = setupLoanProduct(accountHelper);
@@ -65,7 +65,7 @@ public class ClientAuditingIntegrationTest {
public void checkAuditDates() throws InterruptedException {
final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
String username = Utils.uniqueRandomStringGenerator("user", 8);
final Integer userId = (Integer) UserHelper.createUser(this.requestSpec, this.responseSpec, 1, staffId, username, "password",
final Integer userId = (Integer) UserHelper.createUser(this.requestSpec, this.responseSpec, 1, staffId, username, "A1b2c3d4e5f$",
"resourceId");
OffsetDateTime now = Utils.getAuditDateTimeToCompare();
LOG.info("-------------------------Creating Client---------------------------");
@@ -88,7 +88,7 @@ public class ClientAuditingIntegrationTest {
LOG.info("-------------------------Modify Client with System user---------------------------");
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization",
"Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey(username, "password"));
"Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey(username, "A1b2c3d4e5f$"));
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
OffsetDateTime now2 = Utils.getAuditDateTimeToCompare();
@@ -79,7 +79,7 @@ public class LoanAuditingIntegrationTest {
public void checkAuditDates() throws InterruptedException {
final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
String username = Utils.uniqueRandomStringGenerator("user", 8);
final Integer userId = (Integer) UserHelper.createUser(this.requestSpec, this.responseSpec, 1, staffId, username, "P4ssw0rd",
final Integer userId = (Integer) UserHelper.createUser(this.requestSpec, this.responseSpec, 1, staffId, username, "A1b2c3d4e5f$",
"resourceId");
LOG.info("-------------------------Creating Client---------------------------");
@@ -119,7 +119,7 @@ public class LoanAuditingIntegrationTest {
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization",
"Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey(username, "P4ssw0rd"));
"Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey(username, "A1b2c3d4e5f$"));
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
OffsetDateTime now2 = Utils.getAuditDateTimeToCompare();
@@ -79,7 +79,7 @@ public class LoanTransactionAuditingIntegrationTest {
public void checkAuditDates() throws InterruptedException {
final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
String username = Utils.uniqueRandomStringGenerator("user", 8);
final Integer userId = (Integer) UserHelper.createUser(this.requestSpec, this.responseSpec, 1, staffId, username, "P4ssw0rd",
final Integer userId = (Integer) UserHelper.createUser(this.requestSpec, this.responseSpec, 1, staffId, username, "A1b2c3d4e5f$",
"resourceId");
LOG.info("-------------------------Creating Client---------------------------");
@@ -128,7 +128,7 @@ public class LoanTransactionAuditingIntegrationTest {
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization",
"Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey(username, "P4ssw0rd"));
"Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey(username, "A1b2c3d4e5f$"));
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
OffsetDateTime now2 = Utils.getAuditDateTimeToCompare();
@@ -69,7 +69,7 @@ public class LoanValidationIntegrationTest {
public void checkPrincipalErrors() {
final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
String username = Utils.uniqueRandomStringGenerator("user", 8);
UserHelper.createUser(this.requestSpec, this.responseSpec, 1, staffId, username, "P4ssw0rd", "resourceId");
UserHelper.createUser(this.requestSpec, this.responseSpec, 1, staffId, username, "A1b2c3d4e5f$", "resourceId");
LOG.info("-------------------------Creating Client---------------------------");
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
@@ -106,11 +106,11 @@ public class MakercheckerTest {
// create maker user
String maker = Utils.uniqueRandomStringGenerator("user", 8);
final Integer makerUserId = (Integer) UserHelper.createUser(this.requestSpec, this.responseSpec, roleId, staffId, maker,
"P4ssw0rd", "resourceId");
"A1b2c3d4e5f$", "resourceId");
// create client - maker-checker disabled
RequestSpecification makerRequestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build()
.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey(maker, "P4ssw0rd"));
.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey(maker, "A1b2c3d4e5f$"));
Integer clientId = ClientHelper.createClient(makerRequestSpec, this.responseSpec);
assertNotNull(clientId);
ClientHelper.verifyClientCreatedOnServer(requestSpec, this.responseSpec, clientId);
@@ -155,9 +155,9 @@ public class MakercheckerTest {
// create checker user
String checker = Utils.uniqueRandomStringGenerator("user", 8);
final Integer checkerUserId = (Integer) UserHelper.createUser(this.requestSpec, this.responseSpec, roleId, staffId, checker,
"P4ssw0rd", "resourceId");
"A1b2c3d4e5f$", "resourceId");
RequestSpecification checkerRequestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build()
.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey(checker, "P4ssw0rd"));
.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey(checker, "A1b2c3d4e5f$"));
// check by another checker user should succeed
HashMap<?, ?> response = MakercheckersHelper.approveMakerCheckerEntry(checkerRequestSpec, responseSpec, clientCommandId);
@@ -61,7 +61,8 @@ public class NotificationApiTest {
GetOfficesResponse headOffice = OfficeHelper.getHeadOffice(requestSpec, responseSpec);
String username = Utils.uniqueRandomStringGenerator("NotificationUser", 4);
String password = Utils.randomStringGenerator("aA1", 10); // prefix is to conform with the password rules
String password = Utils.randomStringGenerator("A1b2c3d4e5f$", 1); // prefix is to conform with the password
// rules
PostUsersRequest createUserRequest = new PostUsersRequest().username(username)
.firstname(Utils.randomStringGenerator("NotificationFN", 4)).lastname(Utils.randomStringGenerator("NotificationLN", 4))
.email("whatever@mifos.org").password(password).repeatPassword(password).sendPasswordToEmail(false)
@@ -30,6 +30,7 @@ import java.util.List;
import org.apache.fineract.integrationtests.common.CommonConstants;
import org.apache.fineract.integrationtests.common.PasswordPreferencesHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
@@ -42,6 +43,7 @@ public class PasswordPreferencesIntegrationTest {
private ResponseSpecification responseSpec;
private RequestSpecification requestSpec;
private ResponseSpecification generalResponseSpec;
private int originalPasswordPolicyId;
@BeforeEach
public void setUp() {
@@ -50,7 +52,12 @@ public class PasswordPreferencesIntegrationTest {
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.generalResponseSpec = new ResponseSpecBuilder().build();
originalPasswordPolicyId = PasswordPreferencesHelper.getActivePasswordPreference(requestSpec, responseSpec);
}
@AfterEach
void tearDown() {
PasswordPreferencesHelper.updatePasswordPreferences(requestSpec, responseSpec, Integer.toString(originalPasswordPolicyId));
}
@Test
@@ -19,6 +19,7 @@
package org.apache.fineract.integrationtests;
import com.google.gson.JsonObject;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.builder.ResponseSpecBuilder;
import io.restassured.http.ContentType;
@@ -185,7 +186,7 @@ public class UserAdministrationTest extends IntegrationTest {
public void testApplicationUserCanChangeOwnPassword() {
// Admin creates a new user with an empty role
Integer roleId = RolesHelper.createRole(requestSpec, responseSpec);
String originalPassword = "aA1qwerty56";
String originalPassword = "QwE!5rTy#9uP0";
String simpleUsername = Utils.uniqueRandomStringGenerator("NotificationUser", 4);
GetOfficesResponse headOffice = OfficeHelper.getHeadOffice(requestSpec, responseSpec);
PostUsersRequest createUserRequest = new PostUsersRequest().username(simpleUsername)
@@ -198,7 +199,7 @@ public class UserAdministrationTest extends IntegrationTest {
Assertions.assertNotNull(userId);
// User updates its own password
String updatedPassword = "aA1qwerty56!";
String updatedPassword = "QwE!5rTy#9uP0u";
PutUsersUserIdResponse putUsersUserIdResponse = ok(newFineract(simpleUsername, originalPassword).users.update26(userId,
new PutUsersUserIdRequest().password(updatedPassword).repeatPassword(updatedPassword)));
Assertions.assertNotNull(putUsersUserIdResponse.getResourceId());
@@ -218,7 +219,7 @@ public class UserAdministrationTest extends IntegrationTest {
public void testApplicationUserShallNotBeAbleToChangeItsOwnRoles() {
// Admin creates a new user with one role assigned
Integer roleId = RolesHelper.createRole(requestSpec, responseSpec);
String password = "aA1qwerty56";
String password = "QwE!5rTy#9uP0";
String simpleUsername = Utils.uniqueRandomStringGenerator("NotificationUser", 4);
GetOfficesResponse headOffice = OfficeHelper.getHeadOffice(requestSpec, responseSpec);
PostUsersRequest createUserRequest = new PostUsersRequest().username(simpleUsername)
@@ -243,4 +244,41 @@ public class UserAdministrationTest extends IntegrationTest {
Assertions.assertTrue(callFailedRuntimeException.getMessage().contains("not.enough.permission.to.update.fields"));
}
@Test
public void testUserCreationWithValidPassword() {
String validPassword = "Abcdef1#2$3%XYZ";
PostUsersRequest createUserRequest = UserHelper.buildUserRequest(responseSpec, requestSpec, validPassword);
PostUsersResponse userCreationResponse = UserHelper.createUser(requestSpec, responseSpec, createUserRequest);
Assertions.assertNotNull(userCreationResponse.getResourceId());
}
@Test
public void testUserCreationWithInvalidPasswords() {
Map<String, String> invalidPasswords = Map.ofEntries(Map.entry("TooShort", "Ab1#Xyz"), // Less than 12
// characters
Map.entry("NoUppercase", "abcdefg1#2$3%xyz"), // Missing uppercase letter
Map.entry("NoLowercase", "ABCDEFG1#2$3%XYZ"), // Missing lowercase letter
Map.entry("NoDigit", "Abcdefg#@$%XYZabc"), // Missing digit
Map.entry("NoSpecialChar", "Abcdefg123456XYZ"), // Missing special character
Map.entry("ContainsWhitespace", "Abcdefg1# 2$3%"), // Contains whitespace
Map.entry("RepeatedCharacters", "AAbbcc11##$$%%YY") // Contains repeated characters
);
this.responseSpec = new ResponseSpecBuilder().build();
invalidPasswords.forEach((description, password) -> {
PostUsersRequest createUserRequest = UserHelper.buildUserRequest(responseSpec, requestSpec, password);
JsonObject jsonResponse = UserHelper.createUserWithJsonResponse(requestSpec, responseSpec, createUserRequest);
Assertions.assertEquals("400", jsonResponse.get("httpStatusCode").getAsString(), "Expected HTTP 400 for: " + description);
Assertions.assertEquals("validation.msg.validation.errors.exist",
jsonResponse.get("userMessageGlobalisationCode").getAsString(), "Expected user message code for: " + description);
JsonObject errorDetails = jsonResponse.getAsJsonArray("errors").get(0).getAsJsonObject();
Assertions.assertEquals("password", errorDetails.get("parameterName").getAsString(),
"Expected validation error parameter name for: " + description);
Assertions.assertEquals("validation.msg.user.password.does.not.match.regexp",
errorDetails.get("userMessageGlobalisationCode").getAsString(), "Expected validation code for: " + description);
});
}
}
@@ -19,6 +19,8 @@
package org.apache.fineract.integrationtests.useradministration.users;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.path.json.JsonPath;
@@ -44,7 +46,7 @@ public final class UserHelper {
private static final String READ_LOAN_PERMISSION = "READ_LOAN";
public static final String SIMPLE_USER_NAME = Utils.uniqueRandomStringGenerator("NotificationUser", 4);
public static final String SIMPLE_USER_PASSWORD = "aA1qwerty56";
public static final String SIMPLE_USER_PASSWORD = "QwE!5rTy#9uP0";
private static boolean SIMPLE_USER_CREATED = false;
private UserHelper() {}
@@ -73,6 +75,13 @@ public final class UserHelper {
return GSON.fromJson(response, PostUsersResponse.class);
}
public static JsonObject createUserWithJsonResponse(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
PostUsersRequest request) {
String requestBody = GSON.toJson(request);
String jsonResponse = Utils.performServerPost(requestSpec, responseSpec, CREATE_USER_URL, requestBody);
return JsonParser.parseString(jsonResponse).getAsJsonObject();
}
public static Object createUserForSelfService(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
int roleId, int staffId, int clientId, String attribute) {
return Utils.performServerPost(requestSpec, responseSpec, CREATE_USER_URL,
@@ -161,6 +170,16 @@ public final class UserHelper {
return responseRequestSpec;
}
public static PostUsersRequest buildUserRequest(ResponseSpecification responseSpec, RequestSpecification requestSpec, String password) {
Integer roleId = RolesHelper.createRole(requestSpec, responseSpec);
String uniqueUsername = Utils.uniqueRandomStringGenerator("TestUser", 4);
GetOfficesResponse headOffice = OfficeHelper.getHeadOffice(requestSpec, responseSpec);
return new PostUsersRequest().username(uniqueUsername).firstname("Test").lastname("User").email("testuser@example.com")
.password(password).repeatPassword(password).sendPasswordToEmail(false).officeId(headOffice.getId())
.roles(List.of(roleId.longValue()));
}
private static String createSimpleRole(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
Integer roleId = RolesHelper.createRole(requestSpec, responseSpec);
addRepaymentPermissionToRole(requestSpec, responseSpec, roleId);