|
51 | 51 | import static org.junit.Assert.assertEquals;
|
52 | 52 | import static org.junit.Assert.assertFalse;
|
53 | 53 | import static org.junit.Assert.assertTrue;
|
| 54 | +import static org.mockito.Matchers.anyString; |
54 | 55 | import static org.mockito.Mockito.atLeastOnce;
|
55 | 56 | import static org.mockito.Mockito.mock;
|
56 | 57 | import static org.mockito.Mockito.verify;
|
| 58 | +import static org.mockito.Mockito.when; |
57 | 59 | import static org.neo4j.driver.internal.security.TrustOnFirstUseTrustManager.fingerprint;
|
58 | 60 |
|
59 | 61 | public class TLSSocketChannelIT
|
@@ -290,26 +292,36 @@ public void shouldEstablishTLSConnection() throws Throwable
|
290 | 292 | }
|
291 | 293 | }
|
292 | 294 |
|
293 |
| -// @Test |
294 |
| -// public void shouldWarnIfUsingDeprecatedTLSOption() throws Throwable |
295 |
| -// { |
296 |
| -// |
297 |
| -// Logger logger = mock( Logger.class ); |
298 |
| -// SocketChannel channel = SocketChannel.open(); |
299 |
| -// channel.connect( new InetSocketAddress( "localhost", 7687 ) ); |
300 |
| -// |
301 |
| -// // When |
302 |
| -// TLSSocketChannel sslChannel = new TLSSocketChannel( "localhost", 7687, channel, logger, |
303 |
| -// Config.TrustStrategy.trustSignedBy( |
304 |
| -// Neo4jSettings.DEFAULT_TLS_CERT_FILE ) ); |
305 |
| -// sslChannel.close(); |
306 |
| -// |
307 |
| -// // Then |
308 |
| -// verify( logger, atLeastOnce() ) |
309 |
| -// .warn( "Option `TRUST_SIGNED_CERTIFICATE` has been deprecated and will be removed " + |
310 |
| -// "in a future version of the driver. Please switch to use " + |
311 |
| -// "`TRUST_CUSTOM_CA_SIGNED_CERTIFICATES` instead." ); |
312 |
| -// } |
| 295 | + @Test |
| 296 | + public void shouldWarnIfUsingDeprecatedTLSOption() throws Throwable |
| 297 | + { |
| 298 | + |
| 299 | + Logger logger = mock( Logger.class ); |
| 300 | + Logging logging = mock( Logging.class ); |
| 301 | + when(logging.getLog( anyString() )).thenReturn( logger ); |
| 302 | + |
| 303 | + SocketChannel channel = SocketChannel.open(); |
| 304 | + channel.connect( new InetSocketAddress( "localhost", 7687 ) ); |
| 305 | + |
| 306 | + Config config = Config.build() |
| 307 | + .withEncryptionLevel( Config.EncryptionLevel.REQUIRED ) |
| 308 | + .withTrustStrategy( Config.TrustStrategy.trustSignedBy( Neo4jSettings.DEFAULT_TLS_CERT_FILE ) ) |
| 309 | + .withLogging( logging ) |
| 310 | + .toConfig(); |
| 311 | + |
| 312 | + // When |
| 313 | + try ( Driver driver = GraphDatabase.driver( Neo4jRunner.DEFAULT_URI, config ); |
| 314 | + Session session = driver.session() ) |
| 315 | + { |
| 316 | + session.run( "RETURN 1" ).consume(); |
| 317 | + } |
| 318 | + |
| 319 | + // Then |
| 320 | + verify( logger, atLeastOnce() ) |
| 321 | + .warn( "Option `TRUST_SIGNED_CERTIFICATE` has been deprecated and will be removed " + |
| 322 | + "in a future version of the driver. Please switch to use " + |
| 323 | + "`TRUST_CUSTOM_CA_SIGNED_CERTIFICATES` instead." ); |
| 324 | + } |
313 | 325 |
|
314 | 326 | private void performTLSHandshakeUsingKnownCerts( File knownCerts ) throws Throwable
|
315 | 327 | {
|
|
0 commit comments