|
@@ -26,6 +26,7 @@ import static org.apache.hadoop.security.authentication.server.HttpConstants.*;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.util.Properties;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
@@ -38,21 +39,22 @@ import org.apache.directory.server.core.annotations.ContextEntry;
|
|
|
import org.apache.directory.server.core.annotations.CreateDS;
|
|
|
import org.apache.directory.server.core.annotations.CreatePartition;
|
|
|
import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
|
|
|
-import org.apache.directory.server.core.integ.FrameworkRunner;
|
|
|
+import org.apache.directory.server.core.integ.ApacheDSTestExtension;
|
|
|
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.runner.RunWith;
|
|
|
+import org.junit.jupiter.api.AfterEach;
|
|
|
+import org.junit.jupiter.api.Assertions;
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.junit.jupiter.api.Timeout;
|
|
|
+import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
import org.mockito.Mockito;
|
|
|
|
|
|
/**
|
|
|
* This unit test verifies the functionality of "multi-scheme" auth handler.
|
|
|
*/
|
|
|
-@RunWith(FrameworkRunner.class)
|
|
|
+@ExtendWith(ApacheDSTestExtension.class)
|
|
|
@CreateLdapServer(
|
|
|
transports =
|
|
|
{
|
|
@@ -79,7 +81,7 @@ public class TestMultiSchemeAuthenticationHandler
|
|
|
private KerberosSecurityTestcase krbTest = new KerberosSecurityTestcase();
|
|
|
private MultiSchemeAuthenticationHandler handler;
|
|
|
|
|
|
- @Before
|
|
|
+ @BeforeEach
|
|
|
public void setUp() throws Exception {
|
|
|
krbTest.startMiniKdc();
|
|
|
|
|
@@ -99,7 +101,7 @@ public class TestMultiSchemeAuthenticationHandler
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @After
|
|
|
+ @AfterEach
|
|
|
public void tearDown() throws Exception {
|
|
|
krbTest.stopMiniKdc();
|
|
|
}
|
|
@@ -122,18 +124,20 @@ public class TestMultiSchemeAuthenticationHandler
|
|
|
return p;
|
|
|
}
|
|
|
|
|
|
- @Test(timeout = 60000)
|
|
|
+ @Test
|
|
|
+ @Timeout(value = 60, unit = TimeUnit.SECONDS)
|
|
|
public void testRequestWithoutAuthorization() throws Exception {
|
|
|
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
|
|
|
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
|
|
|
|
|
|
- Assert.assertNull(handler.authenticate(request, response));
|
|
|
+ Assertions.assertNull(handler.authenticate(request, response));
|
|
|
Mockito.verify(response).addHeader(WWW_AUTHENTICATE_HEADER, BASIC);
|
|
|
Mockito.verify(response).addHeader(WWW_AUTHENTICATE_HEADER, NEGOTIATE);
|
|
|
Mockito.verify(response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
|
|
}
|
|
|
|
|
|
- @Test(timeout = 60000)
|
|
|
+ @Test
|
|
|
+ @Timeout(value = 60, unit = TimeUnit.SECONDS)
|
|
|
public void testRequestWithInvalidAuthorization() throws Exception {
|
|
|
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
|
|
|
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
|
|
@@ -142,13 +146,14 @@ public class TestMultiSchemeAuthenticationHandler
|
|
|
String credentials = "bjones:invalidpassword";
|
|
|
Mockito.when(request.getHeader(AUTHORIZATION_HEADER))
|
|
|
.thenReturn(base64.encodeToString(credentials.getBytes()));
|
|
|
- Assert.assertNull(handler.authenticate(request, response));
|
|
|
+ Assertions.assertNull(handler.authenticate(request, response));
|
|
|
Mockito.verify(response).addHeader(WWW_AUTHENTICATE_HEADER, BASIC);
|
|
|
Mockito.verify(response).addHeader(WWW_AUTHENTICATE_HEADER, NEGOTIATE);
|
|
|
Mockito.verify(response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
|
|
}
|
|
|
|
|
|
- @Test(timeout = 60000)
|
|
|
+ @Test
|
|
|
+ @Timeout(value = 60, unit = TimeUnit.SECONDS)
|
|
|
public void testRequestWithLdapAuthorization() throws Exception {
|
|
|
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
|
|
|
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
|
|
@@ -159,14 +164,15 @@ public class TestMultiSchemeAuthenticationHandler
|
|
|
Mockito.when(request.getHeader(AUTHORIZATION_HEADER))
|
|
|
.thenReturn(authHeader);
|
|
|
AuthenticationToken token = handler.authenticate(request, response);
|
|
|
- Assert.assertNotNull(token);
|
|
|
+ Assertions.assertNotNull(token);
|
|
|
Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
|
|
|
- Assert.assertEquals(TYPE, token.getType());
|
|
|
- Assert.assertEquals("bjones", token.getUserName());
|
|
|
- Assert.assertEquals("bjones", token.getName());
|
|
|
+ Assertions.assertEquals(TYPE, token.getType());
|
|
|
+ Assertions.assertEquals(token.getUserName(), "bjones");
|
|
|
+ Assertions.assertEquals(token.getName(), "bjones");
|
|
|
}
|
|
|
|
|
|
- @Test(timeout = 60000)
|
|
|
+ @Test
|
|
|
+ @Timeout(value = 60, unit = TimeUnit.SECONDS)
|
|
|
public void testRequestWithInvalidKerberosAuthorization() throws Exception {
|
|
|
String token = new Base64(0).encodeToString(new byte[]{0, 1, 2});
|
|
|
|
|
@@ -178,11 +184,11 @@ public class TestMultiSchemeAuthenticationHandler
|
|
|
|
|
|
try {
|
|
|
handler.authenticate(request, response);
|
|
|
- Assert.fail();
|
|
|
+ Assertions.fail();
|
|
|
} catch (AuthenticationException ex) {
|
|
|
// Expected
|
|
|
} catch (Exception ex) {
|
|
|
- Assert.fail("Wrong exception :"+ex);
|
|
|
+ Assertions.fail("Wrong exception :"+ex);
|
|
|
}
|
|
|
}
|
|
|
|