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

Commit 30346e1

Browse files
committed
Do not expand bangs when prompting for user/password
1 parent d151e1d commit 30346e1

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

cypher-shell/src/main/java/org/neo4j/shell/Main.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ private String promptForNonEmptyText(@Nonnull String prompt, @Nullable Character
172172
private String promptForText(@Nonnull String prompt, @Nullable Character mask) throws Exception {
173173
String line;
174174
ConsoleReader consoleReader = new ConsoleReader(in, out);
175+
// Disable expansion of bangs: !
176+
consoleReader.setExpandEvents(false);
177+
// Ensure Reader does not handle user input for ctrl+C behaviour
178+
consoleReader.setHandleUserInterrupt(false);
175179
line = consoleReader.readLine(prompt + ": ", mask);
176180
consoleReader.close();
177181

cypher-shell/src/test/java/org/neo4j/shell/MainTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,27 @@ public void connectInteractivelyPromptsForPassIfUserExists() throws Exception {
148148
verify(shell, times(2)).connect(connectionConfig);
149149
}
150150

151+
@Test
152+
public void connectInteractivelyPromptsHandlesBang() throws Exception {
153+
doThrow(authException).doNothing().when(shell).connect(connectionConfig);
154+
155+
String inputString = "bo!b\nsec!ret\n";
156+
InputStream inputStream = new ByteArrayInputStream(inputString.getBytes());
157+
158+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
159+
PrintStream ps = new PrintStream(baos);
160+
161+
Main main = new Main(inputStream, ps);
162+
main.connectInteractively(shell, connectionConfig);
163+
164+
String out = new String(baos.toByteArray(), StandardCharsets.UTF_8);
165+
166+
assertEquals(out, "username: bo!b\r\npassword: *******\r\n");
167+
verify(connectionConfig).setUsername("bo!b");
168+
verify(connectionConfig).setPassword("sec!ret");
169+
verify(shell, times(2)).connect(connectionConfig);
170+
}
171+
151172
@Test
152173
public void connectInteractivelyTriesOnlyOnceIfUserPassExists() throws Exception {
153174
doThrow(authException).doThrow(new RuntimeException("second try")).when(shell).connect(connectionConfig);

0 commit comments

Comments
 (0)