Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Nov 21, 2016
1 parent a448973 commit 6805e4e
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 33 deletions.
Expand Up @@ -43,6 +43,7 @@
import org.neo4j.graphdb.Result;
import org.neo4j.graphdb.factory.GraphDatabaseBuilder;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.configuration.Settings;
import org.neo4j.kernel.enterprise.api.security.EnterpriseSecurityContext;
Expand Down Expand Up @@ -85,7 +86,8 @@ public void setUp()
logsDirectory = new File( testDirectory.graphDbDir(), "logs" );
logFilename = new File( logsDirectory, "query.log" );
AssertableLogProvider inMemoryLog = new AssertableLogProvider();
databaseBuilder = new TestEnterpriseGraphDatabaseFactory().setFileSystem( fileSystem.get() )
databaseBuilder = new TestEnterpriseGraphDatabaseFactory()
.setFileSystem( new UncloseableDelegatingFileSystemAbstraction( fileSystem.get() ) )
.setInternalLogProvider( inMemoryLog )
.newImpermanentDatabaseBuilder( testDirectory.graphDbDir() );
}
Expand Down
Expand Up @@ -25,13 +25,10 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import org.neo4j.graphdb.Transaction;
import org.neo4j.kernel.api.Statement;
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;
import org.neo4j.test.DoubleLatch;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -106,7 +103,8 @@ public void shouldLogSecurityEvents() throws Exception
neo.getLocalGraph().shutdown();

// assert on log content
FullLog log = new FullLog();
SecurityLog log = new SecurityLog();
log.load();

log.assertHasLine( "mats", "logged in" );
log.assertHasLine( "adminSubject", "created user `mats`" );
Expand All @@ -121,25 +119,6 @@ public void shouldLogSecurityEvents() throws Exception
log.assertHasLine( "adminSubject", "deleted user `mats`");
}

private class FullLog
{
List<String> lines;

FullLog() throws IOException
{
lines = new ArrayList<>();
BufferedReader bufferedReader = new BufferedReader(
neo.fileSystem().openAsReader( new File( securityLog.getAbsolutePath() ), Charsets.UTF_8 ) );
lines.add( bufferedReader.readLine() );
bufferedReader.lines().forEach( lines::add );
}

void assertHasLine( String subject, String msg )
{
assertThat( lines, hasItem( containsString( "[" + subject + "]: " + msg ) ) );
}
}

/*
Admin creates user Henrik with password bar
Henrik logs in with correct password (gets prompted to change - change to foo)
Expand Down Expand Up @@ -776,4 +755,25 @@ public void shouldNotTryToCreateTokensWhenReading()
assertSuccess( readSubject, "MATCH (n:MyNode) WHERE n.nonExistent = 'foo' RETURN toString(count(*)) AS c",
r -> assertKeyIs( r, "c", "1" ) );
}

private class SecurityLog
{
List<String> lines;

void load() throws IOException
{
File securityLog = new File( AuthScenariosInteractionTestBase.this.securityLog.getAbsolutePath() );
try ( BufferedReader bufferedReader = new BufferedReader(
neo.fileSystem().openAsReader( securityLog, Charsets.UTF_8 ) ) )
{
lines = bufferedReader.lines().collect( java.util.stream.Collectors.toList() );
}
}

void assertHasLine( String subject, String msg )
{
Objects.requireNonNull( lines );
assertThat( lines, hasItem( containsString( "[" + subject + "]: " + msg ) ) );
}
}
}
Expand Up @@ -19,10 +19,17 @@
*/
package org.neo4j.server.security.enterprise.auth;

import org.junit.Rule;

import java.util.Map;

import org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction;
import org.neo4j.test.rule.fs.EphemeralFileSystemRule;

