use of io.crate.user.SecureHash in project crate by crate.
the class UserDefinitions method getSecureHash.
private static SecureHash getSecureHash(String password) {
SecureHash hash = null;
try {
hash = SecureHash.of(new SecureString(password.toCharArray()));
} catch (GeneralSecurityException e) {
// do nothing;
}
assertNotNull(hash);
return hash;
}
use of io.crate.user.SecureHash in project crate by crate.
the class SecureHashTest method testVerifyHash.
@Test
public void testVerifyHash() throws Exception {
SecureHash hash = SecureHash.of(PASSWORD);
assertTrue(hash.verifyHash(PASSWORD));
assertFalse(hash.verifyHash(INVALID_PASSWORD));
}
use of io.crate.user.SecureHash in project crate by crate.
the class UsersMetadataTest method testUsersMetadataFromLegacyXContent.
@Test
public void testUsersMetadataFromLegacyXContent() throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder();
// Generate legacy (v1) XContent of UsersMetadata
// { "users": [ "Ford", "Arthur" ] }
builder.startObject();
builder.startArray("users");
builder.value("Ford");
builder.value("Arthur");
builder.endArray();
builder.endObject();
HashMap<String, SecureHash> expectedUsers = new HashMap<>();
expectedUsers.put("Ford", null);
expectedUsers.put("Arthur", null);
XContentParser parser = JsonXContent.JSON_XCONTENT.createParser(xContentRegistry(), DeprecationHandler.THROW_UNSUPPORTED_OPERATION, Strings.toString(builder));
// start object
parser.nextToken();
UsersMetadata users = UsersMetadata.fromXContent(parser);
assertEquals(users, new UsersMetadata(expectedUsers));
// a metadata custom must consume the surrounded END_OBJECT token, no token must be left
assertThat(parser.nextToken(), nullValue());
}
Aggregations