use of org.apache.accumulo.core.client.security.tokens.NullToken in project accumulo by apache.
the class CredentialsTest method testToString.
@Test
public void testToString() {
Credentials creds = new Credentials(null, null);
assertEquals(Credentials.class.getName() + ":null:null:<hidden>", creds.toString());
creds = new Credentials("", new NullToken());
assertEquals(Credentials.class.getName() + "::" + NullToken.class.getName() + ":<hidden>", creds.toString());
creds = new Credentials("abc", null);
assertEquals(Credentials.class.getName() + ":abc:null:<hidden>", creds.toString());
creds = new Credentials("abc", new PasswordToken(""));
assertEquals(Credentials.class.getName() + ":abc:" + PasswordToken.class.getName() + ":<hidden>", creds.toString());
}
use of org.apache.accumulo.core.client.security.tokens.NullToken in project accumulo by apache.
the class CredentialsTest method testEqualsAndHashCode.
@Test
public void testEqualsAndHashCode() {
Credentials nullNullCreds = new Credentials(null, null);
Credentials abcNullCreds = new Credentials("abc", new NullToken());
Credentials cbaNullCreds = new Credentials("cba", new NullToken());
Credentials abcBlahCreds = new Credentials("abc", new PasswordToken("blah"));
// check hash codes
assertEquals(0, nullNullCreds.hashCode());
assertEquals("abc".hashCode(), abcNullCreds.hashCode());
assertEquals(abcNullCreds.hashCode(), abcBlahCreds.hashCode());
assertNotEquals(abcNullCreds.hashCode(), cbaNullCreds.hashCode());
// identity
assertEquals(abcNullCreds, abcNullCreds);
assertEquals(new Credentials("abc", new NullToken()), abcNullCreds);
// equal, but different token constructors
assertEquals(new Credentials("abc", new PasswordToken("abc".getBytes(UTF_8))), new Credentials("abc", new PasswordToken("abc")));
// test not equals
assertNotEquals(nullNullCreds, abcBlahCreds);
assertNotEquals(nullNullCreds, abcNullCreds);
assertNotEquals(abcNullCreds, abcBlahCreds);
}
use of org.apache.accumulo.core.client.security.tokens.NullToken in project accumulo by apache.
the class AuthenticationTokenTest method testSerializeDeserializeToken.
@Test
public void testSerializeDeserializeToken() {
byte[] randomBytes = new byte[12];
do {
// random fill, but avoid all zeros case
random.nextBytes(randomBytes);
} while (IntStream.range(0, randomBytes.length).allMatch(i -> randomBytes[i] == 0));
byte[] serialized = AuthenticationTokenSerializer.serialize(new PasswordToken(randomBytes));
PasswordToken passwordToken = AuthenticationTokenSerializer.deserialize(PasswordToken.class, serialized);
assertArrayEquals(randomBytes, passwordToken.getPassword());
serialized = AuthenticationTokenSerializer.serialize(new NullToken());
AuthenticationToken nullToken = AuthenticationTokenSerializer.deserialize(NullToken.class, serialized);
assertEquals(new NullToken(), nullToken);
}
Aggregations