use of org.neo4j.kernel.api.security.AuthSubject in project neo4j by neo4j.
the class TransactionEventsIT method shouldGetSpecifiedUsernameAndMetaDataInTXData.
@Test
public void shouldGetSpecifiedUsernameAndMetaDataInTXData() {
final AtomicReference<String> usernameRef = new AtomicReference<>();
final AtomicReference<Map<String, Object>> metaDataRef = new AtomicReference<>();
db.registerTransactionEventHandler(getBeforeCommitHandler(txData -> {
usernameRef.set(txData.username());
metaDataRef.set(txData.metaData());
}));
AuthSubject subject = mock(AuthSubject.class);
when(subject.username()).thenReturn("Christof");
SecurityContext securityContext = new SecurityContext.Frozen(subject, AccessMode.Static.WRITE);
Map<String, Object> metadata = genericMap("username", "joe");
runTransaction(securityContext, metadata);
assertThat("Should have specified username", usernameRef.get(), equalTo("Christof"));
assertThat("Should have metadata with specified username", metaDataRef.get(), equalTo(metadata));
}
Aggregations