use of org.neo4j.internal.kernel.api.connectioninfo.ClientConnectionInfo.EMBEDDED_CONNECTION in project neo4j by neo4j.
the class TransactionEventsIT method shouldGetSpecifiedUsernameAndMetaDataInTXData.
@Test
void shouldGetSpecifiedUsernameAndMetaDataInTXData() {
final AtomicReference<String> usernameRef = new AtomicReference<>();
final AtomicReference<Map<String, Object>> metaDataRef = new AtomicReference<>();
dbms.registerTransactionEventListener(DEFAULT_DATABASE_NAME, getBeforeCommitListener(txData -> {
usernameRef.set(txData.username());
metaDataRef.set(txData.metaData());
}));
AuthSubject subject = mock(AuthSubject.class);
when(subject.username()).thenReturn("Christof");
LoginContext loginContext = new LoginContext(subject, EMBEDDED_CONNECTION) {
@Override
public SecurityContext authorize(IdLookup idLookup, String dbName, AbstractSecurityLog securityLog) {
return new SecurityContext(subject, AccessMode.Static.WRITE, EMBEDDED_CONNECTION, dbName);
}
};
Map<String, Object> metadata = genericMap("username", "joe");
runTransaction(loginContext, metadata);
assertThat(usernameRef.get()).as("Should have specified username").isEqualTo("Christof");
assertThat(metaDataRef.get()).as("Should have metadata with specified username").isEqualTo(metadata);
}
Aggregations