Skip to content

Commit

Permalink
hotfix: 이메일 정규식에 언더스코어를 허용하도록 수정 (#205)
Browse files Browse the repository at this point in the history
* fix: 언더스코어 허용하도록 변경

* refactor: 테스트 접근제어자 제거
  • Loading branch information
uwoobeat authored Feb 28, 2024
1 parent a07fd3c commit 30346c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ public class RegexConstant {
public static final String PHONE_WITHOUT_HYPHEN = "^010[0-9]{8}$";
public static final String NICKNAME = "[ㄱ-ㅣ가-힣]{1,6}$";
public static final String DEPARTMENT = "^D[0-9]{3}$";

public static final String HONGIK_EMAIL = "^[^\\W&=_'-+,<>]+(\\.[^\\W&=_'-+,<>]+)*@g\\.hongik\\.ac\\.kr$";
public static final String HONGIK_EMAIL = "^[^\\W&=+'-+,<>]+(\\.[^\\W&=+'-+,<>]+)*@g\\.hongik\\.ac\\.kr$";

private RegexConstant() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

@SpringBootTest
@ActiveProfiles("test")
public class HongikUnivEmailValidatorTest {
class HongikUnivEmailValidatorTest {

@Autowired
private HongikUnivEmailValidator hongikUnivEmailValidator;

@Test
@DisplayName("'g.hongik.ac.kr' 도메인을 가진 이메일을 검증할 수 있다.")
public void validateEmailDomainTest() {
void validateEmailDomainTest() {
String hongikDomainEmail = "[email protected]";

assertThatCode(() -> hongikUnivEmailValidator.validate(hongikDomainEmail))
Expand All @@ -33,15 +33,15 @@ public void validateEmailDomainTest() {
@ParameterizedTest
@ValueSource(strings = {"[email protected]", "[email protected]", "[email protected]", "[email protected]"})
@DisplayName("'g.hongik.ac.kr'가 아닌 도메인을 가진 이메일을 입력하면 예외를 발생시킨다.")
public void validateEmailDomainMismatchTest(String email) {
void validateEmailDomainMismatchTest(String email) {
assertThatThrownBy(() -> hongikUnivEmailValidator.validate(email))
.isInstanceOf(CustomException.class)
.hasMessage(ErrorCode.UNIV_EMAIL_DOMAIN_MISMATCH.getMessage());
}

@Test
@DisplayName("Email의 '@' 앞 부분에는 연속되지 않은 점이 포함될 수 있다.")
public void validateEmailFormatWithDotsTest() {
void validateEmailFormatWithDotsTest() {
String email = "[email protected]";

assertThatCode(() -> hongikUnivEmailValidator.validate(email)).doesNotThrowAnyException();
Expand All @@ -52,24 +52,23 @@ public void validateEmailFormatWithDotsTest() {
strings = {
"te&[email protected]",
"[email protected]",
"[email protected]",
"te'[email protected]",
"[email protected]",
"[email protected]",
"te,[email protected]",
"te<[email protected]",
"te>[email protected]"
})
@DisplayName("Email의 '@' 앞 부분에 '&', '=', '_', ''', '-', '+', ',', '<', '>'가 포함되는 경우 예외를 발생시킨다.")
public void validateEmailFormatMismatchTest(String email) {
@DisplayName("Email의 '@' 앞 부분에 '&', '=', ''', '-', '+', ',', '<', '>'가 포함되는 경우 예외를 발생시킨다.")
void validateEmailFormatMismatchTest(String email) {
assertThatThrownBy(() -> hongikUnivEmailValidator.validate(email))
.isInstanceOf(CustomException.class)
.hasMessage(ErrorCode.UNIV_EMAIL_FORMAT_MISMATCH.getMessage());
}

@Test
@DisplayName("Email의 '@' 앞 부분에 '.'이 2개 연속 오는 경우 예외를 발생시킨다.")
public void validateEmailFormatMismatchWithDotsTest() {
void validateEmailFormatMismatchWithDotsTest() {
String email = "[email protected]";
assertThatThrownBy(() -> hongikUnivEmailValidator.validate(email))
.isInstanceOf(CustomException.class)
Expand Down

0 comments on commit 30346c7

Please sign in to comment.