Fixed tests.

This commit is contained in:
Simone Bordet 2016-03-08 11:37:05 +01:00
parent fbb27addcd
commit 87ea5ac039
3 changed files with 66 additions and 49 deletions

View File

@ -18,8 +18,6 @@
package org.eclipse.jetty.client.ssl;
import static org.hamcrest.Matchers.nullValue;
import java.io.BufferedReader;
import java.io.EOFException;
import java.io.File;
@ -1862,8 +1860,11 @@ public class SslBytesServerTest extends SslBytesTest
// Instead of passing the Client Hello, we simulate plain text was passed in
proxy.flushToServer(0, "GET / HTTP/1.1\r\n".getBytes(StandardCharsets.UTF_8));
// We expect that the server closes the connection immediately
// We expect that the server sends an alert message and closes.
TLSRecord record = proxy.readFromServer();
Assert.assertNotNull(record);
Assert.assertEquals(TLSRecord.Type.ALERT, record.getType());
record = proxy.readFromServer();
Assert.assertNull(String.valueOf(record), record);
// Check that we did not spin
@ -1982,6 +1983,6 @@ public class SslBytesServerTest extends SslBytesTest
Assert.assertEquals(record.getType(),Type.ALERT);
record = proxy.readFromServer();
}
Assert.assertThat(record,nullValue());
Assert.assertThat(record, Matchers.nullValue());
}
}

View File

@ -91,12 +91,17 @@ public class ALPNNegotiationTest extends AbstractALPNTest
Assert.assertTrue(read > 0);
// Cannot decrypt, as the SSLEngine has been already closed
// Now if we read more, we should either read the TLS Close Alert, or directly -1
// Now if we read more, we should read a TLS Alert.
encrypted.clear();
read = channel.read(encrypted);
// Sending a TLS Close Alert during handshake results in an exception when
// unwrapping that the server react to by closing the connection abruptly.
Assert.assertTrue(read < 0);
if (read > 0)
{
encrypted.flip();
// TLS Alert message type == 21.
Assert.assertEquals(21, encrypted.get() & 0xFF);
encrypted.clear();
Assert.assertEquals(-1, channel.read(encrypted));
}
}
}

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.server.ssl;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
@ -152,9 +153,19 @@ public class SslConnectionFactoryTest
out.write("Rubbish".getBytes());
out.flush();
Assert.assertThat(socket.getInputStream().read(),Matchers.equalTo(-1));
socket.setSoTimeout(1000);
InputStream input = socket.getInputStream();
int read = input.read();
// TLS Alert message type == 21.
Assert.assertThat(read, Matchers.equalTo(21));
int reads = 0;
while (read >= 0)
{
read = input.read();
++reads;
}
Assert.assertThat(reads, Matchers.lessThan(32));
}
}
private String getResponse(String sniHost,String reqHost, String cn) throws Exception