Search in sources :

Example 1 with InsecureTrustManager

use of org.neo4j.test.server.InsecureTrustManager in project neo4j by neo4j.

the class HttpHeadersIT method runRequestAndGetHeaders.

private static Map<String, List<String>> runRequestAndGetHeaders(URI baseUri) throws Exception {
    var uri = baseUri.resolve(txCommitEndpoint());
    var request = HttpRequest.newBuilder(uri).header(ACCEPT, APPLICATION_JSON).POST(noBody()).build();
    var trustAllSslContext = SSLContext.getInstance("TLS");
    trustAllSslContext.init(null, new TrustManager[] { new InsecureTrustManager() }, null);
    var client = HttpClient.newBuilder().sslContext(trustAllSslContext).connectTimeout(Duration.ofMinutes(1)).build();
    var response = client.sendAsync(request, discarding()).get(1, TimeUnit.MINUTES);
    assertEquals(200, response.statusCode());
    return response.headers().map();
}
Also used : InsecureTrustManager(org.neo4j.test.server.InsecureTrustManager)

Example 2 with InsecureTrustManager

use of org.neo4j.test.server.InsecureTrustManager in project neo4j by neo4j.

the class HttpsAccessIT method startServer.

private void startServer(boolean httpEnabled, boolean httpsEnabled) throws Exception {
    CommunityWebContainerBuilder serverBuilder = serverOnRandomPorts().usingDataDir(folder.directory(name.getMethodName()).toAbsolutePath().toString());
    if (!httpEnabled) {
        serverBuilder.withHttpDisabled();
    }
    if (httpsEnabled) {
        serverBuilder.withHttpsEnabled();
    }
    testWebContainer = serverBuilder.build();
    // Because we are generating a non-CA-signed certificate, we need to turn off verification in the client.
    // This is ironic, since there is no proper verification on the CA side in the first place, but I digress.
    TrustManager[] trustAllCerts = { new InsecureTrustManager() };
    // Install the all-trusting trust manager
    SSLContext sc = SSLContext.getInstance("TLS");
    sc.init(null, trustAllCerts, new SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
}
Also used : CommunityWebContainerBuilder(org.neo4j.server.helpers.CommunityWebContainerBuilder) InsecureTrustManager(org.neo4j.test.server.InsecureTrustManager) SecureRandom(java.security.SecureRandom) SSLContext(javax.net.ssl.SSLContext) InsecureTrustManager(org.neo4j.test.server.InsecureTrustManager) TrustManager(javax.net.ssl.TrustManager)

Aggregations

InsecureTrustManager (org.neo4j.test.server.InsecureTrustManager)2 SecureRandom (java.security.SecureRandom)1 SSLContext (javax.net.ssl.SSLContext)1 TrustManager (javax.net.ssl.TrustManager)1 CommunityWebContainerBuilder (org.neo4j.server.helpers.CommunityWebContainerBuilder)1