Skip to content

Commit

Permalink
Merge pull request #570 from zhenlineo/1.7-flaky-test
Browse files Browse the repository at this point in the history
Fixing the flaky test that is caused by certificate file changes.
  • Loading branch information
zhenlineo authored Mar 6, 2019
2 parents f9a6fca + 5b58956 commit f66e194
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@
*/
package org.neo4j.driver.v1.integration;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.function.Supplier;

import org.neo4j.driver.v1.Config;
Expand All @@ -36,6 +30,7 @@
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.StatementResult;
import org.neo4j.driver.v1.exceptions.SecurityException;
import org.neo4j.driver.v1.util.CertificateExtension;
import org.neo4j.driver.v1.util.CertificateToolUtil.CertificateKeyPair;
import org.neo4j.driver.v1.util.DatabaseExtension;
import org.neo4j.driver.v1.util.ParallelizableIT;
Expand All @@ -51,28 +46,7 @@
class TrustCustomCertificateIT
{
@RegisterExtension
static final DatabaseExtension neo4j = new DatabaseExtension();

private static Path originalKeyFile;
private static Path originalCertFile;

@BeforeAll
static void beforeAll() throws IOException
{
originalKeyFile = Files.createTempFile( "key-file-", "" );
originalCertFile = Files.createTempFile( "cert-file-", "" );

Files.copy( neo4j.tlsKeyFile().toPath(), originalKeyFile , StandardCopyOption.REPLACE_EXISTING);
Files.copy( neo4j.tlsCertFile().toPath(), originalCertFile, StandardCopyOption.REPLACE_EXISTING );
}

@AfterAll
static void afterAll() throws Exception
{
neo4j.updateEncryptionKeyAndCert( originalKeyFile.toFile(), originalCertFile.toFile() );
Files.deleteIfExists( originalKeyFile );
Files.deleteIfExists( originalCertFile );
}
static final DatabaseExtension neo4j = new CertificateExtension();

@Test
void shouldAcceptServerWithCertificateSignedByDriverCertificate() throws Throwable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.StatementResult;
import org.neo4j.driver.v1.exceptions.SecurityException;
import org.neo4j.driver.v1.util.CertificateExtension;
import org.neo4j.driver.v1.util.CertificateToolUtil;
import org.neo4j.driver.v1.util.DatabaseExtension;
import org.neo4j.driver.v1.util.ParallelizableIT;
Expand All @@ -46,7 +47,7 @@
class TrustOnFirstUseIT
{
@RegisterExtension
static final DatabaseExtension neo4j = new DatabaseExtension();
static final DatabaseExtension neo4j = new CertificateExtension();

@Test
void shouldTrustOnFirstUse() throws Throwable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2002-2019 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.driver.v1.util;

import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

public class CertificateExtension extends DatabaseExtension implements BeforeAllCallback, AfterAllCallback
{
private static Path originalKeyFile;
private static Path originalCertFile;

@Override
public void beforeAll( ExtensionContext extensionContext ) throws Exception
{
originalKeyFile = Files.createTempFile( "key-file-", "" );
originalCertFile = Files.createTempFile( "cert-file-", "" );

Files.copy( tlsKeyFile().toPath(), originalKeyFile , StandardCopyOption.REPLACE_EXISTING);
Files.copy( tlsCertFile().toPath(), originalCertFile, StandardCopyOption.REPLACE_EXISTING );
}

@Override
public void afterAll( ExtensionContext extensionContext ) throws Exception
{
updateEncryptionKeyAndCert( originalKeyFile.toFile(), originalCertFile.toFile() );
Files.deleteIfExists( originalKeyFile );
Files.deleteIfExists( originalCertFile );
}
}

0 comments on commit f66e194

Please sign in to comment.