public class BoltAuthScenariosInteractionTest extends AuthScenariosInteractionTestBase<BoltInteraction.BoltSubject>
{
@Rule
public EphemeralFileSystemRule fileSystemRule = new EphemeralFileSystemRule();

public BoltAuthScenariosInteractionTest()
{
Expand All @@ -35,6 +42,6 @@ public BoltAuthScenariosInteractionTest()
public NeoInteractionLevel<BoltInteraction.BoltSubject> setUpNeoServer( Map<String, String> config )
throws Throwable
{
return new BoltInteraction( config );
return new BoltInteraction( config, () -> new UncloseableDelegatingFileSystemAbstraction( fileSystemRule.get() ) );
}
}
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.neo4j.bolt.security.auth.AuthenticationException;
import org.neo4j.bolt.v1.messaging.message.FailureMessage;
Expand Down Expand Up @@ -74,13 +75,18 @@ class BoltInteraction implements NeoInteractionLevel<BoltInteraction.BoltSubject
private final Factory<TransportConnection> connectionFactory = SocketConnection::new;
private final Neo4jWithSocket server;
private Map<String,BoltSubject> subjects = new HashMap<>();
private EphemeralFileSystemAbstraction fileSystem;
private FileSystemAbstraction fileSystem;
private EnterpriseAuthManager authManager;

BoltInteraction( Map<String, String> config ) throws IOException
{
this(config, EphemeralFileSystemAbstraction::new);
}

BoltInteraction( Map<String, String> config, Supplier<FileSystemAbstraction> fileSystemSupplier ) throws IOException
{
TestEnterpriseGraphDatabaseFactory factory = new TestEnterpriseGraphDatabaseFactory();
fileSystem = new EphemeralFileSystemAbstraction();
fileSystem = fileSystemSupplier.get();
server = new Neo4jWithSocket( getClass(),
factory,
() -> fileSystem,
Expand Down
Expand Up @@ -19,15 +19,23 @@
*/
package org.neo4j.server.security.enterprise.auth;

import org.junit.Rule;

import java.util.Map;

import org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction;
import org.neo4j.kernel.enterprise.api.security.EnterpriseSecurityContext;
import org.neo4j.test.rule.fs.EphemeralFileSystemRule;

public class EmbeddedAuthScenariosInteractionTest extends AuthScenariosInteractionTestBase<EnterpriseSecurityContext>
{

@Rule
public EphemeralFileSystemRule fileSystemRule = new EphemeralFileSystemRule();

@Override
protected NeoInteractionLevel<EnterpriseSecurityContext> setUpNeoServer( Map<String, String> config ) throws Throwable
{
return new EmbeddedInteraction( config );
return new EmbeddedInteraction( config, () -> new UncloseableDelegatingFileSystemAbstraction( fileSystemRule.get() ) );
}
}
Expand Up @@ -22,6 +22,7 @@
import java.util.Collections;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.neo4j.bolt.BoltKernelExtension;
import org.neo4j.graphdb.ResourceIterator;
Expand All @@ -37,7 +38,6 @@
import org.neo4j.kernel.impl.factory.GraphDatabaseFacade;
import org.neo4j.test.TestEnterpriseGraphDatabaseFactory;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.BoltConnector.EncryptionLevel.OPTIONAL;
Expand All @@ -51,9 +51,14 @@ public class EmbeddedInteraction implements NeoInteractionLevel<EnterpriseSecuri
private FileSystemAbstraction fileSystem;

EmbeddedInteraction( Map<String, String> config ) throws Throwable
{
this (config, EphemeralFileSystemAbstraction::new);
}

EmbeddedInteraction( Map<String, String> config, Supplier<FileSystemAbstraction> fileSystemSupplier ) throws Throwable
{
TestEnterpriseGraphDatabaseFactory factory = new TestEnterpriseGraphDatabaseFactory();
factory.setFileSystem( new EphemeralFileSystemAbstraction() );
factory.setFileSystem( fileSystemSupplier.get() );
GraphDatabaseBuilder builder = factory.newImpermanentDatabaseBuilder();
this.fileSystem = factory.getFileSystem();
init( builder, config );
Expand Down
Expand Up @@ -27,6 +27,8 @@
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.fs.FileUtils;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.configuration.Settings;
Expand Down Expand Up @@ -71,8 +73,12 @@ public void shouldBehaveCorrectlyUnderStress() throws Throwable
String pageSize = fromEnv( "CHECK_POINT_LOG_ROTATION_PAGE_SIZE", DEFAULT_PAGE_SIZE );

System.out.println( "1/6\tBuilding initial store..." );
new ParallelBatchImporter( ensureExistsAndEmpty( storeDir ), DEFAULT, NullLogService.getInstance(),
ExecutionMonitors.defaultVisible(), Config.defaults() ).doImport( new NodeCountInputs( nodeCount ) );
try ( FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction())
{
new ParallelBatchImporter( ensureExistsAndEmpty( storeDir ), fileSystem, DEFAULT,
NullLogService.getInstance(), ExecutionMonitors.defaultVisible(), Config.defaults() )
.doImport( new NodeCountInputs( nodeCount ) );
}

System.out.println( "2/6\tStarting database..." );
GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder( storeDir )
Expand Down

0 comments on commit 6805e4e

Please sign in to comment.