Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.Arrays;
import java.util.Properties;
import java.util.concurrent.Callable;
import org.junit.jupiter.api.Timeout;

/**
* Test class for {@link KerberosAuthenticator}.
Expand Down Expand Up @@ -89,7 +90,8 @@ private Properties getMultiAuthHandlerConfiguration() {
return props;
}

@Test(timeout=60000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this file (and a few additional ones) is using junit4 library for the most part.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your help with the review. You are right, many parts of this module are still using JUnit 4. We are actively upgrading from JUnit 4 to JUnit 5. The goal of this PR is to complete the upgrade of the hadoop-minikdc module and its unit tests, as well as to upgrade other modules that depend on hadoop-minikdc.

@Test
@Timeout(value = 60)
public void testFallbacktoPseudoAuthenticator() throws Exception {
AuthenticatorTestCase auth = new AuthenticatorTestCase();
Properties props = new Properties();
Expand All @@ -99,7 +101,8 @@ public void testFallbacktoPseudoAuthenticator() throws Exception {
auth._testAuthentication(new KerberosAuthenticator(), false);
}

@Test(timeout=60000)
@Test
@Timeout(value = 60)
public void testFallbacktoPseudoAuthenticatorAnonymous() throws Exception {
AuthenticatorTestCase auth = new AuthenticatorTestCase();
Properties props = new Properties();
Expand All @@ -109,7 +112,8 @@ public void testFallbacktoPseudoAuthenticatorAnonymous() throws Exception {
auth._testAuthentication(new KerberosAuthenticator(), false);
}

@Test(timeout=60000)
@Test
@Timeout(value = 60)
public void testNotAuthenticated() throws Exception {
AuthenticatorTestCase auth = new AuthenticatorTestCase();
AuthenticatorTestCase.setAuthenticationHandlerConfig(getAuthenticationHandlerConfiguration());
Expand All @@ -125,7 +129,8 @@ public void testNotAuthenticated() throws Exception {
}
}

@Test(timeout=60000)
@Test
@Timeout(value = 60)
public void testAuthentication() throws Exception {
final AuthenticatorTestCase auth = new AuthenticatorTestCase();
AuthenticatorTestCase.setAuthenticationHandlerConfig(
Expand All @@ -139,7 +144,8 @@ public Void call() throws Exception {
});
}

@Test(timeout=60000)
@Test
@Timeout(value = 60)
public void testAuthenticationPost() throws Exception {
final AuthenticatorTestCase auth = new AuthenticatorTestCase();
AuthenticatorTestCase.setAuthenticationHandlerConfig(
Expand All @@ -153,7 +159,8 @@ public Void call() throws Exception {
});
}

@Test(timeout=60000)
@Test
@Timeout(value = 60)
public void testAuthenticationHttpClient() throws Exception {
final AuthenticatorTestCase auth = new AuthenticatorTestCase();
AuthenticatorTestCase.setAuthenticationHandlerConfig(
Expand All @@ -167,7 +174,8 @@ public Void call() throws Exception {
});
}

@Test(timeout=60000)
@Test
@Timeout(value = 60)
public void testAuthenticationHttpClientPost() throws Exception {
final AuthenticatorTestCase auth = new AuthenticatorTestCase();
AuthenticatorTestCase.setAuthenticationHandlerConfig(
Expand All @@ -181,7 +189,8 @@ public Void call() throws Exception {
});
}

@Test(timeout = 60000)
@Test
@Timeout(value = 60)
public void testNotAuthenticatedWithMultiAuthHandler() throws Exception {
AuthenticatorTestCase auth = new AuthenticatorTestCase();
AuthenticatorTestCase
Expand All @@ -200,7 +209,8 @@ public void testNotAuthenticatedWithMultiAuthHandler() throws Exception {
}
}

@Test(timeout = 60000)
@Test
@Timeout(value = 60)
public void testAuthenticationWithMultiAuthHandler() throws Exception {
final AuthenticatorTestCase auth = new AuthenticatorTestCase();
AuthenticatorTestCase
Expand All @@ -214,7 +224,8 @@ public Void call() throws Exception {
});
}

@Test(timeout = 60000)
@Test
@Timeout(value = 60)
public void testAuthenticationHttpClientPostWithMultiAuthHandler()
throws Exception {
final AuthenticatorTestCase auth = new AuthenticatorTestCase();
Expand All @@ -229,7 +240,8 @@ public Void call() throws Exception {
});
}

@Test(timeout = 60000)
@Test
@Timeout(value = 60)
public void testWrapExceptionWithMessage() {
IOException ex;
ex = new IOException("Induced exception");
Expand All @@ -255,7 +267,8 @@ public void testWrapExceptionWithMessage() {
Assert.assertTrue(ex.equals(ex2));
}

@Test(timeout = 60000)
@Test
@Timeout(value = 60)
public void testNegotiate() throws NoSuchMethodException, InvocationTargetException,
IllegalAccessException, IOException {
KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator();
Expand All @@ -272,7 +285,8 @@ public void testNegotiate() throws NoSuchMethodException, InvocationTargetExcept
Assert.assertTrue((boolean)method.invoke(kerberosAuthenticator, conn));
}

@Test(timeout = 60000)
@Test
@Timeout(value = 60)
public void testNegotiateLowerCase() throws NoSuchMethodException, InvocationTargetException,
IllegalAccessException, IOException {
KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator();
Expand All @@ -289,7 +303,8 @@ public void testNegotiateLowerCase() throws NoSuchMethodException, InvocationTar
Assert.assertTrue((boolean)method.invoke(kerberosAuthenticator, conn));
}

@Test(timeout = 60000)
@Test
@Timeout(value = 60)
public void testReadToken() throws NoSuchMethodException, IOException, IllegalAccessException,
InvocationTargetException {
KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator();
Expand All @@ -310,7 +325,8 @@ public void testReadToken() throws NoSuchMethodException, IOException, IllegalAc
method.invoke(kerberosAuthenticator, conn); // expecting this not to throw an exception
}

@Test(timeout = 60000)
@Test
@Timeout(value = 60)
public void testReadTokenLowerCase() throws NoSuchMethodException, IOException,
IllegalAccessException, InvocationTargetException {
KerberosAuthenticator kerberosAuthenticator = new KerberosAuthenticator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.junit.jupiter.api.Timeout;

public class TestAltKerberosAuthenticationHandler
extends TestKerberosAuthenticationHandler {
Expand All @@ -47,7 +48,8 @@ protected String getExpectedType() {
return AltKerberosAuthenticationHandler.TYPE;
}

@Test(timeout=60000)
@Test
@Timeout(value = 60)
public void testAlternateAuthenticationAsBrowser() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
Expand All @@ -62,7 +64,8 @@ public void testAlternateAuthenticationAsBrowser() throws Exception {
Assert.assertEquals(getExpectedType(), token.getType());
}

@Test(timeout=60000)
@Test
@Timeout(value = 60)
public void testNonDefaultNonBrowserUserAgentAsBrowser() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
Expand Down Expand Up @@ -90,7 +93,8 @@ public void testNonDefaultNonBrowserUserAgentAsBrowser() throws Exception {
Assert.assertEquals(getExpectedType(), token.getType());
}

@Test(timeout=60000)
@Test
@Timeout(value = 60)
public void testNonDefaultNonBrowserUserAgentAsNonBrowser() throws Exception {
if (handler != null) {
handler.destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
*/
package org.apache.hadoop.security.authentication.server;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.File;
import java.security.KeyPair;
Expand All @@ -35,10 +37,10 @@
import org.apache.hadoop.minikdc.KerberosSecurityTestcase;
import org.apache.hadoop.security.authentication.KerberosTestUtils;
import org.apache.hadoop.security.authentication.client.AuthenticationException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.mockito.Mockito;

