From 295a342be0dd0909cc0552b0d810b9367ed159f2 Mon Sep 17 00:00:00 2001 From: bedrin Date: Tue, 31 Oct 2023 00:21:45 +0100 Subject: [PATCH] Remove static initializers from SpnegoAuthenticationProcessingFilterTest --- ...pnegoAuthenticationProcessingFilterTest.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/kerb4j-server/kerb4j-server-spring-security/src/test/java/com/kerb4j/server/spring/SpnegoAuthenticationProcessingFilterTest.java b/kerb4j-server/kerb4j-server-spring-security/src/test/java/com/kerb4j/server/spring/SpnegoAuthenticationProcessingFilterTest.java index f60836e..db08aae 100644 --- a/kerb4j-server/kerb4j-server-spring-security/src/test/java/com/kerb4j/server/spring/SpnegoAuthenticationProcessingFilterTest.java +++ b/kerb4j-server/kerb4j-server-spring-security/src/test/java/com/kerb4j/server/spring/SpnegoAuthenticationProcessingFilterTest.java @@ -54,17 +54,15 @@ * @author Jeremy Stone * @since 1.0 */ -class SpnegoAuthenticationProcessingFilterTest { +public class SpnegoAuthenticationProcessingFilterTest { // data private static final byte[] TEST_TOKEN = "TestToken".getBytes(); private static final String TEST_TOKEN_BASE64 = "VGVzdFRva2Vu"; - private static final Authentication AUTHENTICATION = new SpnegoRequestToken(TEST_TOKEN); private static final String HEADER = "Authorization"; private static final String TOKEN_PREFIX_NEG = "Negotiate "; private static final String TOKEN_PREFIX_KERB = "Kerberos "; - private static final BadCredentialsException BCE = new BadCredentialsException(""); - private static SpnegoAuthenticationToken UNUSED_TICKET_VALIDATION = mock(SpnegoAuthenticationToken.class); + //private static SpnegoAuthenticationToken UNUSED_TICKET_VALIDATION = mock(SpnegoAuthenticationToken.class); private SpnegoAuthenticationProcessingFilter filter; private AuthenticationManager authenticationManager; private HttpServletRequest request; @@ -110,6 +108,7 @@ void testEverythingWorksWithHandlers_Kerberos() throws Exception { } private void everythingWorksWithHandlers(String tokenPrefix) throws Exception { + Authentication AUTHENTICATION = new SpnegoRequestToken(TEST_TOKEN); createHandler(); everythingWorks(tokenPrefix); verify(successHandler).onAuthenticationSuccess(request, response, AUTHENTICATION); @@ -119,6 +118,7 @@ private void everythingWorksWithHandlers(String tokenPrefix) throws Exception { private void everythingWorks(String tokenPrefix) throws IOException, ServletException { + Authentication AUTHENTICATION = new SpnegoRequestToken(TEST_TOKEN); // stubbing when(request.getHeader(HEADER)).thenReturn(tokenPrefix + TEST_TOKEN_BASE64); SpnegoRequestToken requestToken = new SpnegoRequestToken(TEST_TOKEN); @@ -151,7 +151,7 @@ void testAuthenticationFails() throws Exception { @Test void testAuthenticationFailsWithHandlers() throws Exception { createHandler(); - authenticationFails(); + BadCredentialsException BCE = authenticationFails(); verify(failureHandler).onAuthenticationFailure(request, response, BCE); verify(successHandler, never()).onAuthenticationSuccess(any(HttpServletRequest.class), any(HttpServletResponse.class), any(Authentication.class)); @@ -210,7 +210,10 @@ void testAlreadyAuthenticatedNotActive() throws Exception { } } - private void authenticationFails() throws IOException, ServletException { + private BadCredentialsException authenticationFails() throws IOException, ServletException { + + BadCredentialsException BCE = new BadCredentialsException(""); + // stubbing when(request.getHeader(HEADER)).thenReturn(TOKEN_PREFIX_NEG + TEST_TOKEN_BASE64); when(authenticationManager.authenticate(any(Authentication.class))).thenThrow(BCE); @@ -220,6 +223,8 @@ private void authenticationFails() throws IOException, ServletException { // chain should stop here and it should send back a 500 // future version should call some error handler verify(chain, never()).doFilter(any(ServletRequest.class), any(ServletResponse.class)); + + return BCE; } private void createHandler() {