Skip to content

Commit

Permalink
Merge pull request #98 from playkuround/fix/emailAuth
Browse files Browse the repository at this point in the history
Fix: �이메일 인증 버그 수정
  • Loading branch information
redcarrot1 authored Mar 27, 2024
2 parents ed3c609 + 65daf79 commit afa4472
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ public class AuthEmailApi {
private final AuthEmailVerifyService authEmailVerifyService;

@PostMapping
@Operation(summary = "인증메일 전송", description = "해당 메일로 알파벳 대소문자, 숫자 조합으로 이루어진 6자리의 인증 코드를 전송합니다. " +
@Operation(summary = "인증메일 전송", description = "해당 메일로 숫자 6자리의 인증 코드를 전송합니다. " +
"인증 메일 전송은 자정을 기준으로 최대 5번까지 가능합니다. 또한 인증 유효시간은 5분입니다.")
public ApiResponse<AuthEmailSendResponse> authEmailSend(@RequestBody @Valid AuthEmailSendRequest requestDto) {
AuthEmailInfo authEmailInfo = authEmailSendService.sendAuthEmail(requestDto.getTarget());
AuthEmailInfo authEmailInfo = authEmailSendService.sendAuthEmail(requestDto.getTarget().toLowerCase());
return ApiUtils.success(AuthEmailSendResponse.from(authEmailInfo));
}

@GetMapping
@Operation(summary = "인증 코드 확인", description = "인증 코드를 확인합니다. 인증 코드는 메일 전송 후 5분간 유효합니다.")
public ApiResponse<AuthVerifyEmailResponse> authEmailVerify(@RequestParam("code") String code,
@RequestParam("email") String email) {
AuthVerifyEmailResult authVerifyEmailResult = authEmailVerifyService.verifyAuthEmail(code, email);
AuthVerifyEmailResult authVerifyEmailResult = authEmailVerifyService.verifyAuthEmail(code, email.toLowerCase());
return ApiUtils.success(AuthVerifyEmailResponse.from(authVerifyEmailResult));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,26 @@ void failSendAuthEmailByLimitExceed() throws Exception {
.andDo(print());
}

@Test
@DisplayName("메일은 대소문자를 구분하지 않는다.")
void authEmail() throws Exception {
// given
AuthEmailSendRequest attendanceRegisterRequest = new AuthEmailSendRequest("TeSt@kOnkUk.aC.Kr");
String request = objectMapper.writeValueAsString(attendanceRegisterRequest);

// expected
mockMvc.perform(post("/api/auth/emails")
.contentType(MediaType.APPLICATION_JSON)
.content(request)
)
.andExpect(status().isOk())
.andExpect(jsonPath("$.isSuccess").value(true))
.andExpect(jsonPath("$.response.sendingCount").value(1))
.andDo(print());

List<AuthEmail> authEmails = authEmailRepository.findAll();
assertThat(authEmails).hasSize(1);
assertThat(authEmails.get(0).getTarget()).isEqualTo("test@konkuk.ac.kr");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ void authEmailVerifySuccessExistsUser() throws Exception {
@DisplayName("이메일 인증 성공 : 신규회원")
void authEmailVerifySuccessNewUser() throws Exception {
// given
AuthEmail authEmail = AuthEmail.createAuthEmail("newUserEmail", "code", LocalDateTime.now().plusMinutes(5));
AuthEmail authEmail = AuthEmail.createAuthEmail("user@test.com", "code", LocalDateTime.now().plusMinutes(5));
authEmailRepository.save(authEmail);

// expected
MvcResult mvcResult = mockMvc.perform(get("/api/auth/emails")
.param("email", "newUserEmail")
.param("email", "user@test.com")
.param("code", "code")
)
.andExpect(status().isOk())
Expand Down

0 comments on commit afa4472

Please sign in to comment.