Skip to content

Commit 517cdf0

Browse files
committed
feat: 로컬용 FakePhoneAuthenticator 추가
1 parent b1b38d5 commit 517cdf0

File tree

10 files changed

+50
-18
lines changed

10 files changed

+50
-18
lines changed

.github/workflows/deploy.yml

+1
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ jobs:
3333
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
3434
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} .
3535
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}
36+

docker-compose.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ services:
1919
spring:
2020
depends_on:
2121
- db
22-
build: .
22+
image: hjaehyun25/busan-reservation:latest
2323
ports:
2424
- '8080:8080'
25+
restart: on-failure
2526
environment:
27+
SPRING_PROFILES_ACTIVE: default
2628
SPRING_DATASOURCE_URL: jdbc:mysql://busan_db:3306/busan
2729
SPRING_DATASOURCE_USERNAME: root
2830
SPRING_DATASOURCE_PASSWORD: password

src/main/java/com/example/busan/auth/AuthController.java

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.example.busan.auth.dto.AuthenticatePhoneRequest;
44
import com.example.busan.auth.dto.Authentication;
55
import com.example.busan.auth.dto.FindEmailRequest;
6+
import com.example.busan.auth.dto.FindEmailResponse;
67
import com.example.busan.auth.dto.LoginRequest;
78
import com.example.busan.auth.service.AuthService;
89
import com.example.busan.auth.service.PhoneAuthenticator;

src/main/java/com/example/busan/auth/config/PhoneAuthenticatorConfig.java

+36-2
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,54 @@
11
package com.example.busan.auth.config;
22

3+
import com.example.busan.auth.domain.AuthorizationCodeGenerator;
4+
import com.example.busan.auth.infrastructure.InMemoryPhoneAuthenticator;
5+
import com.example.busan.auth.service.PhoneAuthenticator;
36
import net.nurigo.sdk.message.service.DefaultMessageService;
47
import org.springframework.beans.factory.annotation.Value;
58
import org.springframework.context.annotation.Bean;
69
import org.springframework.context.annotation.Configuration;
10+
import org.springframework.context.annotation.Profile;
711

