Skip to content

Commit

Permalink
Ignore test cases with unsupported ciphers
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkerr9000 committed Mar 19, 2019
1 parent b8d29eb commit 1c3b425
Showing 1 changed file with 68 additions and 8 deletions.
Expand Up @@ -19,13 +19,18 @@
*/
package org.neo4j.ssl;

import org.hamcrest.collection.IsArrayContaining;
import org.junit.After;
import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import org.neo4j.ssl.SslContextFactory.SslParameters;
import java.io.IOException;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;

import org.neo4j.test.rule.TestDirectory;
import org.neo4j.test.rule.fs.DefaultFileSystemRule;

Expand All @@ -34,8 +39,8 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.neo4j.ssl.SslContextFactory.SslParameters.protocols;
import static org.neo4j.ssl.SslContextFactory.makeSslContext;
import static org.neo4j.ssl.SslNegotiationTest.SslParametersSetup.protocols;
import static org.neo4j.ssl.SslResourceBuilder.selfSignedKeyId;

@RunWith( Parameterized.class )
Expand Down Expand Up @@ -169,13 +174,23 @@ public void cleanup()
@Test
public void shouldNegotiateCorrectly() throws Exception
{
for ( String cipher : setup.serverParams.ciphers )
{
assumeCipherSupported( cipher );
}

for ( String cipher : setup.clientParams.ciphers )
{
assumeCipherSupported( cipher );
}

SslResource sslServerResource = selfSignedKeyId( 0 ).trustKeyId( 1 ).install( testDir.directory( "server" ) );
SslResource sslClientResource = selfSignedKeyId( 1 ).trustKeyId( 0 ).install( testDir.directory( "client" ) );

server = new SecureServer( makeSslContext( sslServerResource, true, setup.serverParams ) );
server = new SecureServer( makeSslContext( sslServerResource, true, setup.serverParams.toSslParameters() ) );

server.start();
client = new SecureClient( makeSslContext( sslClientResource, false, setup.clientParams ) );
client = new SecureClient( makeSslContext( sslClientResource, false, setup.clientParams.toSslParameters() ) );
client.connect( server.port() );

assertTrue( client.sslHandshakeFuture().await( 1, MINUTES ) );
Expand All @@ -192,21 +207,32 @@ public void shouldNegotiateCorrectly() throws Exception
}
}

private void assumeCipherSupported( String cipher ) throws IOException
{
SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket)factory.createSocket();
String[] enabled = socket.getEnabledCipherSuites();
socket.close();

Assume.assumeThat( enabled, IsArrayContaining.hasItemInArray( cipher ) );
}

private static class TestSetup
{
private final SslParameters serverParams;
private final SslParameters clientParams;
private final SslParametersSetup serverParams;
private final SslParametersSetup clientParams;

private final boolean expectedSuccess;
private final String expectedProtocol;
private final String expectedCipher;

private TestSetup( SslParameters serverParams, SslParameters clientParams, boolean expectedSuccess )
private TestSetup( SslParametersSetup serverParams, SslParametersSetup clientParams, boolean expectedSuccess )
{
this( serverParams, clientParams, expectedSuccess, null, null );
}

private TestSetup( SslParameters serverParams, SslParameters clientParams, boolean expectedSuccess, String expectedProtocol, String expectedCipher )
private TestSetup( SslParametersSetup serverParams, SslParametersSetup clientParams, boolean expectedSuccess, String expectedProtocol,
String expectedCipher )
{
this.serverParams = serverParams;
this.clientParams = clientParams;
Expand All @@ -222,4 +248,38 @@ public String toString()
", expectedProtocol='" + expectedProtocol + '\'' + ", expectedCipher='" + expectedCipher + '\'' + '}';
}
}

static class SslParametersSetup
{
private String[] protocols;
private String[] ciphers;

private SslParametersSetup( String[] protocols, String[] ciphers )
{
this.protocols = protocols;
this.ciphers = ciphers;
}

public static SslParametersSetup protocols( String... protocols )
{
return new SslParametersSetup( protocols, null );
}

public SslParametersSetup ciphers( String... ciphers )
{
this.ciphers = ciphers;
return this;
}

public SslContextFactory.SslParameters toSslParameters()
{
return SslContextFactory.SslParameters.protocols( protocols ).ciphers( ciphers );
}

@Override
public String toString()
{
return "SslParametersSetup{" + "protocols='" + protocols + '\'' + ", ciphers='" + ciphers + '\'' + '}';
}
}
}

0 comments on commit 1c3b425

Please sign in to comment.