Skip to content

Commit 3a18a9c

Browse files
committed
✅ test: qa 테스트 전용 토큰 발급 컨트롤러 추가
1 parent 73db404 commit 3a18a9c

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package akuma.whiplash.domains.auth.presentation;
2+
3+
import akuma.whiplash.domains.member.domain.contants.Role;
4+
import akuma.whiplash.domains.member.persistence.entity.MemberEntity;
5+
import akuma.whiplash.domains.member.persistence.repository.MemberRepository;
6+
import akuma.whiplash.global.config.security.jwt.JwtProvider;
7+
import akuma.whiplash.global.response.ApplicationResponse;
8+
import lombok.RequiredArgsConstructor;
9+
import org.springframework.context.annotation.Profile;
10+
import org.springframework.web.bind.annotation.PostMapping;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RequestParam;
13+
import org.springframework.web.bind.annotation.RestController;
14+
15+
/**
16+
* QA 전용 토큰 발급 컨트롤러
17+
*
18+
* - @Profile("qa") 로 QA 서버에서만 활성화, prod 배포 시 Bean 자체가 생성되지 않음
19+
* - 소셜 로그인 없이 socialId 기반으로 JWT를 발급
20+
* - k6 setup() 단계에서 호출해 테스트용 토큰을 자동 발급받는 용도
21+
*
22+
* 사용 예시:
23+
* POST /qa/auth/token?socialId=QA_DUMMY_001&deviceId=k6-device-001
24+
*/
25+
@Profile("qa")
26+
@RestController
27+
@RequiredArgsConstructor
28+
@RequestMapping("/qa/auth")
29+
public class QaAuthController {
30+
31+
private final MemberRepository memberRepository;
32+
private final JwtProvider jwtProvider;
33+
34+
private static final String BEARER_PREFIX = "Bearer ";
35+
36+
@PostMapping("/token")
37+
public ApplicationResponse<String> issueToken(
38+
@RequestParam String socialId,
39+
@RequestParam(defaultValue = "k6-device") String deviceId
40+
) {
41+
MemberEntity member = memberRepository.findBySocialId(socialId)
42+
.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 socialId: " + socialId));
43+
44+
String accessToken = jwtProvider.generateAccessToken(
45+
member.getId(),
46+
Role.USER,
47+
deviceId
48+
);
49+
50+
return ApplicationResponse.onSuccess(BEARER_PREFIX + accessToken);
51+
}
52+
}

src/main/java/akuma/whiplash/global/config/security/RequestMatcherHolder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public class RequestMatcherHolder {
6464
// actuator
6565
new RequestInfo(GET, "/actuator/**", null),
6666

67+
// QA 전용 토큰 발급 (SecurityConfig에서 qa 프로파일에서만 등록)
68+
new RequestInfo(POST, "/qa/auth/token", null),
69+
6770
// 빌드 에러 방지를 위해 각 권한에 대한 RequestInfo가 최소 1개씩은 리스트에 있어야함
6871
new RequestInfo(GET, "/api/admin/**", ADMIN)
6972
);

0 commit comments

Comments
 (0)