import com.nimbusds.jose.*;
Expand Down Expand Up @@ -107,7 +109,7 @@ public void testCustomCookieNameJWT() throws Exception {

AuthenticationToken token = handler.alternateAuthenticate(request,
response);
Assert.assertEquals("bob", token.getUserName());
assertEquals("bob", token.getUserName());
} catch (ServletException se) {
fail("alternateAuthentication should NOT have thrown a ServletException: "
+ se.getMessage());
Expand Down Expand Up @@ -275,8 +277,8 @@ public void testNoExpirationJWT() throws Exception {

AuthenticationToken token = handler.alternateAuthenticate(request,
response);
Assert.assertNotNull("Token should not be null.", token);
Assert.assertEquals("bob", token.getUserName());
assertNotNull(token, "Token should not be null.");
assertEquals("bob", token.getUserName());
} catch (ServletException se) {
fail("alternateAuthentication should NOT have thrown a ServletException");
} catch (AuthenticationException ae) {
Expand Down Expand Up @@ -340,7 +342,7 @@ public void testValidAudienceJWT() throws Exception {

AuthenticationToken token = handler.alternateAuthenticate(request,
response);
Assert.assertEquals("bob", token.getUserName());
assertEquals("bob", token.getUserName());
} catch (ServletException se) {
fail("alternateAuthentication should NOT have thrown a ServletException");
} catch (AuthenticationException ae) {
Expand Down Expand Up @@ -370,8 +372,8 @@ public void testValidJWT() throws Exception {

AuthenticationToken token = handler.alternateAuthenticate(request,
response);
Assert.assertNotNull("Token should not be null.", token);
Assert.assertEquals("alice", token.getUserName());
assertNotNull(token, "Token should not be null.");
assertEquals("alice", token.getUserName());
} catch (ServletException se) {
fail("alternateAuthentication should NOT have thrown a ServletException.");
} catch (AuthenticationException ae) {
Expand All @@ -392,8 +394,8 @@ public void testOrigURLWithQueryString() throws Exception {
Mockito.when(request.getQueryString()).thenReturn("name=value");

String loginURL = handler.constructLoginURL(request);
Assert.assertNotNull("loginURL should not be null.", loginURL);
Assert.assertEquals("https://localhost:8443/authserver?originalUrl=" + SERVICE_URL + "?name=value", loginURL);
assertNotNull(loginURL, "loginURL should not be null.");
assertEquals("https://localhost:8443/authserver?originalUrl=" + SERVICE_URL + "?name=value", loginURL);
}

@Test
Expand All @@ -409,11 +411,11 @@ public void testOrigURLNoQueryString() throws Exception {
Mockito.when(request.getQueryString()).thenReturn(null);

String loginURL = handler.constructLoginURL(request);
Assert.assertNotNull("LoginURL should not be null.", loginURL);
Assert.assertEquals("https://localhost:8443/authserver?originalUrl=" + SERVICE_URL, loginURL);
assertNotNull(loginURL, "LoginURL should not be null.");
assertEquals("https://localhost:8443/authserver?originalUrl=" + SERVICE_URL, loginURL);
}

@Before
@BeforeEach
public void setup() throws Exception, NoSuchAlgorithmException {
setupKerberosRequirements();

Expand All @@ -434,7 +436,7 @@ protected void setupKerberosRequirements() throws Exception {
getKdc().createPrincipal(new File(keytab), keytabUsers);
}

@After
@AfterEach
public void teardown() throws Exception {
handler.destroy();
}
Expand Down
Loading