Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit 3a35140

Browse files
authored
Merge pull request #74 from praveenag/master
empty password will give relevant error.
2 parents f127eb6 + fc344b6 commit 3a35140

File tree

3 files changed

+47
-15
lines changed

3 files changed

+47
-15
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.neo4j.shell.commands;
2+
3+
4+
import org.junit.Before;
5+
import org.junit.Rule;
6+
import org.junit.Test;
7+
import org.junit.rules.ExpectedException;
8+
import org.neo4j.shell.ConnectionConfig;
9+
import org.neo4j.shell.CypherShell;
10+
import org.neo4j.shell.cli.Format;
11+
import org.neo4j.shell.exception.CommandException;
12+
import org.neo4j.shell.log.Logger;
13+
14+
import static org.mockito.Mockito.doReturn;
15+
import static org.mockito.Mockito.mock;
16+
17+
public class CypherShellFailureIntegrationTest {
18+
@Rule
19+
public final ExpectedException thrown = ExpectedException.none();
20+
21+
private Logger logger = mock(Logger.class);
22+
private CypherShell shell;
23+
24+
@Before
25+
public void setUp() throws Exception {
26+
doReturn(Format.VERBOSE).when(logger).getFormat();
27+
28+
shell = new CypherShell(logger);
29+
}
30+
31+
@Test
32+
public void cypherWithNoPasswordShouldReturnValidError() throws CommandException {
33+
thrown.expectMessage("The client is unauthorized due to authentication failure.");
34+
35+
shell.connect(new ConnectionConfig(logger, "bolt://", "localhost", 7687, "neo4j", "", true));
36+
}
37+
}

cypher-shell/src/main/java/org/neo4j/shell/state/BoltStateHandler.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,7 @@ public void connect(@Nonnull ConnectionConfig connectionConfig) throws CommandEx
9393
throw new CommandException("Already connected");
9494
}
9595

96-
final AuthToken authToken;
97-
if (!connectionConfig.username().isEmpty() && !connectionConfig.password().isEmpty()) {
98-
authToken = AuthTokens.basic(connectionConfig.username(), connectionConfig.password());
99-
} else {
100-
authToken = null;
101-
}
96+
final AuthToken authToken = AuthTokens.basic(connectionConfig.username(), connectionConfig.password());
10297

10398
try {
10499
driver = getDriver(connectionConfig, authToken);

cypher-shell/src/test/java/org/neo4j/shell/state/BoltStateHandlerTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@ public void versionIsNotEmptyAfterConnect() throws CommandException {
8686
assertEquals("9.4.1-ALPHA", handler.getServerVersion());
8787
}
8888

89-
private void stubVersion(StatementResult resultMock, String value) {
90-
ResultSummary resultSummary = mock(ResultSummary.class);
91-
ServerInfo serverInfo = mock(ServerInfo.class);
92-
93-
when(resultSummary.server()).thenReturn(serverInfo);
94-
when(serverInfo.version()).thenReturn(value);
95-
when(resultMock.summary()).thenReturn(resultSummary);
96-
}
97-
9889
@Test
9990
public void closeTransactionAfterRollback() throws CommandException {
10091
boltStateHandler.connect();
@@ -290,6 +281,15 @@ public void turnOnEncryptionIfRequested() throws CommandException {
290281
/**
291282
* Bolt state with faked bolt interactions
292283
*/
284+
private void stubVersion(StatementResult resultMock, String value) {
285+
ResultSummary resultSummary = mock(ResultSummary.class);
286+
ServerInfo serverInfo = mock(ServerInfo.class);
287+
288+
when(resultSummary.server()).thenReturn(serverInfo);
289+
when(serverInfo.version()).thenReturn(value);
290+
when(resultMock.summary()).thenReturn(resultSummary);
291+
}
292+
293293
private static class OfflineBoltStateHandler extends BoltStateHandler {
294294

295295
public OfflineBoltStateHandler(Driver driver) {

0 commit comments

Comments
 (0)