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

Commit edb593b

Browse files
committed
Fix failing tests
1 parent fa569cb commit edb593b

File tree

6 files changed

+58
-18
lines changed

6 files changed

+58
-18
lines changed

cypher-shell/src/integration-test/java/org/neo4j/shell/MainIntegrationTest.java

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import static org.mockito.Mockito.mock;
3535
import static org.mockito.Mockito.verify;
3636
import static org.mockito.Mockito.verifyNoMoreInteractions;
37+
import static org.neo4j.shell.util.Versions.majorVersion;
3738

3839
public class MainIntegrationTest
3940
{
@@ -84,10 +85,21 @@ public void setup() {
8485
}
8586

8687
private void ensureUser() throws Exception {
87-
shell.execute(":use " + DatabaseManager.SYSTEM_DB_NAME);
88-
shell.execute("CREATE OR REPLACE USER foo SET PASSWORD 'pass';");
89-
shell.execute("GRANT ROLE reader TO foo;");
90-
shell.execute(":use");
88+
if (majorVersion(shell.getServerVersion() ) >= 4) {
89+
shell.execute(":use " + DatabaseManager.SYSTEM_DB_NAME);
90+
shell.execute("CREATE OR REPLACE USER foo SET PASSWORD 'pass';");
91+
shell.execute("GRANT ROLE reader TO foo;");
92+
shell.execute(":use");
93+
} else {
94+
try {
95+
shell.execute("CALL dbms.security.createUser('foo', 'pass', true)");
96+
} catch (ClientException e) {
97+
if (e.code().equalsIgnoreCase("Neo.ClientError.General.InvalidArguments") && e.getMessage().contains("already exists")) {
98+
shell.execute("CALL dbms.security.deleteUser('foo')");
99+
shell.execute("CALL dbms.security.createUser('foo', 'pass', true)");
100+
}
101+
}
102+
}
91103
}
92104

93105
@Test
@@ -140,12 +152,28 @@ public void promptsOnPasswordChangeRequired() throws Exception {
140152

141153
// then
142154
assertTrue(shell.isConnected());
143-
// should have prompted to change the password
144-
String expectedChangePasswordOutput = format( "username: foo%npassword: ****%nPassword change required%nnew password: *******%n" );
145-
assertEquals(expectedLoginOutput + expectedChangePasswordOutput, baos.toString());
146-
assertEquals("foo", connectionConfig.username());
147-
assertEquals("newpass", connectionConfig.password());
148-
assertNull(connectionConfig.newPassword());
155+
if (majorVersion(shell.getServerVersion() ) >= 4) {
156+
// should have prompted to change the password
157+
String expectedChangePasswordOutput = format( "username: foo%npassword: ****%nPassword change required%nnew password: *******%n" );
158+
assertEquals(expectedLoginOutput + expectedChangePasswordOutput, baos.toString());
159+
assertEquals("foo", connectionConfig.username());
160+
assertEquals("newpass", connectionConfig.password());
161+
assertNull(connectionConfig.newPassword());
162+
163+
// Should be able to execute read query
164+
shell.execute("MATCH (n) RETURN count(n)");
165+
} else {
166+
// in 3.x we do not get credentials expired exception on connection, but when we try to access data
167+
String expectedChangePasswordOutput = format( "username: foo%npassword: ****%n" );
168+
assertEquals(expectedLoginOutput + expectedChangePasswordOutput, baos.toString());
169+
assertEquals("foo", connectionConfig.username());
170+
assertEquals("pass", connectionConfig.password());
171+
172+
// Should get exception with instructions on how to change password using procedure
173+
exception.expect(ClientException.class);
174+
exception.expectMessage("CALL dbms.changePassword");
175+
shell.execute("MATCH (n) RETURN count(n)");
176+
}
149177
}
150178

151179
@Test

cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellMultiDatabaseIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import static org.neo4j.shell.DatabaseManager.ABSENT_DB_NAME;
2424
import static org.neo4j.shell.DatabaseManager.DEFAULT_DEFAULT_DB_NAME;
2525
import static org.neo4j.shell.DatabaseManager.SYSTEM_DB_NAME;
26-
import static org.neo4j.shell.Versions.majorVersion;
26+
import static org.neo4j.shell.util.Versions.majorVersion;
2727

2828
public class CypherShellMultiDatabaseIntegrationTest
2929
{

cypher-shell/src/integration-test/java/org/neo4j/shell/commands/CypherShellVerboseIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import static org.junit.Assert.assertEquals;
2222
import static org.junit.Assert.assertTrue;
2323
import static org.junit.Assume.assumeTrue;
24-
import static org.neo4j.shell.Versions.majorVersion;
25-
import static org.neo4j.shell.Versions.minorVersion;
24+
import static org.neo4j.shell.util.Versions.majorVersion;
25+
import static org.neo4j.shell.util.Versions.minorVersion;
2626

2727
public class CypherShellVerboseIntegrationTest extends CypherShellIntegrationTest {
2828
@Rule

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.neo4j.shell.exception.CommandException;
2323
import org.neo4j.shell.log.NullLogging;
2424

25+
import static org.neo4j.shell.util.Versions.majorVersion;
26+
2527
/**
2628
* Handles interactions with the driver
2729
*/
@@ -253,8 +255,15 @@ public void changePassword(@Nonnull ConnectionConfig connectionConfig) {
253255
.withDatabase(SYSTEM_DB_NAME);
254256
session = driver.session(builder.build());
255257

256-
String command = "ALTER CURRENT USER SET PASSWORD FROM $o TO $n";
257-
Value parameters = Values.parameters("o", connectionConfig.password(), "n", connectionConfig.newPassword());
258+
String command;
259+
Value parameters;
260+
if (majorVersion(getServerVersion()) >= 4) {
261+
command = "ALTER CURRENT USER SET PASSWORD FROM $o TO $n";
262+
parameters = Values.parameters("o", connectionConfig.password(), "n", connectionConfig.newPassword());
263+
} else {
264+
command = "CALL dbms.security.changePassword($n)";
265+
parameters = Values.parameters("n", connectionConfig.newPassword());
266+
}
258267

259268
StatementResult run = session.run(command, parameters);
260269
run.consume();
@@ -364,7 +373,10 @@ private Optional<List<BoltResult>> captureResults(@Nonnull List<Statement> trans
364373
List<BoltResult> results = executeWithRetry(transactionStatements, (statement, transaction) -> {
365374
// calling list() is what actually executes cypher on the server
366375
StatementResult sr = transaction.run(statement);
367-
BoltResult singleResult = new ListBoltResult(sr.list(), sr.consume(), sr.keys());
376+
List<Record> list = sr.list();
377+
List<String> keys = sr.keys();
378+
ResultSummary summary = sr.consume();
379+
BoltResult singleResult = new ListBoltResult(list, summary, keys );
368380
updateActualDbName(singleResult.getSummary());
369381
return singleResult;
370382
});

cypher-shell/src/integration-test/java/org/neo4j/shell/Version.java renamed to cypher-shell/src/main/java/org/neo4j/shell/util/Version.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.neo4j.shell;
1+
package org.neo4j.shell.util;
22

33
import static java.lang.String.format;
44

cypher-shell/src/integration-test/java/org/neo4j/shell/Versions.java renamed to cypher-shell/src/main/java/org/neo4j/shell/util/Versions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.neo4j.shell;
1+
package org.neo4j.shell.util;
22

33
import static java.lang.Integer.parseInt;
44
import static java.lang.String.format;

0 commit comments

Comments
 (0)