Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: 이메일 인증 버그 수정 #98

Merged
merged 4 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("[email protected]");
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("[email protected]");
}

}
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("[email protected]", "code", LocalDateTime.now().plusMinutes(5));
authEmailRepository.save(authEmail);

// expected
MvcResult mvcResult = mockMvc.perform(get("/api/auth/emails")
.param("email", "newUserEmail")
.param("email", "[email protected]")
.param("code", "code")
)
.andExpect(status().isOk())
Expand Down
Loading