Пример #1
0
  @Test
  public void invalidTokenThrows() {
    when(UserGroupInformation.isSecurityEnabled()).thenReturn(true);
    when(mockProtocolData.getToken()).thenReturn("This is odd");

    try {
      SecuredHDFS.verifyToken(mockProtocolData, mockContext);
      fail("invalid X-GP-TOKEN should throw");
    } catch (SecurityException e) {
      assertEquals("Failed to verify delegation token java.io.EOFException", e.getMessage());
    }
  }
Пример #2
0
  private Object getValueOfField(String fieldname, Class<?> sourceClass, Object source) {
    String sourceClassName = sourceClass.getName();

    Field field = null;
    try {
      field = sourceClass.getDeclaredField(fieldname);
      field.setAccessible(true);
    } catch (SecurityException e) {
      fail(
          "Unable to retrieve "
              + fieldname
              + " field from "
              + sourceClassName
              + ": "
              + e.getCause());
    } catch (NoSuchFieldException e) {
      fail(
          "Unable to retrieve "
              + fieldname
              + " field from "
              + sourceClassName
              + ": "
              + e.getCause());
    }

    assertNotNull("." + fieldname + " field is null!?!", field);
    Object fieldValue = null;
    try {
      fieldValue = field.get(source);
    } catch (IllegalArgumentException e) {
      fail(
          "Unable to retrieve value of "
              + fieldname
              + " from "
              + sourceClassName
              + ": "
              + e.getCause());
    } catch (IllegalAccessException e) {
      fail(
          "Unable to retrieve value of "
              + fieldname
              + " from "
              + sourceClassName
              + ": "
              + e.getCause());
    }
    return fieldValue;
  }
Пример #3
0
 public static void authenticateEndpoint(Endpoint endpoint, String user, String password) {
   try {
     Field userField = endpoint.getClass().getSuperclass().getDeclaredField("user");
     userField.setAccessible(true);
     userField.set(endpoint, user);
     Field passwordField = endpoint.getClass().getSuperclass().getDeclaredField("password");
     passwordField.setAccessible(true);
     passwordField.set(endpoint, password);
   } catch (SecurityException e) {
     fail(e.getMessage());
     e.printStackTrace();
   } catch (NoSuchFieldException e) {
     fail(e.getMessage());
     e.printStackTrace();
   } catch (IllegalArgumentException e) {
     fail(e.getMessage());
     e.printStackTrace();
   } catch (IllegalAccessException e) {
     fail(e.getMessage());
     e.printStackTrace();
   }
 }