Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

temporarily revert tests for command expansion bugs because those bug… #297

Merged
merged 1 commit into from
May 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 19 additions & 39 deletions src/test/java/com/neo4j/docker/TestExtendedConf.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
import com.neo4j.docker.utils.SetContainerUser;
import com.neo4j.docker.utils.TestSettings;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.OutputFrame;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;

Expand All @@ -33,18 +32,17 @@
public class TestExtendedConf
{
private static final Logger log = LoggerFactory.getLogger( TestExtendedConf.class );

@BeforeAll
static void ensureFeaturePresent()
{
Assumptions.assumeTrue( TestSettings.NEO4J_VERSION.isAtLeastVersion( new Neo4jVersion( 4,2,1 ) ),
Assumptions.assumeTrue( TestSettings.NEO4J_VERSION.isAtLeastVersion( new Neo4jVersion( 4,2,0 ) ),
"Extended configuration feature not available before 4.2" );
}

protected GenericContainer createContainer(String password)
protected GenericContainer createContainer()
{
return new GenericContainer(TestSettings.IMAGE_ID)
.withEnv("NEO4J_AUTH", password == null || password.isEmpty() ? "none" : "neo4j/" + password)
.withEnv("NEO4J_AUTH", "none")
.withEnv("NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes")
.withEnv( "EXTENDED_CONF", "yeppers" )
.withExposedPorts(7474, 7687)
Expand All @@ -53,32 +51,20 @@ protected GenericContainer createContainer(String password)
}


@ParameterizedTest
@ValueSource(strings = {"", "secretN30"})
public void shouldStartWithExtendedConf(String password)
@Test
public void shouldStartWithExtendedConf()
{
try(GenericContainer container = createContainer(password))
try(GenericContainer container = createContainer())
{
container.setWaitStrategy( Wait.forHttp( "/" ).forPort( 7474 ).forStatusCode( 200 ) );
container.start();

Assertions.assertTrue( container.isRunning() );
assertPasswordChangedLogIsCorrect( password, container );
}
}

private void assertPasswordChangedLogIsCorrect( String password, GenericContainer container )
{
if ( password.isEmpty()) {
Assertions.assertFalse( container.getLogs( OutputFrame.OutputType.STDOUT).contains( "Changed password for user 'neo4j'." ) );
} else {
Assertions.assertTrue( container.getLogs( OutputFrame.OutputType.STDOUT).contains( "Changed password for user 'neo4j'." ) );
}
}
}

@ParameterizedTest
@ValueSource(strings = {"", "secretN30"})
void testReadsTheExtendedConfFile_defaultUser(String password) throws Exception
@Ignore
@Test
void testReadsTheExtendedConfFile_defaultUser() throws Exception
{
// set up test folders
Path testOutputFolder = HostFileSystemOperations.createTempFolder( "extendedConfIsRead-" );
Expand All @@ -92,17 +78,14 @@ void testReadsTheExtendedConfFile_defaultUser(String password) throws Exception
chmod600( confFolder.resolve( "neo4j.conf" ) );

// start container
try(GenericContainer container = createContainer(password))
try(GenericContainer container = createContainer())
{
runContainerAndVerify( container, confFolder, logsFolder, password );
runContainerAndVerify( container, confFolder, logsFolder );
}
}



@ParameterizedTest
@ValueSource(strings = {"", "secretN30"})
void testReadsTheExtendedConfFile_nonRootUser(String password) throws Exception
@Test
void testReadsTheExtendedConfFile_nonRootUser() throws Exception
{
// set up test folders
Path testOutputFolder = HostFileSystemOperations.createTempFolder( "extendedConfIsRead-" );
Expand All @@ -114,16 +97,16 @@ void testReadsTheExtendedConfFile_nonRootUser(String password) throws Exception
Files.copy( confFile, confFolder.resolve( "neo4j.conf" ) );
chmod600( confFolder.resolve( "neo4j.conf" ) );

try(GenericContainer container = createContainer(password))
try(GenericContainer container = createContainer())
{
SetContainerUser.nonRootUser( container );
container.withFileSystemBind( "/etc/passwd", "/etc/passwd", BindMode.READ_ONLY );
container.withFileSystemBind( "/etc/group", "/etc/group", BindMode.READ_ONLY );
runContainerAndVerify( container, confFolder, logsFolder, password );
runContainerAndVerify( container, confFolder, logsFolder );
}
}

private void runContainerAndVerify(GenericContainer container, Path confFolder, Path logsFolder, String password) throws Exception
private void runContainerAndVerify(GenericContainer container, Path confFolder, Path logsFolder) throws Exception
{
HostFileSystemOperations.mountHostFolderAsVolume( container, confFolder, "/conf" );
HostFileSystemOperations.mountHostFolderAsVolume( container, logsFolder, "/logs" );
Expand All @@ -138,9 +121,6 @@ private void runContainerAndVerify(GenericContainer container, Path confFolder,
Optional<String> isMatch = lines.filter( s -> s.contains("dbms.logs.http.rotation.keep_number=20")).findFirst();
lines.close();
Assertions.assertTrue( isMatch.isPresent(), "dbms.max_databases was not set correctly");

//Check the password was changed if set
assertPasswordChangedLogIsCorrect( password, container );
}

private void chmod600(Path file) throws IOException
Expand Down