Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop' into OP-1189
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudFonzam committed Aug 20, 2024
2 parents 2f1f089 + 79e00e4 commit 741f9c8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/main/java/org/isf/menu/manager/UserBrowsingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
@Component
public class UserBrowsingManager {

private static final String VALID_USERID_PATTERN = "^[a-z0-9-._]+$";

private MenuIoOperations ioOperations;

public UserBrowsingManager(MenuIoOperations menuIoOperations) {
Expand Down Expand Up @@ -97,9 +99,13 @@ public User getUserByName(String userName) throws OHServiceException {
*/
public User newUser(User user) throws OHServiceException {
String username = user.getUserName();
if (!username.matches(VALID_USERID_PATTERN)) {
throw new OHDataValidationException(
new OHExceptionMessage(MessageBundle.getMessage("angal.userbrowser.theusernamecontainsinvalidcharacters.msg")));
}
if (ioOperations.isUserNamePresent(username)) {
throw new OHDataIntegrityViolationException(
new OHExceptionMessage(MessageBundle.formatMessage("angal.userbrowser.theuseralreadyexists.fmt.msg", username)));
new OHExceptionMessage(MessageBundle.formatMessage("angal.userbrowser.theuseralreadyexists.fmt.msg", username)));
}
return ioOperations.newUser(user);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/isf/menu/TestUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

public class TestUser {

private String name = "TestName";
private String name = "testname";
private String passwd = "TestPaswd";
private String desc = "TestDesc";

Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/isf/menu/TestUserBrowsingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package org.isf.menu;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.util.List;

Expand All @@ -35,6 +36,7 @@
import org.isf.menu.service.UserGroupIoOperationRepository;
import org.isf.menu.service.UserIoOperationRepository;
import org.isf.menu.service.UserMenuItemIoOperationRepository;
import org.isf.utils.exception.OHDataValidationException;
import org.isf.utils.exception.OHException;
import org.isf.utils.time.TimeTools;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -214,6 +216,17 @@ void testGetUserGroups() throws Exception {
assertThat(userGroupList.get(0).getCode()).isEqualTo("Z");
}

@Test
void testInvalidUserName() throws Exception {
assertThatThrownBy(() -> {
UserGroup userGroup = testUserGroup.setup(true);
User user = testUser.setup(userGroup, true);
user.setUserName("A@!");
userBrowsingManager.newUser(user);
})
.isInstanceOf(OHDataValidationException.class);
}

private String setupTestUser(boolean usingSet) throws OHException {
UserGroup userGroup = testUserGroup.setup(usingSet);
User user = testUser.setup(userGroup, usingSet);
Expand Down

0 comments on commit 741f9c8

Please sign in to comment.