Java 类org.apache.hadoop.fs.http.client.HttpFSKerberosAuthenticator.DelegationTokenOperation 实例源码

项目:hadoop-plus    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testManagementOperationErrors(AuthenticationHandler handler)
  throws Exception {
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
    thenReturn(DelegationTokenOperation.GETDELEGATIONTOKEN.toString());
  Mockito.when(request.getMethod()).thenReturn("FOO");
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
    Mockito.startsWith("Wrong HTTP method"));

  Mockito.reset(response);
  Mockito.when(request.getMethod()).
    thenReturn(DelegationTokenOperation.GETDELEGATIONTOKEN.getHttpMethod());
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_UNAUTHORIZED),
    Mockito.contains("requires SPNEGO"));
}
项目:hops    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testManagementOperationErrors(AuthenticationHandler handler)
    throws Exception {
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
      thenReturn(DelegationTokenOperation.GETDELEGATIONTOKEN.toString());
  Mockito.when(request.getMethod()).thenReturn("FOO");
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response)
      .sendError(Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
          Mockito.startsWith("Wrong HTTP method"));

  Mockito.reset(response);
  Mockito.when(request.getMethod()).
      thenReturn(DelegationTokenOperation.GETDELEGATIONTOKEN.getHttpMethod());
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response)
      .sendError(Mockito.eq(HttpServletResponse.SC_UNAUTHORIZED),
          Mockito.contains("requires SPNEGO"));
}
项目:hadoop-TCP    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testManagementOperationErrors(AuthenticationHandler handler)
  throws Exception {
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
    thenReturn(DelegationTokenOperation.GETDELEGATIONTOKEN.toString());
  Mockito.when(request.getMethod()).thenReturn("FOO");
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
    Mockito.startsWith("Wrong HTTP method"));

  Mockito.reset(response);
  Mockito.when(request.getMethod()).
    thenReturn(DelegationTokenOperation.GETDELEGATIONTOKEN.getHttpMethod());
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_UNAUTHORIZED),
    Mockito.contains("requires SPNEGO"));
}
项目:hardfs    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testManagementOperationErrors(AuthenticationHandler handler)
  throws Exception {
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
    thenReturn(DelegationTokenOperation.GETDELEGATIONTOKEN.toString());
  Mockito.when(request.getMethod()).thenReturn("FOO");
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
    Mockito.startsWith("Wrong HTTP method"));

  Mockito.reset(response);
  Mockito.when(request.getMethod()).
    thenReturn(DelegationTokenOperation.GETDELEGATIONTOKEN.getHttpMethod());
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_UNAUTHORIZED),
    Mockito.contains("requires SPNEGO"));
}
项目:hadoop-on-lustre2    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testManagementOperationErrors(AuthenticationHandler handler)
  throws Exception {
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
    thenReturn(DelegationTokenOperation.GETDELEGATIONTOKEN.toString());
  Mockito.when(request.getMethod()).thenReturn("FOO");
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
    Mockito.startsWith("Wrong HTTP method"));

  Mockito.reset(response);
  Mockito.when(request.getMethod()).
    thenReturn(DelegationTokenOperation.GETDELEGATIONTOKEN.getHttpMethod());
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_UNAUTHORIZED),
    Mockito.contains("requires SPNEGO"));
}
项目:hadoop-plus    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testCancelToken(AuthenticationHandler handler)
  throws Exception {
  DelegationTokenOperation op =
    DelegationTokenOperation.CANCELDELEGATIONTOKEN;
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
    thenReturn(op.toString());
  Mockito.when(request.getMethod()).
    thenReturn(op.getHttpMethod());

  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
    Mockito.contains("requires the parameter [token]"));

  Mockito.reset(response);
  Token<DelegationTokenIdentifier> token =
    HttpFSServerWebApp.get().get(DelegationTokenManager.class).createToken(
      UserGroupInformation.getCurrentUser(), "foo");
  Mockito.when(request.getParameter(HttpFSKerberosAuthenticator.TOKEN_PARAM)).
    thenReturn(token.encodeToUrlString());
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
  try {
    HttpFSServerWebApp.get().get(DelegationTokenManager.class).verifyToken(token);
    Assert.fail();
  }
  catch (DelegationTokenManagerException ex) {
    Assert.assertTrue(ex.toString().contains("DT01"));
  }
}
项目:hadoop-plus    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testRenewToken(AuthenticationHandler handler)
  throws Exception {
  DelegationTokenOperation op =
    DelegationTokenOperation.RENEWDELEGATIONTOKEN;
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
    thenReturn(op.toString());
  Mockito.when(request.getMethod()).
    thenReturn(op.getHttpMethod());

  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_UNAUTHORIZED),
    Mockito.contains("equires SPNEGO authentication established"));

  Mockito.reset(response);
  AuthenticationToken token = Mockito.mock(AuthenticationToken.class);
  Mockito.when(token.getUserName()).thenReturn("user");
  Assert.assertFalse(handler.managementOperation(token, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
    Mockito.contains("requires the parameter [token]"));

  Mockito.reset(response);
  StringWriter writer = new StringWriter();
  PrintWriter pwriter = new PrintWriter(writer);
  Mockito.when(response.getWriter()).thenReturn(pwriter);
  Token<DelegationTokenIdentifier> dToken =
    HttpFSServerWebApp.get().get(DelegationTokenManager.class).createToken(
      UserGroupInformation.getCurrentUser(), "user");
  Mockito.when(request.getParameter(HttpFSKerberosAuthenticator.TOKEN_PARAM)).
    thenReturn(dToken.encodeToUrlString());
  Assert.assertFalse(handler.managementOperation(token, request, response));
  Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
  pwriter.close();
  Assert.assertTrue(writer.toString().contains("long"));
  HttpFSServerWebApp.get().get(DelegationTokenManager.class).verifyToken(dToken);
}
项目:hops    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testCancelToken(AuthenticationHandler handler) throws Exception {
  DelegationTokenOperation op =
      DelegationTokenOperation.CANCELDELEGATIONTOKEN;
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
      thenReturn(op.toString());
  Mockito.when(request.getMethod()).
      thenReturn(op.getHttpMethod());

  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response)
      .sendError(Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
          Mockito.contains("requires the parameter [token]"));

  Mockito.reset(response);
  Token<DelegationTokenIdentifier> token =
      HttpFSServerWebApp.get().get(DelegationTokenManager.class)
          .createToken(UserGroupInformation.getCurrentUser(), "foo");
  Mockito.when(request.getParameter(HttpFSKerberosAuthenticator.TOKEN_PARAM)).
      thenReturn(token.encodeToUrlString());
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
  try {
    HttpFSServerWebApp.get().get(DelegationTokenManager.class)
        .verifyToken(token);
    Assert.fail();
  } catch (DelegationTokenManagerException ex) {
    Assert.assertTrue(ex.toString().contains("DT01"));
  }
}
项目:hops    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testRenewToken(AuthenticationHandler handler) throws Exception {
  DelegationTokenOperation op = DelegationTokenOperation.RENEWDELEGATIONTOKEN;
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
      thenReturn(op.toString());
  Mockito.when(request.getMethod()).
      thenReturn(op.getHttpMethod());

  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response)
      .sendError(Mockito.eq(HttpServletResponse.SC_UNAUTHORIZED),
          Mockito.contains("equires SPNEGO authentication established"));

  Mockito.reset(response);
  AuthenticationToken token = Mockito.mock(AuthenticationToken.class);
  Mockito.when(token.getUserName()).thenReturn("user");
  Assert.assertFalse(handler.managementOperation(token, request, response));
  Mockito.verify(response)
      .sendError(Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
          Mockito.contains("requires the parameter [token]"));

  Mockito.reset(response);
  StringWriter writer = new StringWriter();
  PrintWriter pwriter = new PrintWriter(writer);
  Mockito.when(response.getWriter()).thenReturn(pwriter);
  Token<DelegationTokenIdentifier> dToken =
      HttpFSServerWebApp.get().get(DelegationTokenManager.class)
          .createToken(UserGroupInformation.getCurrentUser(), "user");
  Mockito.when(request.getParameter(HttpFSKerberosAuthenticator.TOKEN_PARAM)).
      thenReturn(dToken.encodeToUrlString());
  Assert.assertFalse(handler.managementOperation(token, request, response));
  Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
  pwriter.close();
  Assert.assertTrue(writer.toString().contains("long"));
  HttpFSServerWebApp.get().get(DelegationTokenManager.class)
      .verifyToken(dToken);
}
项目:hadoop-TCP    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testCancelToken(AuthenticationHandler handler)
  throws Exception {
  DelegationTokenOperation op =
    DelegationTokenOperation.CANCELDELEGATIONTOKEN;
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
    thenReturn(op.toString());
  Mockito.when(request.getMethod()).
    thenReturn(op.getHttpMethod());

  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
    Mockito.contains("requires the parameter [token]"));

  Mockito.reset(response);
  Token<DelegationTokenIdentifier> token =
    HttpFSServerWebApp.get().get(DelegationTokenManager.class).createToken(
      UserGroupInformation.getCurrentUser(), "foo");
  Mockito.when(request.getParameter(HttpFSKerberosAuthenticator.TOKEN_PARAM)).
    thenReturn(token.encodeToUrlString());
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
  try {
    HttpFSServerWebApp.get().get(DelegationTokenManager.class).verifyToken(token);
    Assert.fail();
  }
  catch (DelegationTokenManagerException ex) {
    Assert.assertTrue(ex.toString().contains("DT01"));
  }
}
项目:hadoop-TCP    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testRenewToken(AuthenticationHandler handler)
  throws Exception {
  DelegationTokenOperation op =
    DelegationTokenOperation.RENEWDELEGATIONTOKEN;
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
    thenReturn(op.toString());
  Mockito.when(request.getMethod()).
    thenReturn(op.getHttpMethod());

  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_UNAUTHORIZED),
    Mockito.contains("equires SPNEGO authentication established"));

  Mockito.reset(response);
  AuthenticationToken token = Mockito.mock(AuthenticationToken.class);
  Mockito.when(token.getUserName()).thenReturn("user");
  Assert.assertFalse(handler.managementOperation(token, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
    Mockito.contains("requires the parameter [token]"));

  Mockito.reset(response);
  StringWriter writer = new StringWriter();
  PrintWriter pwriter = new PrintWriter(writer);
  Mockito.when(response.getWriter()).thenReturn(pwriter);
  Token<DelegationTokenIdentifier> dToken =
    HttpFSServerWebApp.get().get(DelegationTokenManager.class).createToken(
      UserGroupInformation.getCurrentUser(), "user");
  Mockito.when(request.getParameter(HttpFSKerberosAuthenticator.TOKEN_PARAM)).
    thenReturn(dToken.encodeToUrlString());
  Assert.assertFalse(handler.managementOperation(token, request, response));
  Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
  pwriter.close();
  Assert.assertTrue(writer.toString().contains("long"));
  HttpFSServerWebApp.get().get(DelegationTokenManager.class).verifyToken(dToken);
}
项目:hardfs    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testCancelToken(AuthenticationHandler handler)
  throws Exception {
  DelegationTokenOperation op =
    DelegationTokenOperation.CANCELDELEGATIONTOKEN;
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
    thenReturn(op.toString());
  Mockito.when(request.getMethod()).
    thenReturn(op.getHttpMethod());

  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
    Mockito.contains("requires the parameter [token]"));

  Mockito.reset(response);
  Token<DelegationTokenIdentifier> token =
    HttpFSServerWebApp.get().get(DelegationTokenManager.class).createToken(
      UserGroupInformation.getCurrentUser(), "foo");
  Mockito.when(request.getParameter(HttpFSKerberosAuthenticator.TOKEN_PARAM)).
    thenReturn(token.encodeToUrlString());
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
  try {
    HttpFSServerWebApp.get().get(DelegationTokenManager.class).verifyToken(token);
    Assert.fail();
  }
  catch (DelegationTokenManagerException ex) {
    Assert.assertTrue(ex.toString().contains("DT01"));
  }
}
项目:hardfs    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testRenewToken(AuthenticationHandler handler)
  throws Exception {
  DelegationTokenOperation op =
    DelegationTokenOperation.RENEWDELEGATIONTOKEN;
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
    thenReturn(op.toString());
  Mockito.when(request.getMethod()).
    thenReturn(op.getHttpMethod());

  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_UNAUTHORIZED),
    Mockito.contains("equires SPNEGO authentication established"));

  Mockito.reset(response);
  AuthenticationToken token = Mockito.mock(AuthenticationToken.class);
  Mockito.when(token.getUserName()).thenReturn("user");
  Assert.assertFalse(handler.managementOperation(token, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
    Mockito.contains("requires the parameter [token]"));

  Mockito.reset(response);
  StringWriter writer = new StringWriter();
  PrintWriter pwriter = new PrintWriter(writer);
  Mockito.when(response.getWriter()).thenReturn(pwriter);
  Token<DelegationTokenIdentifier> dToken =
    HttpFSServerWebApp.get().get(DelegationTokenManager.class).createToken(
      UserGroupInformation.getCurrentUser(), "user");
  Mockito.when(request.getParameter(HttpFSKerberosAuthenticator.TOKEN_PARAM)).
    thenReturn(dToken.encodeToUrlString());
  Assert.assertFalse(handler.managementOperation(token, request, response));
  Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
  pwriter.close();
  Assert.assertTrue(writer.toString().contains("long"));
  HttpFSServerWebApp.get().get(DelegationTokenManager.class).verifyToken(dToken);
}
项目:hadoop-on-lustre2    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testCancelToken(AuthenticationHandler handler)
  throws Exception {
  DelegationTokenOperation op =
    DelegationTokenOperation.CANCELDELEGATIONTOKEN;
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
    thenReturn(op.toString());
  Mockito.when(request.getMethod()).
    thenReturn(op.getHttpMethod());

  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
    Mockito.contains("requires the parameter [token]"));

  Mockito.reset(response);
  Token<DelegationTokenIdentifier> token =
    HttpFSServerWebApp.get().get(DelegationTokenManager.class).createToken(
      UserGroupInformation.getCurrentUser(), "foo");
  Mockito.when(request.getParameter(HttpFSKerberosAuthenticator.TOKEN_PARAM)).
    thenReturn(token.encodeToUrlString());
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
  try {
    HttpFSServerWebApp.get().get(DelegationTokenManager.class).verifyToken(token);
    Assert.fail();
  }
  catch (DelegationTokenManagerException ex) {
    Assert.assertTrue(ex.toString().contains("DT01"));
  }
}
项目:hadoop-on-lustre2    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testRenewToken(AuthenticationHandler handler)
  throws Exception {
  DelegationTokenOperation op =
    DelegationTokenOperation.RENEWDELEGATIONTOKEN;
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
    thenReturn(op.toString());
  Mockito.when(request.getMethod()).
    thenReturn(op.getHttpMethod());

  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_UNAUTHORIZED),
    Mockito.contains("equires SPNEGO authentication established"));

  Mockito.reset(response);
  AuthenticationToken token = Mockito.mock(AuthenticationToken.class);
  Mockito.when(token.getUserName()).thenReturn("user");
  Assert.assertFalse(handler.managementOperation(token, request, response));
  Mockito.verify(response).sendError(
    Mockito.eq(HttpServletResponse.SC_BAD_REQUEST),
    Mockito.contains("requires the parameter [token]"));

  Mockito.reset(response);
  StringWriter writer = new StringWriter();
  PrintWriter pwriter = new PrintWriter(writer);
  Mockito.when(response.getWriter()).thenReturn(pwriter);
  Token<DelegationTokenIdentifier> dToken =
    HttpFSServerWebApp.get().get(DelegationTokenManager.class).createToken(
      UserGroupInformation.getCurrentUser(), "user");
  Mockito.when(request.getParameter(HttpFSKerberosAuthenticator.TOKEN_PARAM)).
    thenReturn(dToken.encodeToUrlString());
  Assert.assertFalse(handler.managementOperation(token, request, response));
  Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
  pwriter.close();
  Assert.assertTrue(writer.toString().contains("long"));
  HttpFSServerWebApp.get().get(DelegationTokenManager.class).verifyToken(dToken);
}
项目:hadoop-plus    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testGetToken(AuthenticationHandler handler, String renewer)
  throws Exception {
  DelegationTokenOperation op = DelegationTokenOperation.GETDELEGATIONTOKEN;
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
    thenReturn(op.toString());
  Mockito.when(request.getMethod()).
    thenReturn(op.getHttpMethod());

  AuthenticationToken token = Mockito.mock(AuthenticationToken.class);
  Mockito.when(token.getUserName()).thenReturn("user");
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.when(request.getParameter(HttpFSKerberosAuthenticator.RENEWER_PARAM)).
    thenReturn(renewer);

  Mockito.reset(response);
  StringWriter writer = new StringWriter();
  PrintWriter pwriter = new PrintWriter(writer);
  Mockito.when(response.getWriter()).thenReturn(pwriter);
  Assert.assertFalse(handler.managementOperation(token, request, response));
  if (renewer == null) {
    Mockito.verify(token).getUserName();
  } else {
    Mockito.verify(token, Mockito.never()).getUserName();
  }
  Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
  Mockito.verify(response).setContentType(MediaType.APPLICATION_JSON);
  pwriter.close();
  String responseOutput = writer.toString();
  String tokenLabel = HttpFSKerberosAuthenticator.DELEGATION_TOKEN_JSON;
  Assert.assertTrue(responseOutput.contains(tokenLabel));
  Assert.assertTrue(responseOutput.contains(
    HttpFSKerberosAuthenticator.DELEGATION_TOKEN_URL_STRING_JSON));
  JSONObject json = (JSONObject) new JSONParser().parse(responseOutput);
  json = (JSONObject) json.get(tokenLabel);
  String tokenStr;
  tokenStr = (String)
    json.get(HttpFSKerberosAuthenticator.DELEGATION_TOKEN_URL_STRING_JSON);
  Token<DelegationTokenIdentifier> dt = new Token<DelegationTokenIdentifier>();
  dt.decodeFromUrlString(tokenStr);
  HttpFSServerWebApp.get().get(DelegationTokenManager.class).verifyToken(dt);
}
项目:hops    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testGetToken(AuthenticationHandler handler, String renewer)
    throws Exception {
  DelegationTokenOperation op = DelegationTokenOperation.GETDELEGATIONTOKEN;
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
      thenReturn(op.toString());
  Mockito.when(request.getMethod()).
      thenReturn(op.getHttpMethod());

  AuthenticationToken token = Mockito.mock(AuthenticationToken.class);
  Mockito.when(token.getUserName()).thenReturn("user");
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito
      .when(request.getParameter(HttpFSKerberosAuthenticator.RENEWER_PARAM)).
      thenReturn(renewer);

  Mockito.reset(response);
  StringWriter writer = new StringWriter();
  PrintWriter pwriter = new PrintWriter(writer);
  Mockito.when(response.getWriter()).thenReturn(pwriter);
  Assert.assertFalse(handler.managementOperation(token, request, response));
  if (renewer == null) {
    Mockito.verify(token).getUserName();
  } else {
    Mockito.verify(token, Mockito.never()).getUserName();
  }
  Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
  Mockito.verify(response).setContentType(MediaType.APPLICATION_JSON);
  pwriter.close();
  String responseOutput = writer.toString();
  String tokenLabel = HttpFSKerberosAuthenticator.DELEGATION_TOKEN_JSON;
  Assert.assertTrue(responseOutput.contains(tokenLabel));
  Assert.assertTrue(responseOutput.contains(
      HttpFSKerberosAuthenticator.DELEGATION_TOKEN_URL_STRING_JSON));
  JSONObject json = (JSONObject) new JSONParser().parse(responseOutput);
  json = (JSONObject) json.get(tokenLabel);
  String tokenStr;
  tokenStr = (String) json
      .get(HttpFSKerberosAuthenticator.DELEGATION_TOKEN_URL_STRING_JSON);
  Token<DelegationTokenIdentifier> dt =
      new Token<>();
  dt.decodeFromUrlString(tokenStr);
  HttpFSServerWebApp.get().get(DelegationTokenManager.class).verifyToken(dt);
}
项目:hadoop-TCP    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testGetToken(AuthenticationHandler handler, String renewer)
  throws Exception {
  DelegationTokenOperation op = DelegationTokenOperation.GETDELEGATIONTOKEN;
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
    thenReturn(op.toString());
  Mockito.when(request.getMethod()).
    thenReturn(op.getHttpMethod());

  AuthenticationToken token = Mockito.mock(AuthenticationToken.class);
  Mockito.when(token.getUserName()).thenReturn("user");
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.when(request.getParameter(HttpFSKerberosAuthenticator.RENEWER_PARAM)).
    thenReturn(renewer);

  Mockito.reset(response);
  StringWriter writer = new StringWriter();
  PrintWriter pwriter = new PrintWriter(writer);
  Mockito.when(response.getWriter()).thenReturn(pwriter);
  Assert.assertFalse(handler.managementOperation(token, request, response));
  if (renewer == null) {
    Mockito.verify(token).getUserName();
  } else {
    Mockito.verify(token, Mockito.never()).getUserName();
  }
  Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
  Mockito.verify(response).setContentType(MediaType.APPLICATION_JSON);
  pwriter.close();
  String responseOutput = writer.toString();
  String tokenLabel = HttpFSKerberosAuthenticator.DELEGATION_TOKEN_JSON;
  Assert.assertTrue(responseOutput.contains(tokenLabel));
  Assert.assertTrue(responseOutput.contains(
    HttpFSKerberosAuthenticator.DELEGATION_TOKEN_URL_STRING_JSON));
  JSONObject json = (JSONObject) new JSONParser().parse(responseOutput);
  json = (JSONObject) json.get(tokenLabel);
  String tokenStr;
  tokenStr = (String)
    json.get(HttpFSKerberosAuthenticator.DELEGATION_TOKEN_URL_STRING_JSON);
  Token<DelegationTokenIdentifier> dt = new Token<DelegationTokenIdentifier>();
  dt.decodeFromUrlString(tokenStr);
  HttpFSServerWebApp.get().get(DelegationTokenManager.class).verifyToken(dt);
}
项目:hardfs    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testGetToken(AuthenticationHandler handler, String renewer)
  throws Exception {
  DelegationTokenOperation op = DelegationTokenOperation.GETDELEGATIONTOKEN;
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
    thenReturn(op.toString());
  Mockito.when(request.getMethod()).
    thenReturn(op.getHttpMethod());

  AuthenticationToken token = Mockito.mock(AuthenticationToken.class);
  Mockito.when(token.getUserName()).thenReturn("user");
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.when(request.getParameter(HttpFSKerberosAuthenticator.RENEWER_PARAM)).
    thenReturn(renewer);

  Mockito.reset(response);
  StringWriter writer = new StringWriter();
  PrintWriter pwriter = new PrintWriter(writer);
  Mockito.when(response.getWriter()).thenReturn(pwriter);
  Assert.assertFalse(handler.managementOperation(token, request, response));
  if (renewer == null) {
    Mockito.verify(token).getUserName();
  } else {
    Mockito.verify(token, Mockito.never()).getUserName();
  }
  Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
  Mockito.verify(response).setContentType(MediaType.APPLICATION_JSON);
  pwriter.close();
  String responseOutput = writer.toString();
  String tokenLabel = HttpFSKerberosAuthenticator.DELEGATION_TOKEN_JSON;
  Assert.assertTrue(responseOutput.contains(tokenLabel));
  Assert.assertTrue(responseOutput.contains(
    HttpFSKerberosAuthenticator.DELEGATION_TOKEN_URL_STRING_JSON));
  JSONObject json = (JSONObject) new JSONParser().parse(responseOutput);
  json = (JSONObject) json.get(tokenLabel);
  String tokenStr;
  tokenStr = (String)
    json.get(HttpFSKerberosAuthenticator.DELEGATION_TOKEN_URL_STRING_JSON);
  Token<DelegationTokenIdentifier> dt = new Token<DelegationTokenIdentifier>();
  dt.decodeFromUrlString(tokenStr);
  HttpFSServerWebApp.get().get(DelegationTokenManager.class).verifyToken(dt);
}
项目:hadoop-on-lustre2    文件:TestHttpFSKerberosAuthenticationHandler.java   
private void testGetToken(AuthenticationHandler handler, String renewer,
    Text expectedTokenKind) throws Exception {
  DelegationTokenOperation op = DelegationTokenOperation.GETDELEGATIONTOKEN;
  HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
  HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
  Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).
    thenReturn(op.toString());
  Mockito.when(request.getMethod()).
    thenReturn(op.getHttpMethod());

  AuthenticationToken token = Mockito.mock(AuthenticationToken.class);
  Mockito.when(token.getUserName()).thenReturn("user");
  Assert.assertFalse(handler.managementOperation(null, request, response));
  Mockito.when(request.getParameter(HttpFSKerberosAuthenticator.RENEWER_PARAM)).
    thenReturn(renewer);

  Mockito.reset(response);
  StringWriter writer = new StringWriter();
  PrintWriter pwriter = new PrintWriter(writer);
  Mockito.when(response.getWriter()).thenReturn(pwriter);
  Assert.assertFalse(handler.managementOperation(token, request, response));
  if (renewer == null) {
    Mockito.verify(token).getUserName();
  } else {
    Mockito.verify(token, Mockito.never()).getUserName();
  }
  Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
  Mockito.verify(response).setContentType(MediaType.APPLICATION_JSON);
  pwriter.close();
  String responseOutput = writer.toString();
  String tokenLabel = HttpFSKerberosAuthenticator.DELEGATION_TOKEN_JSON;
  Assert.assertTrue(responseOutput.contains(tokenLabel));
  Assert.assertTrue(responseOutput.contains(
    HttpFSKerberosAuthenticator.DELEGATION_TOKEN_URL_STRING_JSON));
  JSONObject json = (JSONObject) new JSONParser().parse(responseOutput);
  json = (JSONObject) json.get(tokenLabel);
  String tokenStr;
  tokenStr = (String)
    json.get(HttpFSKerberosAuthenticator.DELEGATION_TOKEN_URL_STRING_JSON);
  Token<DelegationTokenIdentifier> dt = new Token<DelegationTokenIdentifier>();
  dt.decodeFromUrlString(tokenStr);
  HttpFSServerWebApp.get().get(DelegationTokenManager.class).verifyToken(dt);
  Assert.assertEquals(expectedTokenKind, dt.getKind());
}