Merged branch 'jetty-9.4.x' into 'master'.

This commit is contained in:
Simone Bordet 2017-01-19 15:22:40 +01:00
commit cf46ad473b
1 changed files with 21 additions and 11 deletions

View File

@ -30,8 +30,8 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSocket;
import org.eclipse.jetty.alpn.ALPN; import org.eclipse.jetty.alpn.ALPN;
import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.BufferUtil;
@ -91,13 +91,17 @@ public class ALPNNegotiationTest extends AbstractALPNTest
Assert.assertTrue(read > 0); Assert.assertTrue(read > 0);
// Cannot decrypt, as the SSLEngine has been already closed // Cannot decrypt, as the SSLEngine has been already closed
// Now if we read more, we should read a TLS Alert. // It may happen that the read() above read both the ServerHello and the TLS Close Alert.
// Now if we can read more, we should read the TLS Close Alert and then the TCP FIN.
encrypted.clear(); encrypted.clear();
read = channel.read(encrypted); read = channel.read(encrypted);
Assert.assertTrue(read > 0); if (read > 0)
Assert.assertEquals(21, encrypted.get(0)); {
encrypted.clear(); encrypted.flip();
Assert.assertEquals(-1, channel.read(encrypted)); Assert.assertEquals(21, encrypted.get());
encrypted.clear();
Assert.assertEquals(-1, channel.read(encrypted));
}
} }
} }
@ -147,12 +151,18 @@ public class ALPNNegotiationTest extends AbstractALPNTest
ByteBuffer decrypted = ByteBuffer.allocate(sslEngine.getSession().getApplicationBufferSize()); ByteBuffer decrypted = ByteBuffer.allocate(sslEngine.getSession().getApplicationBufferSize());
sslEngine.unwrap(encrypted, decrypted); sslEngine.unwrap(encrypted, decrypted);
// Now if we read more, we should read the TLS Close Alert. // It may happen that the read() above read both the ServerHello and the TLS Close Alert.
if (!encrypted.hasRemaining())
{
// Now if we can read more, we should read the TLS Close Alert and then the TCP FIN.
encrypted.clear();
read = channel.read(encrypted);
Assert.assertTrue(read > 0);
encrypted.flip();
}
Assert.assertEquals(21, encrypted.get());
encrypted.clear(); encrypted.clear();
read = channel.read(encrypted); Assert.assertEquals(-1, channel.read(encrypted));
encrypted.flip();
Assert.assertTrue(read > 0);
Assert.assertEquals(21, encrypted.get(0));
} }
} }