提交 e062b692 编写于 作者: oldratlee's avatar oldratlee 🔥

Merge remote-tracking branch 'origin/dubbo-2.4.x-dev' into dubbo-2.4.x-dev

......@@ -113,6 +113,7 @@ public class ExchangeCodec extends TelnetCodec {
// get data length.
int len = Bytes.bytes2int(header, 12);
checkPayload(channel, len);
int tt = len + HEADER_LENGTH;
if( readable < tt ) {
......@@ -124,7 +125,6 @@ public class ExchangeCodec extends TelnetCodec {
is = StreamUtils.limitedInputStream(is, len);
try {
checkPayload(channel, len);
return decodeBody(channel, is, header);
} finally {
if (is.available() > 0) {
......
......@@ -151,7 +151,18 @@ public class ExchangeCodecTest extends TelnetCodecTest{
byte[] header = new byte[] { MAGIC_HIGH , MAGIC_LOW , 0 ,0 ,0 ,0 ,0 , 0 ,0 ,0 ,0 };
testDecode_assertEquals(header, TelnetCodec.NEED_MORE_INPUT);
}
@Test
public void test_Decode_Check_Payload() throws IOException {
byte[] header = new byte[]{MAGIC_HIGH, MAGIC_LOW, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
byte[] request = assemblyDataProtocol(header);
try {
testDecode_assertEquals(request, TelnetCodec.NEED_MORE_INPUT);
Assert.fail();
} catch (IOException expected) {
Assert.assertTrue(expected.getMessage().startsWith("Data length too large: " + Bytes.bytes2int(new byte[]{1, 1, 1, 1})));
}
}
@Test
public void test_Decode_Body_Need_Readmore() throws IOException{
byte[] header = new byte[] { MAGIC_HIGH , MAGIC_LOW , 0 ,0 ,0 ,0 ,0 , 0 ,0 ,0 ,0, 0, 0, 0 , 1 ,1, 'a', 'a' };
......@@ -320,7 +331,7 @@ public class ExchangeCodecTest extends TelnetCodecTest{
Response response = new Response();
response.setHeartbeat(true);
response.setId(1001l);
response.setStatus((byte)20 );
response.setStatus((byte) 20);
response.setVersion("11");
Person person = new Person();
response.setResult(person);
......@@ -407,36 +418,6 @@ public class ExchangeCodecTest extends TelnetCodecTest{
Assert.assertTrue(date.equals(decodedRequest.getData()));
}
@Test
public void testMessageLengthExceedPayloadLimit() throws Exception {
Request request = new Request(1L);
request.setData("hello");
UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream(512);
Channel channel = getCliendSideChannel(url);
codec.encode(channel, bos, request);
byte [] requestMessage = bos.toByteArray();
byte[] message = new byte[requestMessage.length * 2];
System.arraycopy(requestMessage, 0, message, 0, requestMessage.length);
System.arraycopy(requestMessage, 0, message, requestMessage.length, requestMessage.length);
channel = getServerSideChannel(
url.addParameter(Constants.PAYLOAD_KEY, requestMessage.length - 16 /* head length */ - 2));
UnsafeByteArrayInputStream bis = new UnsafeByteArrayInputStream(message);
try {
codec.decode(channel, bis);
Assert.fail();
} catch (IOException e) {
Assert.assertTrue(e.getMessage().startsWith("Data length too large: " + (requestMessage.length - 16 /* head length */)));
}
channel = getServerSideChannel(url.addParameter(Constants.PAYLOAD_KEY, Constants.DEFAULT_PAYLOAD));
Object object = codec.decode(channel, bis);
Assert.assertTrue(object instanceof Request);
Request decodeRequest = (Request)object;
Assert.assertEquals(request.getId(), decodeRequest.getId());
Assert.assertEquals(request.getData(), decodeRequest.getData());
}
@Test
public void testMessageLengthExceedPayloadLimitWhenEncode() throws Exception {
Request request = new Request(1L);
......@@ -458,5 +439,6 @@ public class ExchangeCodecTest extends TelnetCodecTest{
Assert.assertTrue(channel.getReceivedMessage() instanceof Response);
Response receiveMessage = (Response)channel.getReceivedMessage();
Assert.assertEquals(Response.BAD_RESPONSE, receiveMessage.getStatus());
Assert.assertTrue(receiveMessage.getErrorMessage().contains("Data length too large: "));
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册