diff --git a/src/main/java/org/ays/common/util/validation/NameValidator.java b/src/main/java/org/ays/common/util/validation/NameValidator.java index 870034d9..61dc209e 100644 --- a/src/main/java/org/ays/common/util/validation/NameValidator.java +++ b/src/main/java/org/ays/common/util/validation/NameValidator.java @@ -23,7 +23,7 @@ class NameValidator implements ConstraintValidator { * It also avoids strings that start with special characters *

*/ - private static final String NAME_REGEX = "^(?![^a-zA-ZÇçĞğİıÖöŞşÜü])[a-zA-ZÇçĞğİıÖöŞşÜü ,.'-]*$"; + private static final String NAME_REGEX = "^(?!.*[ ,.'-]{2})[a-zA-ZÇçĞğİıÖöŞşÜü]+(?:[ ,.'-](?![ ,.'-])[a-zA-ZÇçĞğİıÖöŞşÜü]+)*$"; /** * Checks whether the given value is a valid name or not. diff --git a/src/test/java/org/ays/auth/controller/AdminRegistrationApplicationControllerTest.java b/src/test/java/org/ays/auth/controller/AdminRegistrationApplicationControllerTest.java index 9eeae345..fdbae7f7 100644 --- a/src/test/java/org/ays/auth/controller/AdminRegistrationApplicationControllerTest.java +++ b/src/test/java/org/ays/auth/controller/AdminRegistrationApplicationControllerTest.java @@ -518,7 +518,10 @@ void givenPhoneNumberWithInvalidOperator_whenPhoneNumberIsNotValid_thenReturnVal "John *^%$#", " John", "? John", - "J" + "J", + "J----", + "City--King", + "John Doe" }) void givenInvalidAdminRegisterApplicationCompleteRequestWithParametrizedInvalidNames_whenNamesAreNotValid_thenReturnValidationError(String invalidName) throws Exception { diff --git a/src/test/java/org/ays/auth/controller/AysRoleControllerTest.java b/src/test/java/org/ays/auth/controller/AysRoleControllerTest.java index 29b5228a..53d4ccce 100644 --- a/src/test/java/org/ays/auth/controller/AysRoleControllerTest.java +++ b/src/test/java/org/ays/auth/controller/AysRoleControllerTest.java @@ -147,7 +147,10 @@ void givenValidRoleListRequest_whenRolesFound_thenReturnAysPageResponseOfRolesRe "Role *^%$#", " Test", "? Role", - "J" + "J", + "J----", + "City--King", + "John Doe" }) void givenRoleListRequest_whenNameDoesNotValid_thenReturnValidationError(String invalidName) throws Exception { @@ -383,6 +386,9 @@ void givenValidRoleCreateRequest_whenUserUnauthorized_thenReturnAccessDeniedExce " Kurum yöneticisi", "!Kurum", "12Kurum", + "J----", + "City--King", + "John Doe", "A", "% fsdh ", "493268349068342", @@ -591,6 +597,9 @@ void givenInvalidIdAndValidRoleUpdateRequest_whenIdNotValid_thenReturnValidation " Role", "Role ", "123Role", + "J----", + "City--King", + "John Doe", ".Role", "% fsdh ", "493268349068342", diff --git a/src/test/java/org/ays/auth/controller/AysUserControllerTest.java b/src/test/java/org/ays/auth/controller/AysUserControllerTest.java index db98a0e2..921e8d8a 100644 --- a/src/test/java/org/ays/auth/controller/AysUserControllerTest.java +++ b/src/test/java/org/ays/auth/controller/AysUserControllerTest.java @@ -109,7 +109,10 @@ void givenValidUserListRequest_whenUsersFound_thenReturnAysPageResponseOfUsersRe "User *^%$#", " Test", "? User", - "J" + "J", + "J----", + "Martin-Luther--King", + "John Doe" }) void givenUserListRequest_whenFirstNameDoesNotValid_thenReturnValidationError(String invalidName) throws Exception { @@ -144,7 +147,10 @@ void givenUserListRequest_whenFirstNameDoesNotValid_thenReturnValidationError(St "User *^%$#", " Test", "? User", - "J" + "J", + "J----", + "Martin-Luther--King", + "John Doe" }) void givenUserListRequest_whenLastNameDoesNotValid_thenReturnValidationError(String invalidName) throws Exception { @@ -178,7 +184,10 @@ void givenUserListRequest_whenLastNameDoesNotValid_thenReturnValidationError(Str "City *^%$#", " Test", "? User", - "J" + "J", + "J----", + "City--King", + "John Doe" }) void givenUserListRequest_whenCityDoesNotValid_thenReturnValidationError(String invalidName) throws Exception { diff --git a/src/test/java/org/ays/emergency_application/controller/EmergencyEvacuationApplicationControllerTest.java b/src/test/java/org/ays/emergency_application/controller/EmergencyEvacuationApplicationControllerTest.java index bf0f92c2..93a5cbd4 100644 --- a/src/test/java/org/ays/emergency_application/controller/EmergencyEvacuationApplicationControllerTest.java +++ b/src/test/java/org/ays/emergency_application/controller/EmergencyEvacuationApplicationControllerTest.java @@ -390,6 +390,9 @@ void givenEmergencyEvacuationApplicationId_whenUnauthorizedForGettingEmergencyEv @ValueSource(strings = { "Invalid with special characters: #$%", ".,..,.,.,.,.,,.,.,.,.,.,.,.,.,..,.,.,,.,.,.,", + "J----", + "City--King", + "John Doe", "t", " a", "151201485621548562154851458614125461254125412", @@ -510,6 +513,9 @@ void givenInvalidEmergencyEvacuationApplicationRequest_whenPhoneNumbersAreSameOn "Invalid with special characters: #$%", "#$½#$£#$£#$$#½#£$£#$#£½#$½#$½$£#$#£$$#½#$$½", ".,..,.,.,.,.,,.,.,.,.,.,.,.,.,..,.,.,,.,.,.,", + "J----", + "City--King", + "John Doe", "t", " a", "151201485621548562154851458614125461254125412", @@ -545,6 +551,9 @@ void givenInvalidEmergencyEvacuationApplicationRequest_whenFirstNameIsNotValid_t "Invalid with special characters: #$%", "#$½#$£#$£#$$#½#£$£#$#£½#$½#$½$£#$#£$$#½#$$½", ".,..,.,.,.,.,,.,.,.,.,.,.,.,.,..,.,.,,.,.,.,", + "J----", + "City--King", + "John Doe", "t", " a", "151201485621548562154851458614125461254125412", @@ -817,6 +826,9 @@ void givenInvalidEmergencyEvacuationApplicationRequest_whenTargetDistrictIsNotVa "#$½#$£#$£#$$#½#£$£#$#£½#$½#$½$£#$#£$$#½#$$½", ".,..,.,.,.,.,,.,.,.,.,.,.,.,.,..,.,.,,.,.,.,", "t", + "J----", + "City--King", + "John Doe", " a", "151201485621548562154851458614125461254125412", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam In hac habitasse platea dictumst. Nullam in turpis at nunc ultrices.", @@ -852,6 +864,9 @@ void givenInvalidEmergencyEvacuationApplicationRequest_whenApplicantFirstNameIsN "#$½#$£#$£#$$#½#£$£#$#£½#$½#$½$£#$#£$$#½#$$½", ".,..,.,.,.,.,,.,.,.,.,.,.,.,.,..,.,.,,.,.,.,", "t", + "J----", + "City--King", + "John Doe", " a", "151201485621548562154851458614125461254125412", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam In hac habitasse platea dictumst. Nullam in turpis at nunc ultrices.",