812
@Configuration
913
public class PhoneAuthenticatorConfig {
1014

15+
private final AuthorizationCodeGenerator codeGenerator;
1116
private final String key;
1217
private final String secret;
18+
private final String sender;
1319

14-
public PhoneAuthenticatorConfig(@Value("${phone.key}") final String key,
15-
@Value("${phone.secret}") final String secret) {
20+
public PhoneAuthenticatorConfig(final AuthorizationCodeGenerator codeGenerator,
21+
@Value("${phone.key}") final String key,
22+
@Value("${phone.secret}") final String secret,
23+
@Value("${phone.sender}") final String sender) {
24+
this.codeGenerator = codeGenerator;
1625
this.key = key;
1726
this.secret = secret;
27+
this.sender = sender;
28+
}
29+
30+
@Profile("prod")
31+
@Bean
32+
public PhoneAuthenticator phoneAuthenticator() {
33+
return new InMemoryPhoneAuthenticator(messageService(), codeGenerator, sender);
34+
}
35+
36+
@Profile("default")
37+
@Bean
38+
public PhoneAuthenticator fakePhoneAuthenticator() {
39+
return new PhoneAuthenticator() {
40+
@Override
41+
public void sendCode(final String phone) {
42+
}
43+
44+
@Override
45+
public void authenticate(final String code) {
46+
}
47+
48+
@Override
49+
public void validateAuthenticated(final String phone) {
50+
}
51+
};
1852
}
1953

2054
@Bean
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.busan.auth;
1+
package com.example.busan.auth.dto;
22

33
public record FindEmailResponse(String email) {
44
}

src/main/java/com/example/busan/auth/infrastructure/InMemoryPhoneAuthenticator.java

-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
import org.slf4j.LoggerFactory;
1111
import org.springframework.beans.factory.annotation.Value;
1212
import org.springframework.scheduling.annotation.Scheduled;
13-
import org.springframework.stereotype.Component;
1413

1514
import java.time.LocalDateTime;
1615
import java.util.Map;
1716
import java.util.concurrent.ConcurrentHashMap;
1817

19-
@Component
2018
public class InMemoryPhoneAuthenticator implements PhoneAuthenticator {
2119

2220
private static final Logger log = LoggerFactory.getLogger(InMemoryPhoneAuthenticator.class);

src/main/java/com/example/busan/auth/service/AuthService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.example.busan.auth.service;
22

3-
import com.example.busan.auth.FindEmailResponse;
43
import com.example.busan.auth.domain.PasswordEncoder;
54
import com.example.busan.auth.dto.Authentication;
5+
import com.example.busan.auth.dto.FindEmailResponse;
66
import com.example.busan.auth.dto.LoginRequest;
77
import com.example.busan.member.domain.Member;
88
import com.example.busan.member.domain.MemberRepository;

src/test/java/com/example/busan/auth/AuthControllerTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.example.busan.auth.dto.AuthenticatePhoneRequest;
55
import com.example.busan.auth.dto.Authentication;
66
import com.example.busan.auth.dto.FindEmailRequest;
7+
import com.example.busan.auth.dto.FindEmailResponse;
78
import com.example.busan.auth.dto.LoginRequest;
89
import com.example.busan.auth.service.AuthService;
910
import com.example.busan.auth.service.PhoneAuthenticator;

src/test/java/com/example/busan/auth/AuthenticationServiceTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.example.busan.auth.domain.PasswordEncoder;
55
import com.example.busan.auth.dto.Authentication;
66
import com.example.busan.auth.dto.FindEmailRequest;
7+
import com.example.busan.auth.dto.FindEmailResponse;
78
import com.example.busan.auth.dto.LoginRequest;
89
import com.example.busan.auth.service.AuthService;
910
import com.example.busan.member.domain.Member;

src/test/java/com/example/busan/auth/infrastructure/InMemoryPhoneAuthenticatorTest.java

+5-11
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,22 @@
44
import net.nurigo.sdk.message.service.DefaultMessageService;
55
import org.junit.jupiter.api.DisplayName;
66
import org.junit.jupiter.api.Test;
7-
import org.springframework.beans.factory.annotation.Autowired;
87
import org.springframework.boot.test.context.SpringBootTest;
9-
import org.springframework.boot.test.mock.mockito.MockBean;
108

119
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1210
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
1311
import static org.mockito.BDDMockito.any;
1412
import static org.mockito.BDDMockito.given;
1513
import static org.mockito.BDDMockito.times;
1614
import static org.mockito.BDDMockito.verify;
15+
import static org.mockito.Mockito.mock;
1716

1817
@SpringBootTest
1918
class InMemoryPhoneAuthenticatorTest {
2019

21-
@Autowired
22-
private InMemoryPhoneAuthenticator phoneAuthenticator;
23-
@MockBean
24-
private DefaultMessageService messageService;
25-
@MockBean
26-
private AuthorizationCodeGenerator codeGenerator;
20+
private final DefaultMessageService messageService = mock(DefaultMessageService.class);
21+
private final AuthorizationCodeGenerator codeGenerator = mock(AuthorizationCodeGenerator.class);
22+
private final InMemoryPhoneAuthenticator phoneAuthenticator = new InMemoryPhoneAuthenticator(messageService, codeGenerator, "01012341234");
2723

2824
@Test
2925
@DisplayName("휴대폰 인증 코드를 전송할 수 있다")
@@ -32,10 +28,8 @@ void sendCode() {
3228
given(codeGenerator.generate())
3329
.willReturn("123455");
3430

35-
final String phone = "01012345";
36-
3731
//when
38-
phoneAuthenticator.sendCode(phone);
32+
phoneAuthenticator.sendCode("01012345678");
3933

4034
//then
4135
verify(messageService, times(1)).sendOne(any());

0 commit comments

Comments
 (0)