diff --git a/common/src/test/scala/org/neo4j/spark/service/AuthenticationTest.scala b/common/src/test/scala/org/neo4j/spark/service/AuthenticationTest.scala new file mode 100644 index 000000000..b24cfd70e --- /dev/null +++ b/common/src/test/scala/org/neo4j/spark/service/AuthenticationTest.scala @@ -0,0 +1,47 @@ +package org.neo4j.spark.service + +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor +import org.neo4j.driver.AuthToken +import org.neo4j.driver.Config +import org.neo4j.driver.GraphDatabase +import org.neo4j.spark.util.DriverCache +import org.neo4j.spark.util.Neo4jOptions +import org.powermock.api.mockito.PowerMockito +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner +import org.testcontainers.shaded.com.google.common.io.BaseEncoding + +import java.util +import org.junit.Assert.assertEquals +import org.mockito.ArgumentMatchers._ +import org.mockito.Mockito.times + +@PrepareForTest(Array(classOf[GraphDatabase])) +@RunWith(classOf[PowerMockRunner]) +class AuthenticationTest { + + @Test + def testLdapConnectionToken(): Unit = { + val options = new util.HashMap[String, String] + options.put("url", "bolt://localhost:7687") + options.put("authentication.type", "custom") + options.put("authentication.custom.credentials", BaseEncoding.base64.encode("user:password".getBytes)) + options.put("labels", "Person") + + val argumentCaptor = ArgumentCaptor.forClass(classOf[AuthToken]) + val neo4jOptions = new Neo4jOptions(options) + val neo4jDriverOptions = neo4jOptions.connection + val driverCache = new DriverCache(neo4jDriverOptions, "jobId") + + PowerMockito.mockStatic(classOf[GraphDatabase]) + + driverCache.getOrCreate() + + PowerMockito.verifyStatic(classOf[GraphDatabase], times(1)) + GraphDatabase.driver(anyString, argumentCaptor.capture, any(classOf[Config])) + + assertEquals(neo4jDriverOptions.toNeo4jAuth, argumentCaptor.getValue) + } +} \ No newline at end of file diff --git a/test-support/pom.xml b/test-support/pom.xml index 942a6847d..e4f142f65 100644 --- a/test-support/pom.xml +++ b/test-support/pom.xml @@ -17,6 +17,10 @@ 4.0.0 + + 2.0.9 + + @@ -49,6 +53,18 @@ 2.12.0 + + org.powermock + powermock-module-junit4 + ${powermock.version} + + + + org.powermock + powermock-api-mockito2 + ${powermock.version} + + \ No newline at end of file