|
18 | 18 | */ |
19 | 19 | package org.neo4j.driver.v1.integration; |
20 | 20 |
|
| 21 | +import org.junit.Before; |
21 | 22 | import org.junit.Rule; |
22 | 23 | import org.junit.Test; |
23 | 24 |
|
| 25 | +import org.neo4j.driver.internal.util.ServerVersion; |
24 | 26 | import org.neo4j.driver.v1.Config; |
25 | 27 | import org.neo4j.driver.v1.Driver; |
26 | 28 | import org.neo4j.driver.v1.GraphDatabase; |
27 | 29 | import org.neo4j.driver.v1.Record; |
28 | 30 | import org.neo4j.driver.v1.Session; |
29 | 31 | import org.neo4j.driver.v1.StatementResult; |
| 32 | +import org.neo4j.driver.v1.exceptions.ClientException; |
30 | 33 | import org.neo4j.driver.v1.exceptions.ServiceUnavailableException; |
31 | 34 | import org.neo4j.driver.v1.util.Neo4jSettings; |
32 | 35 | import org.neo4j.driver.v1.util.Neo4jSettings.BoltTlsLevel; |
33 | 36 | import org.neo4j.driver.v1.util.TestNeo4j; |
34 | 37 |
|
35 | 38 | import static org.hamcrest.CoreMatchers.equalTo; |
36 | 39 | import static org.hamcrest.CoreMatchers.startsWith; |
| 40 | +import static org.hamcrest.Matchers.instanceOf; |
37 | 41 | import static org.junit.Assert.assertThat; |
38 | 42 | import static org.junit.Assert.fail; |
| 43 | +import static org.neo4j.driver.internal.util.ServerVersion.v3_1_0; |
39 | 44 |
|
40 | 45 | public class EncryptionIT |
41 | 46 | { |
42 | 47 | @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 | + } |
44 | 57 |
|
45 | 58 | @Test |
46 | 59 | public void shouldOperateWithNoEncryptionWhenItIsOptionalInTheDatabase() |
@@ -108,9 +121,19 @@ private void testMismatchingEncryption( BoltTlsLevel tlsLevel, boolean driverEnc |
108 | 121 | GraphDatabase.driver( neo4j.uri(), neo4j.authToken(), config ).close(); |
109 | 122 | fail( "Exception expected" ); |
110 | 123 | } |
111 | | - catch ( ServiceUnavailableException e ) |
| 124 | + catch ( RuntimeException e ) |
112 | 125 | { |
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 | + } |
114 | 137 | } |
115 | 138 | } |
116 | 139 |
|
|
0 commit comments