1
mirror of https://github.com/rapid7/metasploit-payloads synced 2025-03-24 18:16:24 +01:00

wait up to 5 seconds for shell output before checking the result.

otherwise, we can jumpt the gun and fail the test randomly
This commit is contained in:
Brent Cook 2015-03-26 01:14:38 -05:00
parent fdebac9f9d
commit 5998658155

@ -15,6 +15,11 @@ public class ShellTest extends TestCase {
DataInputStream in = new DataInputStream(new ByteArrayInputStream(commands.getBytes("ISO-8859-1"))); DataInputStream in = new DataInputStream(new ByteArrayInputStream(commands.getBytes("ISO-8859-1")));
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
shell.start(in, out, new String[] {"Payload", "--", "Shell"}); shell.start(in, out, new String[] {"Payload", "--", "Shell"});
int timeout = 5000;
while (out.size() == 0 && timeout > 0) {
Thread.sleep(100);
timeout -= 100;
}
String shellOutput = new String(out.toByteArray(), "ISO-8859-1"); String shellOutput = new String(out.toByteArray(), "ISO-8859-1");
Assert.assertTrue("MagicToken missing in shell output: "+shellOutput, shellOutput.contains("MagicToken")); Assert.assertTrue("MagicToken missing in shell output: "+shellOutput, shellOutput.contains("MagicToken"));
Assert.assertEquals(-1, in.read()); Assert.assertEquals(-1, in.read());