@Test
  public void testCanValidateBadToken() {
    parameters.setToken(receivedBadToken);
    TokenValidatorResponse response = validator.validateToken(parameters);

    assertEquals(ReceivedToken.STATE.INVALID, response.getToken().getState());
  }
  @Test
  public void testCanValidateToken() {
    TokenValidatorResponse response = validator.validateToken(parameters);

    assertEquals(ReceivedToken.STATE.VALID, response.getToken().getState());

    assertThat(response.getToken().getPrincipal(), instanceOf(GuestPrincipal.class));
  }
  @Test
  public void testCanValidateBadIpToken() {
    TokenValidatorParameters params = new TokenValidatorParameters();
    params.setToken(receivedTokenBadIp);
    TokenValidatorResponse response = validator.validateToken(params);

    assertEquals(ReceivedToken.STATE.INVALID, response.getToken().getState());
  }
  @Before
  public void setup() {
    validator = new GuestValidator();
    validator.setSupportedRealm(Arrays.asList("DDF"));
    GuestAuthenticationToken guestAuthenticationToken =
        new GuestAuthenticationToken("DDF", "127.0.0.1");

    GuestAuthenticationToken guestAuthenticationTokenAnyRealm =
        new GuestAuthenticationToken("*", "127.0.0.1");

    GuestAuthenticationToken guestAuthenticationTokenIpv6 =
        new GuestAuthenticationToken("*", "0:0:0:0:0:0:0:1");

    GuestAuthenticationToken guestAuthenticationTokenBadIp =
        new GuestAuthenticationToken("*", "123.abc.45.def");

    BinarySecurityTokenType binarySecurityTokenType = new BinarySecurityTokenType();
    binarySecurityTokenType.setValueType(GuestAuthenticationToken.GUEST_TOKEN_VALUE_TYPE);
    binarySecurityTokenType.setEncodingType(BSTAuthenticationToken.BASE64_ENCODING);
    binarySecurityTokenType.setId(GuestAuthenticationToken.BST_GUEST_LN);
    binarySecurityTokenType.setValue(guestAuthenticationToken.getEncodedCredentials());
    JAXBElement<BinarySecurityTokenType> binarySecurityTokenElement =
        new JAXBElement<BinarySecurityTokenType>(
            new QName(
                "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
                "BinarySecurityToken"),
            BinarySecurityTokenType.class,
            binarySecurityTokenType);

    BinarySecurityTokenType binarySecurityTokenType2 = new BinarySecurityTokenType();
    binarySecurityTokenType2.setValueType(GuestAuthenticationToken.GUEST_TOKEN_VALUE_TYPE);
    binarySecurityTokenType2.setEncodingType(BSTAuthenticationToken.BASE64_ENCODING);
    binarySecurityTokenType2.setId(GuestAuthenticationToken.BST_GUEST_LN);
    binarySecurityTokenType2.setValue(
        Base64.encodeBytes("NotGuest".getBytes(), Base64.DONT_BREAK_LINES));
    JAXBElement<BinarySecurityTokenType> binarySecurityTokenElement2 =
        new JAXBElement<BinarySecurityTokenType>(
            new QName(
                "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
                "BinarySecurityToken"),
            BinarySecurityTokenType.class,
            binarySecurityTokenType2);

    BinarySecurityTokenType binarySecurityTokenType3 = new BinarySecurityTokenType();
    binarySecurityTokenType3.setValueType(GuestAuthenticationToken.GUEST_TOKEN_VALUE_TYPE);
    binarySecurityTokenType3.setEncodingType(BSTAuthenticationToken.BASE64_ENCODING);
    binarySecurityTokenType3.setId(GuestAuthenticationToken.BST_GUEST_LN);
    binarySecurityTokenType3.setValue(guestAuthenticationTokenAnyRealm.getEncodedCredentials());
    JAXBElement<BinarySecurityTokenType> binarySecurityTokenElement3 =
        new JAXBElement<BinarySecurityTokenType>(
            new QName(
                "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
                "BinarySecurityToken"),
            BinarySecurityTokenType.class,
            binarySecurityTokenType3);

    BinarySecurityTokenType binarySecurityTokenType4 = new BinarySecurityTokenType();
    binarySecurityTokenType4.setValueType(GuestAuthenticationToken.GUEST_TOKEN_VALUE_TYPE);
    binarySecurityTokenType4.setEncodingType(BSTAuthenticationToken.BASE64_ENCODING);
    binarySecurityTokenType4.setId(GuestAuthenticationToken.BST_GUEST_LN);
    binarySecurityTokenType4.setValue(guestAuthenticationTokenIpv6.getEncodedCredentials());
    JAXBElement<BinarySecurityTokenType> binarySecurityTokenElement4 =
        new JAXBElement<BinarySecurityTokenType>(
            new QName(
                "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
                "BinarySecurityToken"),
            BinarySecurityTokenType.class,
            binarySecurityTokenType4);

    BinarySecurityTokenType binarySecurityTokenType5 = new BinarySecurityTokenType();
    binarySecurityTokenType5.setValueType(GuestAuthenticationToken.GUEST_TOKEN_VALUE_TYPE);
    binarySecurityTokenType5.setEncodingType(BSTAuthenticationToken.BASE64_ENCODING);
    binarySecurityTokenType5.setId(GuestAuthenticationToken.BST_GUEST_LN);
    binarySecurityTokenType5.setValue(guestAuthenticationTokenBadIp.getEncodedCredentials());
    JAXBElement<BinarySecurityTokenType> binarySecurityTokenElement5 =
        new JAXBElement<BinarySecurityTokenType>(
            new QName(
                "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
                "BinarySecurityToken"),
            BinarySecurityTokenType.class,
            binarySecurityTokenType5);

    receivedToken = new ReceivedToken(binarySecurityTokenElement);
    receivedAnyRealmToken = new ReceivedToken(binarySecurityTokenElement3);
    receivedBadToken = new ReceivedToken(binarySecurityTokenElement2);
    receivedTokenIpv6 = new ReceivedToken(binarySecurityTokenElement4);
    receivedTokenBadIp = new ReceivedToken(binarySecurityTokenElement5);
    parameters = new TokenValidatorParameters();
    parameters.setToken(receivedToken);
  }
  @Test
  public void testCanHandleAnyRealmToken() throws JAXBException {
    boolean canHandle = validator.canHandleToken(receivedAnyRealmToken);

    assertTrue(canHandle);
  }