Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
neo-tobias committed Sep 22, 2024
1 parent 0cf9e44 commit 19a3094
Show file tree
Hide file tree
Showing 22 changed files with 201 additions and 285 deletions.
10 changes: 5 additions & 5 deletions src/test/java/com/neo4j/docker/TestDeprecationWarning.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void shouldWarnIfUsingDeprecatedBaseOS_coreDB() throws Exception
{
Assumptions.assumeTrue( TestSettings.BASE_OS == TestSettings.BaseOS.UBI8,
"Deprecation warning should only exist in UBI8 images");
try(GenericContainer container = new GenericContainer(TestSettings.IMAGE_ID))
try(GenericContainer container = new GenericContainer(TestSettings.NEO4J_IMAGE_ID))
{
container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" )
.withExposedPorts( 7474, 7687 )
Expand All @@ -45,7 +45,7 @@ void shouldWarnIfUsingDeprecatedBaseOS_admin()
{
Assumptions.assumeTrue( TestSettings.BASE_OS == TestSettings.BaseOS.UBI8,
"Deprecation warning should only exist in UBI8 images");
try(GenericContainer container = new GenericContainer(TestSettings.ADMIN_IMAGE_ID))
try(GenericContainer container = new GenericContainer(TestSettings.NEO4J_ADMIN_IMAGE_ID))
{
container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" )
.withExposedPorts( 7474, 7687 )
Expand All @@ -66,7 +66,7 @@ void shouldOnlyWarnWhenRunningNeo4jCommands() throws Exception
{
Assumptions.assumeTrue( TestSettings.BASE_OS == TestSettings.BaseOS.UBI8,
"Deprecation warning should only exist in UBI8 images");
try(GenericContainer container = new GenericContainer(TestSettings.IMAGE_ID))
try(GenericContainer container = new GenericContainer(TestSettings.NEO4J_IMAGE_ID))
{
container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" )
.withExposedPorts( 7474, 7687 )
Expand All @@ -86,7 +86,7 @@ void shouldIgnoreDeprecationSuppression_coreDB() throws Exception
{
Assumptions.assumeTrue( TestSettings.BASE_OS == TestSettings.BaseOS.UBI8,
"Deprecation warning should only exist in UBI8 images");
try(GenericContainer container = new GenericContainer(TestSettings.IMAGE_ID))
try(GenericContainer container = new GenericContainer(TestSettings.NEO4J_IMAGE_ID))
{
container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" )
.withEnv( DEPRECATION_WARN_SUPPRESS_FLAG, "suppress" )
Expand All @@ -106,7 +106,7 @@ void shouldIgnoreDeprecationSuppressed_admin()
{
Assumptions.assumeTrue( TestSettings.BASE_OS == TestSettings.BaseOS.UBI8,
"Deprecation warning should only exist in UBI8 images");
try(GenericContainer container = new GenericContainer(TestSettings.ADMIN_IMAGE_ID))
try(GenericContainer container = new GenericContainer(TestSettings.NEO4J_ADMIN_IMAGE_ID))
{
container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" )
.withEnv( DEPRECATION_WARN_SUPPRESS_FLAG, "suppress" )
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/neo4j/docker/TestDockerComposeSecrets.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermissions;
import java.time.Duration;

import static com.neo4j.docker.utils.WaitStrategies.waitForBoltReady;

Expand Down Expand Up @@ -50,7 +49,7 @@ private DockerComposeContainer createContainer( File composeFile, Path container

container.withExposedService( serviceName, DEFAULT_BOLT_PORT )
.withExposedService( serviceName, DEFAULT_HTTP_PORT )
.withEnv( "NEO4J_IMAGE", TestSettings.IMAGE_ID.asCanonicalNameString() )
.withEnv( "NEO4J_IMAGE", TestSettings.NEO4J_IMAGE_ID.asCanonicalNameString() )
.withEnv( "HOST_ROOT", containerRootDir.toAbsolutePath().toString() )
.waitingFor( serviceName, waitForBoltReady() )
.withLogConsumer( serviceName, new Slf4jLogConsumer( log ) );
Expand Down
32 changes: 6 additions & 26 deletions src/test/java/com/neo4j/docker/coredb/TestAdminReport.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package com.neo4j.docker.coredb;

import com.neo4j.docker.utils.DatabaseIO;
import com.neo4j.docker.utils.Neo4jVersion;
import com.neo4j.docker.utils.SetContainerUser;
import com.neo4j.docker.utils.WaitStrategies;
import com.neo4j.docker.utils.TemporaryFolderManager;
import com.neo4j.docker.utils.TestSettings;
import com.neo4j.docker.utils.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -47,27 +42,12 @@ static void setCorrectPathFlagForVersion()
reportDestinationFlag = "--to-path";
}
}

private GenericContainer createNeo4jContainer( boolean asCurrentUser)
{
GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID )
.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" )
.withEnv( "NEO4J_AUTH", "neo4j/"+PASSWORD )
.withExposedPorts( 7474, 7687 )
.withLogConsumer( new Slf4jLogConsumer( log ) )
.waitingFor(WaitStrategies.waitForNeo4jReady( PASSWORD ));
if(asCurrentUser)
{
SetContainerUser.nonRootUser( container );
}
return container;
}


@ParameterizedTest(name = "ascurrentuser_{0}")
@ValueSource(booleans = {true, false})
void testMountToTmpReports(boolean asCurrentUser) throws Exception
{
try(GenericContainer container = createNeo4jContainer(asCurrentUser))
try(GenericContainer container = HelperContainers.createNeo4jContainer(asCurrentUser))
{
temporaryFolderManager.createFolderAndMountAsVolume(container, "/logs");
Path reportFolder = temporaryFolderManager.createFolderAndMountAsVolume(container, "/tmp/reports");
Expand Down Expand Up @@ -102,7 +82,7 @@ void testCanWriteReportToAnyMountedLocation_toPathWithSpace(boolean asCurrentUse

private void verifyCanWriteToMountedLocation(boolean asCurrentUser, String testFolderPrefix, String[] execArgs) throws Exception
{
try(GenericContainer container = createNeo4jContainer(asCurrentUser))
try(GenericContainer container = HelperContainers.createNeo4jContainer(asCurrentUser))
{
temporaryFolderManager.createFolderAndMountAsVolume(container, "/logs");
Path reportFolder = temporaryFolderManager.createFolderAndMountAsVolume(container, "/reports");
Expand All @@ -120,7 +100,7 @@ private void verifyCanWriteToMountedLocation(boolean asCurrentUser, String testF
@Test
void shouldShowNeo4jAdminHelpText_whenCMD() throws Exception
{
try(GenericContainer container = createNeo4jContainer(false))
try(GenericContainer container = HelperContainers.createNeo4jContainer(false))
{
container.withCommand( "neo4j-admin-report", "--help" );
WaitStrategies.waitUntilContainerFinished( container, Duration.ofSeconds( 20 ) );
Expand All @@ -142,7 +122,7 @@ void shouldShowNeo4jAdminHelpText_whenCMD() throws Exception
@Test
void shouldShowNeo4jAdminHelpText_whenEXEC() throws Exception
{
try(GenericContainer container = createNeo4jContainer(false))
try(GenericContainer container = HelperContainers.createNeo4jContainer(false))
{
temporaryFolderManager.createFolderAndMountAsVolume(container, "/logs");
container.start();
Expand Down
55 changes: 18 additions & 37 deletions src/test/java/com/neo4j/docker/coredb/TestAuthentication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

import com.neo4j.docker.coredb.configurations.Configuration;
import com.neo4j.docker.coredb.configurations.Setting;
import com.neo4j.docker.utils.DatabaseIO;
import com.neo4j.docker.utils.Neo4jVersion;
import com.neo4j.docker.utils.SetContainerUser;
import com.neo4j.docker.utils.WaitStrategies;
import com.neo4j.docker.utils.TemporaryFolderManager;
import com.neo4j.docker.utils.TestSettings;
import com.neo4j.docker.utils.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -35,21 +30,7 @@ public class TestAuthentication

@RegisterExtension
public static TemporaryFolderManager temporaryFolderManager = new TemporaryFolderManager();

private GenericContainer createContainer( boolean asCurrentUser )
{
GenericContainer container = new GenericContainer( TestSettings.IMAGE_ID );
container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" )
.withExposedPorts( 7474, 7687 )
.withLogConsumer( new Slf4jLogConsumer( log ) )
.waitingFor(WaitStrategies.waitForBoltReady());
if(asCurrentUser)
{
SetContainerUser.nonRootUser( container );
}
return container;
}


private Path setInitialPasswordWithSecretsFile(GenericContainer container, String password) throws IOException
{
Path secretsFolder = temporaryFolderManager.createFolderAndMountAsVolume( container, "/secrets" );
Expand All @@ -63,7 +44,7 @@ void testNoPassword()
{
// we test that setting NEO4J_AUTH to "none" lets the database start in TestBasic.java,
// but that does not test that we can read/write the database
try(GenericContainer container = createContainer( false ))
try(GenericContainer container = HelperContainers.createNeo4jContainer( false ))
{
container.withEnv( "NEO4J_AUTH", "none");
container.start();
Expand All @@ -76,7 +57,7 @@ void testNoPassword()
@Test
void testPasswordCantBeNeo4j() throws Exception
{
try(GenericContainer failContainer = new GenericContainer( TestSettings.IMAGE_ID ).withLogConsumer( new Slf4jLogConsumer( log ) ))
try(GenericContainer failContainer = new GenericContainer( TestSettings.NEO4J_IMAGE_ID ).withLogConsumer( new Slf4jLogConsumer( log ) ))
{
if ( TestSettings.EDITION == TestSettings.Edition.ENTERPRISE )
{
Expand All @@ -97,7 +78,7 @@ void testPasswordCantBeNeo4j() throws Exception
@Test
void testDefaultPasswordAndPasswordResetIfNoNeo4jAuthSet()
{
try(GenericContainer container = createContainer( true ))
try(GenericContainer container = HelperContainers.createNeo4jContainer( true ))
{
log.info( "Starting first container as current user and not specifying NEO4J_AUTH" );
container.waitingFor( WaitStrategies.waitForNeo4jReady( "neo4j" ) );
Expand All @@ -123,7 +104,7 @@ void testCanSetPassword( boolean asCurrentUser ) throws Exception
String password = "some_valid_password";
Path dataMount;

try(GenericContainer firstContainer = createContainer( asCurrentUser ))
try(GenericContainer firstContainer = HelperContainers.createNeo4jContainer( asCurrentUser ))
{
firstContainer.withEnv( "NEO4J_AUTH", "neo4j/"+password )
.waitingFor(WaitStrategies.waitForNeo4jReady(password));
Expand All @@ -137,7 +118,7 @@ void testCanSetPassword( boolean asCurrentUser ) throws Exception
}

// with a new container, check the database data.
try(GenericContainer secondContainer = createContainer( asCurrentUser )
try(GenericContainer secondContainer = HelperContainers.createNeo4jContainer( asCurrentUser )
.waitingFor(WaitStrategies.waitForNeo4jReady(password)))
{
temporaryFolderManager.mountHostFolderAsVolume( secondContainer, dataMount, "/data" );
Expand All @@ -154,7 +135,7 @@ void testCanSetPasswordFromSecretsFile( boolean asCurrentUser ) throws Exception
{
String password = "some_valid_password";

try(GenericContainer container = createContainer( asCurrentUser )
try(GenericContainer container = HelperContainers.createNeo4jContainer( asCurrentUser )
.waitingFor(WaitStrategies.waitForNeo4jReady(password)))
{
setInitialPasswordWithSecretsFile( container, password );
Expand All @@ -173,7 +154,7 @@ void testSecretsFileTakesPriorityOverEnvAuthentication() throws Exception
String password = "some_valid_password";
String wrongPassword = "not_the_password";

try(GenericContainer container = createContainer(false )
try(GenericContainer container = HelperContainers.createNeo4jContainer(false )
.waitingFor(WaitStrategies.waitForNeo4jReady(password)))
{
container.withEnv( "NEO4J_AUTH", "neo4j/" + wrongPassword );
Expand All @@ -192,7 +173,7 @@ void testSecretsFileTakesPriorityOverEnvAuthentication() throws Exception
@Test
void testFailsIfSecretsFileSetButMissing()
{
try(GenericContainer failContainer = createContainer( false ))
try(GenericContainer failContainer = HelperContainers.createNeo4jContainer( false ))
{
WaitStrategies.waitUntilContainerFinished( failContainer, Duration.ofSeconds( 30 ) );
failContainer.withEnv( NEO4J_AUTH_FILE_ENV, "/secrets/doesnotexist.secret" );
Expand All @@ -211,7 +192,7 @@ void testCanSetPasswordWithDebugging() throws Exception
{
String password = "some_valid_password";

try ( GenericContainer container = createContainer( false ) )
try ( GenericContainer container = HelperContainers.createNeo4jContainer( false ) )
{
container.withEnv( "NEO4J_AUTH", "neo4j/" + password )
.withEnv( "NEO4J_DEBUG", "yes" )
Expand All @@ -230,7 +211,7 @@ void testSettingNeo4jAuthDoesntOverrideExistingPassword( boolean asCurrentUser )
String password = "some_valid_password";
Path dataMount;

try(GenericContainer firstContainer = createContainer( asCurrentUser ))
try(GenericContainer firstContainer = HelperContainers.createNeo4jContainer( asCurrentUser ))
{
firstContainer.withEnv( "NEO4J_AUTH", "neo4j/"+password )
.waitingFor(WaitStrategies.waitForNeo4jReady( password));
Expand All @@ -245,7 +226,7 @@ void testSettingNeo4jAuthDoesntOverrideExistingPassword( boolean asCurrentUser )
}

// with a new container, check the database data.
try(GenericContainer secondContainer = createContainer( asCurrentUser ))
try(GenericContainer secondContainer = HelperContainers.createNeo4jContainer( asCurrentUser ))
{
String wrongPassword = "not_the_password";
secondContainer.withEnv( "NEO4J_AUTH", "neo4j/"+wrongPassword );
Expand All @@ -264,7 +245,7 @@ void testPromptsForPasswordReset()
{
Assumptions.assumeTrue( TestSettings.NEO4J_VERSION.isAtLeastVersion( new Neo4jVersion( 3,6,0 ) ),
"Require password reset is only a feature in 3.6 onwards");
try(GenericContainer container = createContainer( false ))
try(GenericContainer container = HelperContainers.createNeo4jContainer( false ))
{
String user = "neo4j";
String intialPass = "apassword";
Expand All @@ -290,7 +271,7 @@ void testWarnAndFailIfPasswordLessThan8Chars(boolean usePasswordFile) throws Exc
Assumptions.assumeTrue( TestSettings.NEO4J_VERSION.isAtLeastVersion( new Neo4jVersion( 5,2,0 ) ),
"Minimum password length introduced in 5.2.0");
String shortPassword = "123";
try(GenericContainer failContainer = createContainer( false ))
try(GenericContainer failContainer = HelperContainers.createNeo4jContainer( false ))
{
if(usePasswordFile)
{
Expand Down Expand Up @@ -318,7 +299,7 @@ void testWarnAndFailIfPasswordLessThanOverride(boolean usePasswordFile) throws E
Assumptions.assumeTrue( TestSettings.NEO4J_VERSION.isAtLeastVersion( new Neo4jVersion( 5,2,0 ) ),
"Minimum password length introduced in 5.2.0");
String shortPassword = "123";
try(GenericContainer failContainer = createContainer( false ))
try(GenericContainer failContainer = HelperContainers.createNeo4jContainer( false ))
{
if(usePasswordFile)
{
Expand Down Expand Up @@ -348,7 +329,7 @@ void shouldNotWarnAboutMinimumPasswordLengthIfSettingOverridden_env(boolean useP
Assumptions.assumeTrue( TestSettings.NEO4J_VERSION.isAtLeastVersion( new Neo4jVersion( 5,2,0 ) ),
"Minimum password length introduced in 5.2.0");
String shortPassword = "123";
try(GenericContainer container = createContainer( false ))
try(GenericContainer container = HelperContainers.createNeo4jContainer( false ).waitingFor(WaitStrategies.waitForBoltReady()))
{
if(usePasswordFile)
{
Expand All @@ -370,7 +351,7 @@ void shouldNotWarnAboutMinimumPasswordLengthIfSettingOverridden_conf(boolean use
Assumptions.assumeTrue( TestSettings.NEO4J_VERSION.isAtLeastVersion( new Neo4jVersion( 5,2,0 ) ),
"Minimum password length introduced in 5.2.0");
String shortPassword = "123";
try(GenericContainer container = createContainer( false ))
try(GenericContainer container = HelperContainers.createNeo4jContainer( false ))
{
if(usePasswordFile)
{
Expand Down
Loading

0 comments on commit 19a3094

Please sign in to comment.