@@ -39,7 +39,7 @@ void skipsPublicHtmlPages(String path) throws Exception {
3939 UserRepository userRepository = mock (UserRepository .class );
4040 AuthTokenService authTokenService = mock (AuthTokenService .class );
4141 FilterChain filterChain = mock (FilterChain .class );
42- JwtAuthenticationFilter filter = new JwtAuthenticationFilter (jwtTokenProvider , userRepository , authTokenService );
42+ JwtAuthenticationFilter filter = new JwtAuthenticationFilter (jwtTokenProvider , authTokenService );
4343 MockHttpServletRequest request = new MockHttpServletRequest ("GET" , path );
4444 MockHttpServletResponse response = new MockHttpServletResponse ();
4545
@@ -56,20 +56,19 @@ void validAccessTokenAuthenticatesUserAndContinuesFilterChain() throws Exception
5656 UserRepository userRepository = mock (UserRepository .class );
5757 AuthTokenService authTokenService = mock (AuthTokenService .class );
5858 FilterChain filterChain = mock (FilterChain .class );
59- JwtAuthenticationFilter filter = new JwtAuthenticationFilter (jwtTokenProvider , userRepository , authTokenService );
59+ JwtAuthenticationFilter filter = new JwtAuthenticationFilter (jwtTokenProvider , authTokenService );
6060 MockHttpServletRequest request = new MockHttpServletRequest ("GET" , "/schedules" );
6161 MockHttpServletResponse response = new MockHttpServletResponse ();
6262 User user = user ("user@example.com" , "encoded-password" );
6363
6464 when (jwtTokenProvider .extractAccessToken (request )).thenReturn (Optional .of ("access-token" ));
6565 when (jwtTokenProvider .extractRefreshToken (request )).thenReturn (Optional .empty ());
66- when (jwtTokenProvider .isAccessTokenValid ("access-token" )).thenReturn (true );
67- when (jwtTokenProvider .extractUserId ("access-token" )).thenReturn (Optional .of (1L ));
68- when (userRepository .findById (1L )).thenReturn (Optional .of (user ));
66+ when (authTokenService .validateActiveAccessToken ("access-token" )).thenReturn (user );
6967
7068 filter .doFilter (request , response , filterChain );
7169
7270 verify (filterChain ).doFilter (request , response );
71+ verify (authTokenService ).validateActiveAccessToken ("access-token" );
7372 assertThat (SecurityContextHolder .getContext ().getAuthentication ().getName ()).isEqualTo ("user@example.com" );
7473 }
7574
@@ -79,7 +78,7 @@ void validRefreshTokenReissuesAccessTokenWithoutContinuingRequest() throws Excep
7978 UserRepository userRepository = mock (UserRepository .class );
8079 AuthTokenService authTokenService = mock (AuthTokenService .class );
8180 FilterChain filterChain = mock (FilterChain .class );
82- JwtAuthenticationFilter filter = new JwtAuthenticationFilter (jwtTokenProvider , userRepository , authTokenService );
81+ JwtAuthenticationFilter filter = new JwtAuthenticationFilter (jwtTokenProvider , authTokenService );
8382 MockHttpServletRequest request = new MockHttpServletRequest ("GET" , "/schedules" );
8483 MockHttpServletResponse response = new MockHttpServletResponse ();
8584 User user = user ("user@example.com" , "encoded-password" );
@@ -102,7 +101,7 @@ void missingAccessTokenReturnsTokenEmptyErrorEnvelope() throws Exception {
102101 UserRepository userRepository = mock (UserRepository .class );
103102 AuthTokenService authTokenService = mock (AuthTokenService .class );
104103 FilterChain filterChain = mock (FilterChain .class );
105- JwtAuthenticationFilter filter = new JwtAuthenticationFilter (jwtTokenProvider , userRepository , authTokenService );
104+ JwtAuthenticationFilter filter = new JwtAuthenticationFilter (jwtTokenProvider , authTokenService );
106105 MockHttpServletRequest request = new MockHttpServletRequest ("GET" , "/schedules" );
107106 MockHttpServletResponse response = new MockHttpServletResponse ();
108107
@@ -122,7 +121,7 @@ void invalidRefreshTokenReturnsRefreshSpecificErrorEnvelope() throws Exception {
122121 UserRepository userRepository = mock (UserRepository .class );
123122 AuthTokenService authTokenService = mock (AuthTokenService .class );
124123 FilterChain filterChain = mock (FilterChain .class );
125- JwtAuthenticationFilter filter = new JwtAuthenticationFilter (jwtTokenProvider , userRepository , authTokenService );
124+ JwtAuthenticationFilter filter = new JwtAuthenticationFilter (jwtTokenProvider , authTokenService );
126125 MockHttpServletRequest request = new MockHttpServletRequest ("GET" , "/schedules" );
127126 MockHttpServletResponse response = new MockHttpServletResponse ();
128127
@@ -144,13 +143,13 @@ void invalidAccessTokenReturnsAccessSpecificErrorEnvelope() throws Exception {
144143 UserRepository userRepository = mock (UserRepository .class );
145144 AuthTokenService authTokenService = mock (AuthTokenService .class );
146145 FilterChain filterChain = mock (FilterChain .class );
147- JwtAuthenticationFilter filter = new JwtAuthenticationFilter (jwtTokenProvider , userRepository , authTokenService );
146+ JwtAuthenticationFilter filter = new JwtAuthenticationFilter (jwtTokenProvider , authTokenService );
148147 MockHttpServletRequest request = new MockHttpServletRequest ("GET" , "/schedules" );
149148 MockHttpServletResponse response = new MockHttpServletResponse ();
150149
151150 when (jwtTokenProvider .extractAccessToken (request )).thenReturn (Optional .of ("access-token" ));
152151 when (jwtTokenProvider .extractRefreshToken (request )).thenReturn (Optional .empty ());
153- when (jwtTokenProvider . isAccessTokenValid ("access-token" ))
152+ when (authTokenService . validateActiveAccessToken ("access-token" ))
154153 .thenThrow (new InvalidAccessTokenException ("bad access" ));
155154
156155 filter .doFilter (request , response , filterChain );
@@ -162,7 +161,7 @@ void invalidAccessTokenReturnsAccessSpecificErrorEnvelope() throws Exception {
162161
163162 @ Test
164163 void socialLoginUserWithoutPasswordReceivesGeneratedAuthenticationPassword () {
165- JwtAuthenticationFilter filter = new JwtAuthenticationFilter (mock (JwtTokenProvider .class ), mock (UserRepository . class ), mock ( AuthTokenService .class ));
164+ JwtAuthenticationFilter filter = new JwtAuthenticationFilter (mock (JwtTokenProvider .class ), mock (AuthTokenService .class ));
166165 User user = user ("social@example.com" , null );
167166
168167 filter .saveAuthentication (user );
@@ -175,7 +174,7 @@ void socialLoginUserWithoutPasswordReceivesGeneratedAuthenticationPassword() {
175174
176175 @ Test
177176 void socialLoginUserWithoutEmailUsesUserIdAuthenticationName () {
178- JwtAuthenticationFilter filter = new JwtAuthenticationFilter (mock (JwtTokenProvider .class ), mock (UserRepository . class ), mock ( AuthTokenService .class ));
177+ JwtAuthenticationFilter filter = new JwtAuthenticationFilter (mock (JwtTokenProvider .class ), mock (AuthTokenService .class ));
179178 User user = user (null , null );
180179
181180 filter .saveAuthentication (user );
0 commit comments