Skip to content

Commit e705db1

Browse files
committed
Fixed encryption test with 3.0 neo4j
Neo4j 3.0.x throws different error when encryption required but not used by the driver. This commit fixes test to account for it.
1 parent b92eac3 commit e705db1

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

driver/src/test/java/org/neo4j/driver/v1/integration/EncryptionIT.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,42 @@
1818
*/
1919
package org.neo4j.driver.v1.integration;
2020

21+
import org.junit.Before;
2122
import org.junit.Rule;
2223
import org.junit.Test;
2324

25+
import org.neo4j.driver.internal.util.ServerVersion;
2426
import org.neo4j.driver.v1.Config;
2527
import org.neo4j.driver.v1.Driver;
2628
import org.neo4j.driver.v1.GraphDatabase;
2729
import org.neo4j.driver.v1.Record;
2830
import org.neo4j.driver.v1.Session;
2931
import org.neo4j.driver.v1.StatementResult;
32+
import org.neo4j.driver.v1.exceptions.ClientException;
3033
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
3134
import org.neo4j.driver.v1.util.Neo4jSettings;
3235
import org.neo4j.driver.v1.util.Neo4jSettings.BoltTlsLevel;
3336
import org.neo4j.driver.v1.util.TestNeo4j;
3437

3538
import static org.hamcrest.CoreMatchers.equalTo;
3639
import static org.hamcrest.CoreMatchers.startsWith;
40+
import static org.hamcrest.Matchers.instanceOf;
3741
import static org.junit.Assert.assertThat;
3842
import static org.junit.Assert.fail;
43+
import static org.neo4j.driver.internal.util.ServerVersion.v3_1_0;
3944

4045
public class EncryptionIT
4146
{
4247
@Rule
43-
public TestNeo4j neo4j = new TestNeo4j();
48+
public final TestNeo4j neo4j = new TestNeo4j();
49+
50+
private ServerVersion neo4jVersion;
51+
52+
@Before
53+
public void setUp()
54+
{
55+
neo4jVersion = neo4j.version();
56+
}
4457

4558
@Test
4659
public void shouldOperateWithNoEncryptionWhenItIsOptionalInTheDatabase()
@@ -108,9 +121,19 @@ private void testMismatchingEncryption( BoltTlsLevel tlsLevel, boolean driverEnc
108121
GraphDatabase.driver( neo4j.uri(), neo4j.authToken(), config ).close();
109122
fail( "Exception expected" );
110123
}
111-
catch ( ServiceUnavailableException e )
124+
catch ( RuntimeException e )
112125
{
113-
assertThat( e.getMessage(), startsWith( "Connection to the database terminated" ) );
126+
// pre 3.1 neo4j throws different exception when encryption required but not used
127+
if ( neo4jVersion.lessThan( v3_1_0 ) && tlsLevel == BoltTlsLevel.REQUIRED )
128+
{
129+
assertThat( e, instanceOf( ClientException.class ) );
130+
assertThat( e.getMessage(), startsWith( "This server requires a TLS encrypted connection" ) );
131+
}
132+
else
133+
{
134+
assertThat( e, instanceOf( ServiceUnavailableException.class ) );
135+
assertThat( e.getMessage(), startsWith( "Connection to the database terminated" ) );
136+
}
114137
}
115138
}
116139

driver/src/test/java/org/neo4j/driver/v1/util/Neo4jRunner.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,23 +290,22 @@ private void updateServerSettingsFile()
290290

291291
private void installShutdownHook()
292292
{
293-
Runtime.getRuntime().addShutdownHook( new Thread( new Runnable()
293+
Runtime.getRuntime().addShutdownHook( new Thread( () ->
294294
{
295-
@Override
296-
public void run()
297-
{
298295
try
299296
{
300-
debug("Starting shutdown hook");
301-
driver.close();
297+
debug( "Starting shutdown hook" );
298+
if ( driver != null )
299+
{
300+
driver.close();
301+
}
302302
stopNeo4j();
303-
debug("Finished shutdown hook");
303+
debug( "Finished shutdown hook" );
304304
}
305305
catch ( Exception e )
306306
{
307307
e.printStackTrace();
308308
}
309-
}
310309
} ) );
311310
}
312311

0 commit comments

Comments
 (0)