Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The query log will now include the name of the access mode (the username) as part of the log message. This is solved by making all `QuerySession` implementors use their provided transactional context to acquire the username and put it in the `toString()`, which is already printed to the query log.
- Loading branch information
Showing
11 changed files
with
393 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
community/bolt/src/test/java/org/neo4j/bolt/v1/runtime/cypher/BoltQuerySessionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,43 @@ | |||
/* | |||
* Copyright (c) 2002-2016 "Neo Technology," | |||
* Network Engine for Objects in Lund AB [http://neotechnology.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.bolt.v1.runtime.cypher; | |||
|
|||
import org.junit.Test; | |||
|
|||
import org.neo4j.bolt.v1.runtime.cypher.CypherStatementRunner.BoltQuerySession; | |||
import org.neo4j.kernel.api.security.AccessMode; | |||
import org.neo4j.kernel.impl.query.FakeTransactionalContext; | |||
import org.neo4j.kernel.impl.query.QuerySession; | |||
|
|||
import static org.hamcrest.core.IsEqual.equalTo; | |||
import static org.junit.Assert.*; | |||
|
|||
public class BoltQuerySessionTest | |||
{ | |||
@Test | |||
public void shouldIncludeUsernameInToString() | |||
{ | |||
QuerySession session = new BoltQuerySession( | |||
new FakeTransactionalContext( AccessMode.Static.READ ), "fakeSource" ); | |||
|
|||
assertThat( session.toString(), equalTo( String.format( "bolt-session\t%s\t%s", "fakeSource", "READ" ) ) ); | |||
} | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
community/kernel/src/test/java/org/neo4j/kernel/impl/query/EmbeddedQuerySessionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,45 @@ | |||
/* | |||
* Copyright (c) 2002-2016 "Neo Technology," | |||
* Network Engine for Objects in Lund AB [http://neotechnology.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.kernel.impl.query; | |||
|
|||
import org.junit.Test; | |||
|
|||
import static org.hamcrest.CoreMatchers.equalTo; | |||
import static org.junit.Assert.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
|
|||
import static org.neo4j.kernel.api.security.AccessMode.Static.WRITE_ONLY; | |||
|
|||
public class EmbeddedQuerySessionTest | |||
{ | |||
|
|||
@Test | |||
public void shouldIncludeUserNameInToString() | |||
{ | |||
TransactionalContext mock = mock( TransactionalContext.class ); | |||
when( mock.accessMode() ).thenReturn( WRITE_ONLY ); | |||
QuerySession session = QueryEngineProvider.embeddedSession( mock ); | |||
|
|||
assertThat( session.toString(), | |||
equalTo( String.format( "embedded-session\tthread\t%s\t%s", | |||
Thread.currentThread().getName(), WRITE_ONLY.name() ) ) ); | |||
} | |||
} |
123 changes: 123 additions & 0 deletions
123
community/kernel/src/test/java/org/neo4j/kernel/impl/query/FakeTransactionalContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,123 @@ | |||
/* | |||
* Copyright (c) 2002-2016 "Neo Technology," | |||
* Network Engine for Objects in Lund AB [http://neotechnology.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.kernel.impl.query; | |||
|
|||
import org.neo4j.graphdb.Lock; | |||
import org.neo4j.graphdb.PropertyContainer; | |||
import org.neo4j.kernel.GraphDatabaseQueryService; | |||
import org.neo4j.kernel.api.KernelTransaction; | |||
import org.neo4j.kernel.api.ReadOperations; | |||
import org.neo4j.kernel.api.Statement; | |||
import org.neo4j.kernel.api.dbms.DbmsOperations; | |||
import org.neo4j.kernel.api.security.AccessMode; | |||
import org.neo4j.kernel.api.txstate.TxStateHolder; | |||
|
|||
public class FakeTransactionalContext implements TransactionalContext | |||
{ | |||
private final AccessMode mode; | |||
|
|||
public FakeTransactionalContext( AccessMode mode ) { | |||
this.mode = mode; | |||
} | |||
|
|||
@Override | |||
public ReadOperations readOperations() | |||
{ | |||
throw new UnsupportedOperationException( "fake test class" ); | |||
} | |||
|
|||
@Override | |||
public DbmsOperations dbmsOperations() | |||
{ | |||
throw new UnsupportedOperationException( "fake test class" ); | |||
} | |||
|
|||
@Override | |||
public boolean isTopLevelTx() | |||
{ | |||
throw new UnsupportedOperationException( "fake test class" ); | |||
} | |||
|
|||
@Override | |||
public void close( boolean success ) | |||
{ | |||
throw new UnsupportedOperationException( "fake test class" ); | |||
} | |||
|
|||
@Override | |||
public void commitAndRestartTx() | |||
{ | |||
throw new UnsupportedOperationException( "fake test class" ); | |||
} | |||
|
|||
@Override | |||
public void cleanForReuse() | |||
{ | |||
throw new UnsupportedOperationException( "fake test class" ); | |||
} | |||
|
|||
@Override | |||
public TransactionalContext provideContext() | |||
{ | |||
throw new UnsupportedOperationException( "fake test class" ); | |||
} | |||
|
|||
@Override | |||
public boolean isOpen() | |||
{ | |||
throw new UnsupportedOperationException( "fake test class" ); | |||
} | |||
|
|||
@Override | |||
public GraphDatabaseQueryService graph() | |||
{ | |||
throw new UnsupportedOperationException( "fake test class" ); | |||
} | |||
|
|||
@Override | |||
public Statement statement() | |||
{ | |||
throw new UnsupportedOperationException( "fake test class" ); | |||
} | |||
|
|||
@Override | |||
public TxStateHolder stateView() | |||
{ | |||
throw new UnsupportedOperationException( "fake test class" ); | |||
} | |||
|
|||
@Override | |||
public Lock acquireWriteLock( PropertyContainer p ) | |||
{ | |||
throw new UnsupportedOperationException( "fake test class" ); | |||
} | |||
|
|||
@Override | |||
public AccessMode accessMode() | |||
{ | |||
return mode; | |||
} | |||
|
|||
@Override | |||
public KernelTransaction.Revertable restrictCurrentTransaction( AccessMode accessMode ) | |||
{ | |||
throw new UnsupportedOperationException( "fake test class" ); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
community/server/src/test/java/org/neo4j/server/rest/web/ServerQuerySessionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,58 @@ | |||
/* | |||
* Copyright (c) 2002-2016 "Neo Technology," | |||
* Network Engine for Objects in Lund AB [http://neotechnology.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.server.rest.web; | |||
|
|||
import javax.servlet.http.HttpServletRequest; | |||
|
|||
import org.junit.Test; | |||
|
|||
import org.neo4j.kernel.api.security.AccessMode; | |||
import org.neo4j.kernel.impl.query.FakeTransactionalContext; | |||
import org.neo4j.kernel.impl.query.QuerySession; | |||
|
|||
import static org.hamcrest.core.IsEqual.equalTo; | |||
import static org.junit.Assert.*; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
|
|||
public class ServerQuerySessionTest | |||
{ | |||
|
|||
@Test | |||
public void shouldIncludeUsernameInToString() | |||
{ | |||
QuerySession session = new ServerQuerySession( null, new FakeTransactionalContext( AccessMode.Static.READ ) ); | |||
|
|||
assertThat( session.toString(), equalTo( String.format( "server-session\t%s", "READ" ) ) ); | |||
} | |||
|
|||
@Test | |||
public void shouldIncludeUsernameInToStringWithHttp() | |||
{ | |||
HttpServletRequest mock = mock( HttpServletRequest.class ); | |||
when(mock.getRemoteAddr()).thenReturn( "remote-addr" ); | |||
when(mock.getRequestURI()).thenReturn( "req-uri" ); | |||
|
|||
QuerySession session = new ServerQuerySession( mock, new FakeTransactionalContext( AccessMode.Static.READ ) ); | |||
|
|||
assertThat( session.toString(), equalTo( String.format( "server-session\thttp\t%s\t%s\t%s", "remote-addr", "req-uri", "READ" ) ) ); | |||
} | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.