Conversation
📝 WalkthroughWalkthroughHealthControllerTest에 Spring Security 테스트 지원과 모의 보안 빈이 추가되고, 테스트용 application.yml에 서버 프로필과 jwt.secret이 추가되었으며, 빌드에 spring-security-test 의존성이 추가되었습니다. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 토끼의 시
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/test/java/com/eatsfine/eatsfine/controller/HealthControllerTest.java`:
- Line 27: HealthControllerTest currently disables the security filter chain via
`@AutoConfigureMockMvc`(addFilters = false) which creates a coverage gap; add one
or more tests that exercise security behavior by either removing
addFilters=false for a new test class or adding complementary tests that enable
filters and assert authentication/authorization flows (e.g., using `@WithMockUser`
on test methods) to validate HealthController endpoints under security; target
the test class/methods named HealthControllerTest and any specific test methods
calling MockMvc.perform(...) so they verify expected HTTP status/response when
unauthenticated vs authenticated and when roles/authorities are present.
src/test/java/com/eatsfine/eatsfine/controller/HealthControllerTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/test/java/com/eatsfine/eatsfine/controller/HealthControllerTest.java`:
- Around line 53-63: 현재 setUp()에서 jwtAuthenticationFilter.doFilter(...)를 완전히 스텁해
보안 필터를 우회하므로 인증/인가 동작이 검증되지 않습니다; 이를 해결하려면 기존 HealthControllerTest의 setUp()에서
jwtAuthenticationFilter 스텁을 제거하거나, 인증 동작을 검증할 별도 테스트 클래스를 만들어
`@AutoConfigureMockMvc`(addFilters = true) 또는 실제 필터가 적용된 MockMvc로 테스트하여 "인증되지 않은
요청은 401" 및 "권한 없는 요청은 403" 시나리오를 검사하세요; 구체적으로 JwtAuthenticationFilter을 실제로 적용하는
테스트(예: healthCheckWithoutAuth_shouldReturn401,
healthCheckWithoutRole_shouldReturn403)를 추가하고 해당 테스트에서는 setUp의 doAnswer 스텁을 사용하지
않거나 별도 클래스로 분리해 필터가 실행되도록 하세요.
- Line 13: Replace usages of the deprecated `@MockBean` in HealthControllerTest
with the new `@MockitoBean`: update the import from
org.springframework.boot.test.mock.mockito.MockBean to
org.springframework.test.context.bean.override.mockito.MockitoBean and change
any `@MockBean` annotations on fields or parameters inside the
HealthControllerTest class to `@MockitoBean` so tests use the new annotation for
Spring Boot 3.4.1 compatibility.
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
| import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
| import org.springframework.boot.test.mock.mockito.MockBean; |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Spring Boot 3.4 MockBean deprecation @MockitoBean replacement
💡 Result:
In Spring Boot 3.4, Boot’s Mockito test annotations are deprecated:
org.springframework.boot.test.mock.mockito.@MockBean→ use Spring Framework’sorg.springframework.test.context.bean.override.mockito.@MockitoBean(github.com)org.springframework.boot.test.mock.mockito.@SpyBean→ useorg.springframework.test.context.bean.override.mockito.@MockitoSpyBean(github.com)
Common replacement (field-level)
// before (deprecated in Boot 3.4)
import org.springframework.boot.test.mock.mockito.MockBean;
// after
import org.springframework.test.context.bean.override.mockito.MockitoBean;
`@MockitoBean`
UserService userService;@MockitoBean overrides (replaces, or creates if missing) a bean in the test ApplicationContext; use @Qualifier or the field name to disambiguate, or set name/value. (docs.spring.io)
If you previously used @MockBeans
There’s no need for a Boot-specific container; with Spring you can use repeatable @MockitoBean at the type level (and/or multiple fields). (docs.spring.io)
Citations:
- 1: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.4-Release-Notes?utm_source=openai
- 2: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.4-Release-Notes?utm_source=openai
- 3: https://docs.spring.io/spring-framework/reference/testing/annotations/integration-spring/annotation-mockitobean.html?utm_source=openai
- 4: https://docs.spring.io/spring-framework/docs/6.2.x/javadoc-api/org/springframework/test/context/bean/override/mockito/MockitoBean.html?utm_source=openai
🏁 Script executed:
find . -name "build.gradle*" -o -name "pom.xml" | head -5Repository: Eatsfine/BE
Length of output: 69
🏁 Script executed:
cat build.gradle | grep -A 5 -B 5 "spring.boot"Repository: Eatsfine/BE
Length of output: 1904
🏁 Script executed:
cat src/test/java/com/eatsfine/eatsfine/controller/HealthControllerTest.java | head -20Repository: Eatsfine/BE
Length of output: 1081
🏁 Script executed:
cat build.gradle | grep -i "spring.boot\|gradle"Repository: Eatsfine/BE
Length of output: 657
🏁 Script executed:
head -50 build.gradle | grep -E "plugins|springframework.boot|id"Repository: Eatsfine/BE
Length of output: 637
@MockBean 어노테이션을 새로운 @MockitoBean으로 변경해주세요.
현재 프로젝트는 Spring Boot 3.4.1을 사용하고 있으며, 이 버전부터 org.springframework.boot.test.mock.mockito.MockBean은 deprecated 예정입니다. 새로운 @MockitoBean 어노테이션(org.springframework.test.context.bean.override.mockito.MockitoBean)으로 변경하여 향후 호환성을 유지해주세요.
🤖 Prompt for AI Agents
In `@src/test/java/com/eatsfine/eatsfine/controller/HealthControllerTest.java` at
line 13, Replace usages of the deprecated `@MockBean` in HealthControllerTest with
the new `@MockitoBean`: update the import from
org.springframework.boot.test.mock.mockito.MockBean to
org.springframework.test.context.bean.override.mockito.MockitoBean and change
any `@MockBean` annotations on fields or parameters inside the
HealthControllerTest class to `@MockitoBean` so tests use the new annotation for
Spring Boot 3.4.1 compatibility.
| @BeforeEach | ||
| void setUp() throws ServletException, IOException { | ||
| doAnswer(invocation -> { | ||
| HttpServletRequest request = invocation.getArgument(0); | ||
| HttpServletResponse response = invocation.getArgument(1); | ||
| FilterChain chain = invocation.getArgument(2); | ||
| chain.doFilter(request, response); | ||
| return null; | ||
| }).when(jwtAuthenticationFilter).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class), | ||
| any(FilterChain.class)); | ||
| } |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial
보안 필터 우회 방식에 대한 고려사항.
doFilter 스텁을 통해 JWT 필터를 완전히 우회하는 방식은 컨트롤러 로직 테스트에는 적합하지만, 실제 보안 동작은 검증하지 않습니다. @WithMockUser와 함께 사용해도 인증/인가 플로우 자체는 테스트되지 않습니다.
가능하다면 별도의 테스트 케이스를 추가하여 다음 시나리오를 검증하는 것을 권장합니다:
- 인증되지 않은 요청 시 401 응답
- 권한 없는 요청 시 403 응답
🧪 보안 동작 검증 테스트 예시
`@Test`
`@DisplayName`("인증되지 않은 요청은 401 응답을 반환한다")
void healthCheckWithoutAuth_shouldReturn401() throws Exception {
// JwtAuthenticationFilter가 실제로 동작하도록 setUp의 doAnswer를 제거하거나
// 별도 테스트 클래스에서 `@AutoConfigureMockMvc`(addFilters = true)로 테스트
mockMvc
.perform(get("/api/v1/deploy/health-check"))
.andExpect(status().isUnauthorized());
}🤖 Prompt for AI Agents
In `@src/test/java/com/eatsfine/eatsfine/controller/HealthControllerTest.java`
around lines 53 - 63, 현재 setUp()에서 jwtAuthenticationFilter.doFilter(...)를 완전히
스텁해 보안 필터를 우회하므로 인증/인가 동작이 검증되지 않습니다; 이를 해결하려면 기존 HealthControllerTest의
setUp()에서 jwtAuthenticationFilter 스텁을 제거하거나, 인증 동작을 검증할 별도 테스트 클래스를 만들어
`@AutoConfigureMockMvc`(addFilters = true) 또는 실제 필터가 적용된 MockMvc로 테스트하여 "인증되지 않은
요청은 401" 및 "권한 없는 요청은 403" 시나리오를 검사하세요; 구체적으로 JwtAuthenticationFilter을 실제로 적용하는
테스트(예: healthCheckWithoutAuth_shouldReturn401,
healthCheckWithoutRole_shouldReturn403)를 추가하고 해당 테스트에서는 setUp의 doAnswer 스텁을 사용하지
않거나 별도 클래스로 분리해 필터가 실행되도록 하세요.
💡 작업 개요
✅ 작업 내용
🧪 테스트 내용
📝 기타 참고 사항
Summary by CodeRabbit
릴리스 노트
Tests
Chores