|
|
@ -26,6 +26,7 @@ import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.io.TempDir;
|
|
|
|
import org.junit.jupiter.api.io.TempDir;
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
|
|
import org.junit.jupiter.params.provider.ValueSource;
|
|
|
|
import org.junit.jupiter.params.provider.ValueSource;
|
|
|
|
|
|
|
|
import org.neo4j.driver.AuthTokenManagers;
|
|
|
|
import org.neo4j.driver.AuthTokens;
|
|
|
|
import org.neo4j.driver.AuthTokens;
|
|
|
|
import org.neo4j.driver.Config;
|
|
|
|
import org.neo4j.driver.Config;
|
|
|
|
import org.neo4j.driver.Config.ConfigBuilder;
|
|
|
|
import org.neo4j.driver.Config.ConfigBuilder;
|
|
|
@ -143,7 +144,7 @@ class Neo4jAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void uriShouldDefaultToLocalhost() {
|
|
|
|
void uriShouldDefaultToLocalhost() {
|
|
|
|
assertThat(new PropertiesNeo4jConnectionDetails(new Neo4jProperties()).getUri())
|
|
|
|
assertThat(new PropertiesNeo4jConnectionDetails(new Neo4jProperties(), null).getUri())
|
|
|
|
.isEqualTo(URI.create("bolt://localhost:7687"));
|
|
|
|
.isEqualTo(URI.create("bolt://localhost:7687"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -152,12 +153,12 @@ class Neo4jAutoConfigurationTests {
|
|
|
|
URI customUri = URI.create("bolt://localhost:4242");
|
|
|
|
URI customUri = URI.create("bolt://localhost:4242");
|
|
|
|
Neo4jProperties properties = new Neo4jProperties();
|
|
|
|
Neo4jProperties properties = new Neo4jProperties();
|
|
|
|
properties.setUri(customUri);
|
|
|
|
properties.setUri(customUri);
|
|
|
|
assertThat(new PropertiesNeo4jConnectionDetails(properties).getUri()).isEqualTo(customUri);
|
|
|
|
assertThat(new PropertiesNeo4jConnectionDetails(properties, null).getUri()).isEqualTo(customUri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void authenticationShouldDefaultToNone() {
|
|
|
|
void authenticationShouldDefaultToNone() {
|
|
|
|
assertThat(new PropertiesNeo4jConnectionDetails(new Neo4jProperties()).getAuthToken())
|
|
|
|
assertThat(new PropertiesNeo4jConnectionDetails(new Neo4jProperties(), null).getAuthToken())
|
|
|
|
.isEqualTo(AuthTokens.none());
|
|
|
|
.isEqualTo(AuthTokens.none());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -166,8 +167,9 @@ class Neo4jAutoConfigurationTests {
|
|
|
|
Neo4jProperties properties = new Neo4jProperties();
|
|
|
|
Neo4jProperties properties = new Neo4jProperties();
|
|
|
|
properties.getAuthentication().setUsername("Farin");
|
|
|
|
properties.getAuthentication().setUsername("Farin");
|
|
|
|
properties.getAuthentication().setPassword("Urlaub");
|
|
|
|
properties.getAuthentication().setPassword("Urlaub");
|
|
|
|
assertThat(new PropertiesNeo4jConnectionDetails(properties).getAuthToken())
|
|
|
|
PropertiesNeo4jConnectionDetails connectionDetails = new PropertiesNeo4jConnectionDetails(properties, null);
|
|
|
|
.isEqualTo(AuthTokens.basic("Farin", "Urlaub"));
|
|
|
|
assertThat(connectionDetails.getAuthToken()).isEqualTo(AuthTokens.basic("Farin", "Urlaub"));
|
|
|
|
|
|
|
|
assertThat(connectionDetails.getAuthTokenManager()).isNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -177,8 +179,22 @@ class Neo4jAutoConfigurationTests {
|
|
|
|
authentication.setUsername("Farin");
|
|
|
|
authentication.setUsername("Farin");
|
|
|
|
authentication.setPassword("Urlaub");
|
|
|
|
authentication.setPassword("Urlaub");
|
|
|
|
authentication.setRealm("Test Realm");
|
|
|
|
authentication.setRealm("Test Realm");
|
|
|
|
assertThat(new PropertiesNeo4jConnectionDetails(properties).getAuthToken())
|
|
|
|
PropertiesNeo4jConnectionDetails connectionDetails = new PropertiesNeo4jConnectionDetails(properties, null);
|
|
|
|
.isEqualTo(AuthTokens.basic("Farin", "Urlaub", "Test Realm"));
|
|
|
|
assertThat(connectionDetails.getAuthToken()).isEqualTo(AuthTokens.basic("Farin", "Urlaub", "Test Realm"));
|
|
|
|
|
|
|
|
assertThat(connectionDetails.getAuthTokenManager()).isNull();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void authenticationWithAuthTokenManagerAndUsernameShouldProvideAuthTokenManger() {
|
|
|
|
|
|
|
|
Neo4jProperties properties = new Neo4jProperties();
|
|
|
|
|
|
|
|
Authentication authentication = properties.getAuthentication();
|
|
|
|
|
|
|
|
authentication.setUsername("Farin");
|
|
|
|
|
|
|
|
authentication.setPassword("Urlaub");
|
|
|
|
|
|
|
|
authentication.setRealm("Test Realm");
|
|
|
|
|
|
|
|
assertThat(new PropertiesNeo4jConnectionDetails(properties,
|
|
|
|
|
|
|
|
AuthTokenManagers.expirationBased(
|
|
|
|
|
|
|
|
() -> AuthTokens.basic("username", "password").expiringAt(System.currentTimeMillis() + 5000)))
|
|
|
|
|
|
|
|
.getAuthTokenManager()).isNotNull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -186,7 +202,7 @@ class Neo4jAutoConfigurationTests {
|
|
|
|
Neo4jProperties properties = new Neo4jProperties();
|
|
|
|
Neo4jProperties properties = new Neo4jProperties();
|
|
|
|
Authentication authentication = properties.getAuthentication();
|
|
|
|
Authentication authentication = properties.getAuthentication();
|
|
|
|
authentication.setKerberosTicket("AABBCCDDEE");
|
|
|
|
authentication.setKerberosTicket("AABBCCDDEE");
|
|
|
|
assertThat(new PropertiesNeo4jConnectionDetails(properties).getAuthToken())
|
|
|
|
assertThat(new PropertiesNeo4jConnectionDetails(properties, null).getAuthToken())
|
|
|
|
.isEqualTo(AuthTokens.kerberos("AABBCCDDEE"));
|
|
|
|
.isEqualTo(AuthTokens.kerberos("AABBCCDDEE"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -197,7 +213,7 @@ class Neo4jAutoConfigurationTests {
|
|
|
|
authentication.setUsername("Farin");
|
|
|
|
authentication.setUsername("Farin");
|
|
|
|
authentication.setKerberosTicket("AABBCCDDEE");
|
|
|
|
authentication.setKerberosTicket("AABBCCDDEE");
|
|
|
|
assertThatIllegalStateException()
|
|
|
|
assertThatIllegalStateException()
|
|
|
|
.isThrownBy(() -> new PropertiesNeo4jConnectionDetails(properties).getAuthToken())
|
|
|
|
.isThrownBy(() -> new PropertiesNeo4jConnectionDetails(properties, null).getAuthToken())
|
|
|
|
.withMessage("Cannot specify both username ('Farin') and kerberos ticket ('AABBCCDDEE')");
|
|
|
|
.withMessage("Cannot specify both username ('Farin') and kerberos ticket ('AABBCCDDEE')");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -313,7 +329,7 @@ class Neo4jAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
private Config mapDriverConfig(Neo4jProperties properties, ConfigBuilderCustomizer... customizers) {
|
|
|
|
private Config mapDriverConfig(Neo4jProperties properties, ConfigBuilderCustomizer... customizers) {
|
|
|
|
return new Neo4jAutoConfiguration().mapDriverConfig(properties,
|
|
|
|
return new Neo4jAutoConfiguration().mapDriverConfig(properties,
|
|
|
|
new PropertiesNeo4jConnectionDetails(properties), Arrays.asList(customizers));
|
|
|
|
new PropertiesNeo4jConnectionDetails(properties, null), Arrays.asList(customizers));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|