|
18 | 18 | import org.mockito.junit.jupiter.MockitoExtension; |
19 | 19 | import org.springframework.mock.web.MockHttpServletRequest; |
20 | 20 | import org.springframework.mock.web.MockHttpServletResponse; |
| 21 | +import org.springframework.security.authentication.BadCredentialsException; |
21 | 22 | import org.springframework.security.core.AuthenticationException; |
22 | 23 |
|
23 | 24 | import static org.assertj.core.api.Assertions.assertThat; |
24 | 25 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 26 | +import static org.mockito.Mockito.verify; |
25 | 27 | import static org.mockito.Mockito.verifyNoInteractions; |
| 28 | +import static org.mockito.Mockito.when; |
26 | 29 |
|
27 | 30 | @ExtendWith(MockitoExtension.class) |
28 | 31 | class OAuthLoginFilterValidationTest { |
@@ -65,6 +68,29 @@ void googleLoginFilterRejectsInvalidRequest() throws Exception { |
65 | 68 | verifyNoInteractions(googleLoginService, userRepository); |
66 | 69 | } |
67 | 70 |
|
| 71 | + @Test |
| 72 | + @DisplayName("구글 로그인 필터가 검증 실패한 idToken을 인증 실패로 처리한다") |
| 73 | + void googleLoginFilterRejectsUnverifiedIdToken() throws Exception { |
| 74 | + GoogleLoginFilter filter = new GoogleLoginFilter( |
| 75 | + "/oauth2/google/login", |
| 76 | + objectMapper, |
| 77 | + validator, |
| 78 | + googleLoginService, |
| 79 | + userRepository); |
| 80 | + MockHttpServletResponse response = new MockHttpServletResponse(); |
| 81 | + |
| 82 | + when(googleLoginService.verifyIdentityToken("invalid-token")).thenReturn(null); |
| 83 | + |
| 84 | + assertThatThrownBy(() -> filter.attemptAuthentication( |
| 85 | + request("/oauth2/google/login", "{\"idToken\":\"invalid-token\"}"), |
| 86 | + response)) |
| 87 | + .isInstanceOf(BadCredentialsException.class) |
| 88 | + .hasMessage("Invalid Google identity token"); |
| 89 | + |
| 90 | + verify(googleLoginService).verifyIdentityToken("invalid-token"); |
| 91 | + verifyNoInteractions(userRepository); |
| 92 | + } |
| 93 | + |
68 | 94 | @Test |
69 | 95 | @DisplayName("카카오 로그인 필터가 잘못된 요청을 400 validation 응답으로 처리한다") |
70 | 96 | void kakaoLoginFilterRejectsInvalidRequest() throws Exception { |
|
0 commit comments