-
Notifications
You must be signed in to change notification settings - Fork 460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WFCORE-3187] add-user.sh tool prints unexpected characters if arrow … #3064
Closed
MMarus
wants to merge
1
commit into
wildfly:master
from
mmarus-reference:WFCORE-3187-add-user.sh-prints-unexpected-characters
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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
72 changes: 72 additions & 0 deletions
72
...gement/src/main/java/org/jboss/as/domain/management/security/adduser/ReadLineHandler.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2017, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software 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 | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
|
||
package org.jboss.as.domain.management.security.adduser; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import org.aesh.readline.Prompt; | ||
import org.aesh.readline.Readline; | ||
import org.aesh.readline.ReadlineBuilder; | ||
import org.aesh.terminal.Connection; | ||
import org.aesh.terminal.tty.Signal; | ||
|
||
/** | ||
* Class to read line from terminal using Aesh-readline library. | ||
* Created by Marek Marusic <mmarusic@redhat.com> on 8/7/17. | ||
*/ | ||
class ReadLineHandler implements Consumer<Connection> { | ||
private String line; | ||
private Prompt prompt; | ||
|
||
public ReadLineHandler(Prompt prompt) { | ||
this.prompt = prompt; | ||
} | ||
|
||
public String getLine() { | ||
return line; | ||
} | ||
|
||
@Override | ||
public void accept(Connection connection) { | ||
read(connection, ReadlineBuilder.builder().enableHistory(false).build(), prompt); | ||
// lets open the connection to the terminal using this thread | ||
connection.openBlocking(); | ||
} | ||
|
||
protected void read(Connection connection, Readline readline, Prompt prompt) { | ||
// Set the Ctrl-C handler | ||
connection.setSignalHandler(signal -> { | ||
if (signal == Signal.INT) | ||
connection.close(); | ||
}); | ||
|
||
readline.readline(connection, prompt, line -> { | ||
// we specify a simple lambda consumer to read the input thats saved into line. | ||
if (line != null) { | ||
this.line = line; | ||
connection.close(); | ||
} else | ||
read(connection, readline, prompt); | ||
}); | ||
} | ||
} |
134 changes: 134 additions & 0 deletions
134
...nt/src/test/java/org/jboss/as/domain/management/security/adduser/AeshJavaConsoleTest.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2017, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software 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 | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
|
||
package org.jboss.as.domain.management.security.adduser; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.aesh.readline.terminal.Key; | ||
import org.aesh.readline.tty.terminal.TerminalConnection; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.PipedInputStream; | ||
import java.io.PipedOutputStream; | ||
import java.nio.charset.Charset; | ||
|
||
/** | ||
* Created by Marek Marusic <mmarusic@redhat.com> on 8/9/17. | ||
*/ | ||
public class AeshJavaConsoleTest { | ||
|
||
@Test | ||
public void testLeftArrow() throws IOException, InterruptedException { | ||
AeshJavaConsoleTestResource aeshJavaConsoleTestResource = new AeshJavaConsoleTestResource(); | ||
aeshJavaConsoleTestResource.start(); | ||
Thread.sleep(100); | ||
|
||
aeshJavaConsoleTestResource.write("Foo"); | ||
aeshJavaConsoleTestResource.write(Key.LEFT); | ||
aeshJavaConsoleTestResource.write("F"); | ||
aeshJavaConsoleTestResource.write(Key.ENTER); | ||
aeshJavaConsoleTestResource.flushWrites(); | ||
|
||
Thread.sleep(100); | ||
assertEquals("FoFo", aeshJavaConsoleTestResource.getLine()); | ||
} | ||
|
||
@Test | ||
public void testUpArrow() throws IOException, InterruptedException { | ||
AeshJavaConsoleTestResource aeshJavaConsoleTestResource = new AeshJavaConsoleTestResource(); | ||
aeshJavaConsoleTestResource.start(); | ||
Thread.sleep(100); | ||
|
||
aeshJavaConsoleTestResource.write("Foo"); | ||
aeshJavaConsoleTestResource.write(Key.UP); | ||
aeshJavaConsoleTestResource.write("F"); | ||
aeshJavaConsoleTestResource.write(Key.ENTER); | ||
aeshJavaConsoleTestResource.flushWrites(); | ||
|
||
Thread.sleep(100); | ||
assertEquals("FooF", aeshJavaConsoleTestResource.getLine()); | ||
} | ||
|
||
@Test | ||
public void testInterruptionSignal() throws IOException, InterruptedException { | ||
AeshJavaConsoleTestResource aeshJavaConsoleTestResource = new AeshJavaConsoleTestResource(); | ||
aeshJavaConsoleTestResource.start(); | ||
Thread.sleep(100); | ||
|
||
aeshJavaConsoleTestResource.write("Foo".getBytes()); | ||
aeshJavaConsoleTestResource.write(Key.CTRL_C.getKeyValuesAsString().getBytes()); | ||
aeshJavaConsoleTestResource.flushWrites(); | ||
|
||
Thread.sleep(100); | ||
assertEquals(false, aeshJavaConsoleTestResource.isAlive()); | ||
assertEquals(Thread.State.TERMINATED, aeshJavaConsoleTestResource.getState()); | ||
} | ||
|
||
private static class AeshJavaConsoleTestResource extends Thread { | ||
private PipedOutputStream pipedOutputStream; | ||
private PipedInputStream pipedInputStream; | ||
private ByteArrayOutputStream out; | ||
private String line; | ||
|
||
public AeshJavaConsoleTestResource() throws IOException { | ||
pipedOutputStream = new PipedOutputStream(); | ||
pipedInputStream = new PipedInputStream(pipedOutputStream); | ||
out = new ByteArrayOutputStream(); | ||
} | ||
|
||
public String getLine() { | ||
return line; | ||
} | ||
|
||
public void flushWrites() throws IOException { | ||
pipedOutputStream.flush(); | ||
} | ||
|
||
public void write(String data) throws IOException { | ||
write(data.getBytes()); | ||
} | ||
|
||
public void write(byte[] data) throws IOException { | ||
pipedOutputStream.write(data); | ||
} | ||
|
||
public void write(Key key) throws IOException { | ||
write(key.getKeyValuesAsString().getBytes()); | ||
} | ||
|
||
public void run() { | ||
// Create JavaConsole with custom input, output streams for testing | ||
JavaConsole javaConsole = new JavaConsole() { | ||
@Override | ||
protected void createTerminalConnection(ReadLineHandler readLineHandler) throws IOException { | ||
new TerminalConnection(Charset.defaultCharset(), pipedInputStream, out, readLineHandler); | ||
} | ||
}; | ||
|
||
line = javaConsole.readLine(""); | ||
} | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will let @bstansberry also comment on this dependency.
IMO I am not overly concerned as the add-user utility is destined to be deprecated and either re-written or replaced hopefully soon.