HADOOP-10394. TestAuthenticationFilter is flaky. (Arpit Agarwal)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1576145 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d74ec9dd20
commit
109e88bf17
|
@ -37,8 +37,13 @@ import org.mockito.Mockito;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
public class TestAuthenticationFilter {
|
public class TestAuthenticationFilter {
|
||||||
|
|
||||||
|
private static final long TOKEN_VALIDITY_SEC = 1000;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetConfiguration() throws Exception {
|
public void testGetConfiguration() throws Exception {
|
||||||
AuthenticationFilter filter = new AuthenticationFilter();
|
AuthenticationFilter filter = new AuthenticationFilter();
|
||||||
|
@ -123,7 +128,7 @@ public class TestAuthenticationFilter {
|
||||||
String param = request.getParameter("authenticated");
|
String param = request.getParameter("authenticated");
|
||||||
if (param != null && param.equals("true")) {
|
if (param != null && param.equals("true")) {
|
||||||
token = new AuthenticationToken("u", "p", "t");
|
token = new AuthenticationToken("u", "p", "t");
|
||||||
token.setExpires((expired) ? 0 : System.currentTimeMillis() + 1000);
|
token.setExpires((expired) ? 0 : System.currentTimeMillis() + TOKEN_VALIDITY_SEC);
|
||||||
} else {
|
} else {
|
||||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
|
@ -139,7 +144,8 @@ public class TestAuthenticationFilter {
|
||||||
try {
|
try {
|
||||||
FilterConfig config = Mockito.mock(FilterConfig.class);
|
FilterConfig config = Mockito.mock(FilterConfig.class);
|
||||||
Mockito.when(config.getInitParameter(AuthenticationFilter.AUTH_TYPE)).thenReturn("simple");
|
Mockito.when(config.getInitParameter(AuthenticationFilter.AUTH_TYPE)).thenReturn("simple");
|
||||||
Mockito.when(config.getInitParameter(AuthenticationFilter.AUTH_TOKEN_VALIDITY)).thenReturn("1000");
|
Mockito.when(config.getInitParameter(AuthenticationFilter.AUTH_TOKEN_VALIDITY)).thenReturn(
|
||||||
|
(new Long(TOKEN_VALIDITY_SEC)).toString());
|
||||||
Mockito.when(config.getInitParameterNames()).thenReturn(
|
Mockito.when(config.getInitParameterNames()).thenReturn(
|
||||||
new Vector<String>(Arrays.asList(AuthenticationFilter.AUTH_TYPE,
|
new Vector<String>(Arrays.asList(AuthenticationFilter.AUTH_TYPE,
|
||||||
AuthenticationFilter.AUTH_TOKEN_VALIDITY)).elements());
|
AuthenticationFilter.AUTH_TOKEN_VALIDITY)).elements());
|
||||||
|
@ -148,7 +154,7 @@ public class TestAuthenticationFilter {
|
||||||
Assert.assertTrue(filter.isRandomSecret());
|
Assert.assertTrue(filter.isRandomSecret());
|
||||||
Assert.assertNull(filter.getCookieDomain());
|
Assert.assertNull(filter.getCookieDomain());
|
||||||
Assert.assertNull(filter.getCookiePath());
|
Assert.assertNull(filter.getCookiePath());
|
||||||
Assert.assertEquals(1000, filter.getValidity());
|
Assert.assertEquals(TOKEN_VALIDITY_SEC, filter.getValidity());
|
||||||
} finally {
|
} finally {
|
||||||
filter.destroy();
|
filter.destroy();
|
||||||
}
|
}
|
||||||
|
@ -265,7 +271,7 @@ public class TestAuthenticationFilter {
|
||||||
filter.init(config);
|
filter.init(config);
|
||||||
|
|
||||||
AuthenticationToken token = new AuthenticationToken("u", "p", DummyAuthenticationHandler.TYPE);
|
AuthenticationToken token = new AuthenticationToken("u", "p", DummyAuthenticationHandler.TYPE);
|
||||||
token.setExpires(System.currentTimeMillis() + 1000);
|
token.setExpires(System.currentTimeMillis() + TOKEN_VALIDITY_SEC);
|
||||||
Signer signer = new Signer("secret".getBytes());
|
Signer signer = new Signer("secret".getBytes());
|
||||||
String tokenSigned = signer.sign(token.toString());
|
String tokenSigned = signer.sign(token.toString());
|
||||||
|
|
||||||
|
@ -298,7 +304,7 @@ public class TestAuthenticationFilter {
|
||||||
filter.init(config);
|
filter.init(config);
|
||||||
|
|
||||||
AuthenticationToken token = new AuthenticationToken("u", "p", "invalidtype");
|
AuthenticationToken token = new AuthenticationToken("u", "p", "invalidtype");
|
||||||
token.setExpires(System.currentTimeMillis() - 1000);
|
token.setExpires(System.currentTimeMillis() - TOKEN_VALIDITY_SEC);
|
||||||
Signer signer = new Signer("secret".getBytes());
|
Signer signer = new Signer("secret".getBytes());
|
||||||
String tokenSigned = signer.sign(token.toString());
|
String tokenSigned = signer.sign(token.toString());
|
||||||
|
|
||||||
|
@ -337,7 +343,7 @@ public class TestAuthenticationFilter {
|
||||||
filter.init(config);
|
filter.init(config);
|
||||||
|
|
||||||
AuthenticationToken token = new AuthenticationToken("u", "p", "invalidtype");
|
AuthenticationToken token = new AuthenticationToken("u", "p", "invalidtype");
|
||||||
token.setExpires(System.currentTimeMillis() + 1000);
|
token.setExpires(System.currentTimeMillis() + TOKEN_VALIDITY_SEC);
|
||||||
Signer signer = new Signer("secret".getBytes());
|
Signer signer = new Signer("secret".getBytes());
|
||||||
String tokenSigned = signer.sign(token.toString());
|
String tokenSigned = signer.sign(token.toString());
|
||||||
|
|
||||||
|
@ -410,7 +416,7 @@ public class TestAuthenticationFilter {
|
||||||
Mockito.when(config.getInitParameter(AuthenticationFilter.AUTH_TYPE))
|
Mockito.when(config.getInitParameter(AuthenticationFilter.AUTH_TYPE))
|
||||||
.thenReturn(DummyAuthenticationHandler.class.getName());
|
.thenReturn(DummyAuthenticationHandler.class.getName());
|
||||||
Mockito.when(config.getInitParameter(AuthenticationFilter
|
Mockito.when(config.getInitParameter(AuthenticationFilter
|
||||||
.AUTH_TOKEN_VALIDITY)).thenReturn("1000");
|
.AUTH_TOKEN_VALIDITY)).thenReturn(new Long(TOKEN_VALIDITY_SEC).toString());
|
||||||
Mockito.when(config.getInitParameter(AuthenticationFilter
|
Mockito.when(config.getInitParameter(AuthenticationFilter
|
||||||
.SIGNATURE_SECRET)).thenReturn("secret");
|
.SIGNATURE_SECRET)).thenReturn("secret");
|
||||||
Mockito.when(config.getInitParameterNames()).thenReturn(new
|
Mockito.when(config.getInitParameterNames()).thenReturn(new
|
||||||
|
@ -474,8 +480,7 @@ public class TestAuthenticationFilter {
|
||||||
Signer signer = new Signer("secret".getBytes());
|
Signer signer = new Signer("secret".getBytes());
|
||||||
String value = signer.verifyAndExtract(v);
|
String value = signer.verifyAndExtract(v);
|
||||||
AuthenticationToken token = AuthenticationToken.parse(value);
|
AuthenticationToken token = AuthenticationToken.parse(value);
|
||||||
Assert.assertEquals(System.currentTimeMillis() + 1000 * 1000,
|
assertThat(token.getExpires(), not(0L));
|
||||||
token.getExpires(), 100);
|
|
||||||
|
|
||||||
if (withDomainPath) {
|
if (withDomainPath) {
|
||||||
Assert.assertEquals(".foo.com", cookieMap.get("Domain"));
|
Assert.assertEquals(".foo.com", cookieMap.get("Domain"));
|
||||||
|
@ -549,7 +554,7 @@ public class TestAuthenticationFilter {
|
||||||
Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://foo:8080/bar"));
|
Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://foo:8080/bar"));
|
||||||
|
|
||||||
AuthenticationToken token = new AuthenticationToken("u", "p", "t");
|
AuthenticationToken token = new AuthenticationToken("u", "p", "t");
|
||||||
token.setExpires(System.currentTimeMillis() + 1000);
|
token.setExpires(System.currentTimeMillis() + TOKEN_VALIDITY_SEC);
|
||||||
Signer signer = new Signer("secret".getBytes());
|
Signer signer = new Signer("secret".getBytes());
|
||||||
String tokenSigned = signer.sign(token.toString());
|
String tokenSigned = signer.sign(token.toString());
|
||||||
|
|
||||||
|
@ -599,7 +604,7 @@ public class TestAuthenticationFilter {
|
||||||
Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://foo:8080/bar"));
|
Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://foo:8080/bar"));
|
||||||
|
|
||||||
AuthenticationToken token = new AuthenticationToken("u", "p", DummyAuthenticationHandler.TYPE);
|
AuthenticationToken token = new AuthenticationToken("u", "p", DummyAuthenticationHandler.TYPE);
|
||||||
token.setExpires(System.currentTimeMillis() - 1000);
|
token.setExpires(System.currentTimeMillis() - TOKEN_VALIDITY_SEC);
|
||||||
Signer signer = new Signer("secret".getBytes());
|
Signer signer = new Signer("secret".getBytes());
|
||||||
String tokenSigned = signer.sign(token.toString());
|
String tokenSigned = signer.sign(token.toString());
|
||||||
|
|
||||||
|
@ -661,7 +666,7 @@ public class TestAuthenticationFilter {
|
||||||
Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://foo:8080/bar"));
|
Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://foo:8080/bar"));
|
||||||
|
|
||||||
AuthenticationToken token = new AuthenticationToken("u", "p", "invalidtype");
|
AuthenticationToken token = new AuthenticationToken("u", "p", "invalidtype");
|
||||||
token.setExpires(System.currentTimeMillis() + 1000);
|
token.setExpires(System.currentTimeMillis() + TOKEN_VALIDITY_SEC);
|
||||||
Signer signer = new Signer("secret".getBytes());
|
Signer signer = new Signer("secret".getBytes());
|
||||||
String tokenSigned = signer.sign(token.toString());
|
String tokenSigned = signer.sign(token.toString());
|
||||||
|
|
||||||
|
@ -708,7 +713,7 @@ public class TestAuthenticationFilter {
|
||||||
Mockito.reset(response);
|
Mockito.reset(response);
|
||||||
|
|
||||||
AuthenticationToken token = new AuthenticationToken("u", "p", "t");
|
AuthenticationToken token = new AuthenticationToken("u", "p", "t");
|
||||||
token.setExpires(System.currentTimeMillis() + 1000);
|
token.setExpires(System.currentTimeMillis() + TOKEN_VALIDITY_SEC);
|
||||||
Signer signer = new Signer("secret".getBytes());
|
Signer signer = new Signer("secret".getBytes());
|
||||||
String tokenSigned = signer.sign(token.toString());
|
String tokenSigned = signer.sign(token.toString());
|
||||||
Cookie cookie = new Cookie(AuthenticatedURL.AUTH_COOKIE, tokenSigned);
|
Cookie cookie = new Cookie(AuthenticatedURL.AUTH_COOKIE, tokenSigned);
|
||||||
|
|
|
@ -415,6 +415,8 @@ Release 2.4.0 - UNRELEASED
|
||||||
|
|
||||||
HADOOP-10395. TestCallQueueManager is flaky. (Arpit Agarwal)
|
HADOOP-10395. TestCallQueueManager is flaky. (Arpit Agarwal)
|
||||||
|
|
||||||
|
HADOOP-10394. TestAuthenticationFilter is flaky. (Arpit Agarwal)
|
||||||
|
|
||||||
BREAKDOWN OF HADOOP-10184 SUBTASKS AND RELATED JIRAS
|
BREAKDOWN OF HADOOP-10184 SUBTASKS AND RELATED JIRAS
|
||||||
|
|
||||||
HADOOP-10185. FileSystem API for ACLs. (cnauroth)
|
HADOOP-10185. FileSystem API for ACLs. (cnauroth)
|
||||||
|
|
Loading…
Reference in New Issue