Bug#1104933: activemq: diff for NMU version 5.17.6+dfsg-1.1 (20/48)
From
Emmanuel Arias@1:229/2 to
All on Sun Jun 1 01:20:01 2025
[continued from previous message]
++import javax.jms.InvalidClientIDException;
++import javax.jms.JMSException;
++import org.apache.activemq.ActiveMQConnection;
++import org.apache.activemq.MaxFrameSizeExceededException;
++import org.apache.activemq.command.WireFormatInfo;
++import org.junit.Test;
++
++import java.io.IOException;
++import java.lang.reflect.Field;
++
++import static org.junit.Assert.assertEquals;
++import static org.junit.Assert.fail;
++
++public class OpenWireUtilTest {
++
++ @Test
++ public void testValidateIsThrowable() {
++ OpenWireUtil.validateIsThrowable(Exception.class);
++ OpenWireUtil.validateIsThrowable(Throwable.class);
++ OpenWireUtil.validateIsThrowable(JMSException.class);
++ OpenWireUtil.validateIsThrowable(InvalidClientIDException.class);
++
++ try {
++ OpenWireUtil.validateIsThrowable(String.class);
++ fail("Not a valid Throwable");
++ } catch (IllegalArgumentException e) {
++ // expected
++ }
++
++ try {
++ OpenWireUtil.validateIsThrowable(ActiveMQConnection.class);
++ fail("Not a valid Throwable");
++ } catch (IllegalArgumentException e) {
++ // expected
++ }
++ }
++
++ @Test
++ public void testConvertJmsPackage() {
++ // should not change
++ assertEquals(InvalidClientIDException.class.getName(),
++ OpenWireUtil.convertJmsPackage(InvalidClientIDException.class.getName()));
++
++ // should convert to correct exception type
++ assertEquals(InvalidClientIDException.class.getName(),
++ OpenWireUtil.convertJmsPackage(OpenWireUtil.jmsPackageToReplace + ".InvalidClientIDException"));
++ }
++
++ @Test
++ public void testValidateBufferSize() throws IOException {
++ OpenWireFormatFactory factory = new OpenWireFormatFactory();
++
++ var wireFormat = (OpenWireFormat) factory.createWireFormat();
++
++ // Nothing set, no validation
++ OpenWireUtil.validateBufferSize(wireFormat, 2048);
++
++ // verify max frame check works
++ try {
++ wireFormat.setMaxFrameSize(1024);
++ OpenWireUtil.validateBufferSize(wireFormat, 2048);
++ fail("should have failed");
++ } catch (MaxFrameSizeExceededException e) {
++ // expected
++ }
++
++ // rest max frame size back so we can test validating current size
++ // is less than expected buffer size
++ wireFormat.setMaxFrameSize(OpenWireFormat.DEFAULT_MAX_FRAME_SIZE);
++ WireFormatInfo wfi = new WireFormatInfo();
++ wfi.setProperty("test", "test");
++
++ // should be no error for the first 2 calls, last call should
++ // go over frame size and error
++ initContext(wireFormat, 2048);
++ OpenWireUtil.validateBufferSize(wireFormat, 1024);
++ OpenWireUtil.validateBufferSize(wireFormat, 1024);
++ try {
++ OpenWireUtil.validateBufferSize(wireFormat, 1);
++ fail("should have failed");
++ } catch (IOException e) {
++ // expected
++ }
++ }
++
++ @SuppressWarnings("unchecked")
++ private void initContext(OpenWireFormat format, int frameSize) throws IOException {
++ try {
++ Field mcThreadLocalField = OpenWireFormat.class.getDeclaredField("marshallingContext");
++ mcThreadLocalField.setAccessible(true);
++ var mcThreadLocal = (ThreadLocal<OpenWireFormat.MarshallingContext>) mcThreadLocalField.get(format);
++ var context = new OpenWireFormat.MarshallingContext();
++ context.setFrameSize(frameSize);
++ mcThreadLocal.set(context);
++ } catch (ReflectiveOperationException e) {
++ throw new RuntimeException(e);
++ }
++ }
++
++}
+--- a/activemq-client/src/test/java/org/apache/activemq/openwire/OpenWireValidationTest.java
++++ b/activemq-client/src/test/java/org/apache/activemq/openwire/OpenWireValidationTest.java
+@@ -16,25 +16,31 @@
+ */
+ package org.apache.activemq.openwire;
+
+-import static org.junit.Assert.assertTrue;
+-
++import java.io.DataInputStream;
+ import java.io.DataOutput;
+ import java.io.IOException;
++import java.lang.reflect.InvocationTargetException;
+ import java.lang.reflect.Method;
++import java.nio.ByteBuffer;
++import java.nio.charset.StandardCharsets;
+ import java.util.ArrayList;
+ import java.util.Collection;
+ import java.util.List;
+-import org.apache.activemq.command.CommandTypes;
+-import org.apache.activemq.command.ExceptionResponse;
++import javassist.util.proxy.MethodHandler;
++import javassist.util.proxy.ProxyFactory;
++import javassist.util.proxy.ProxyObject;
++import org.apache.activemq.command.*;
++import org.apache.activemq.transport.nio.NIOInputStream;
+ import org.apache.activemq.util.ByteSequence;
+ import org.junit.Test;
+ import org.junit.runner.RunWith;
+ import org.junit.runners.Parameterized;
+ import org.junit.runners.Parameterized.Parameters;
+
++import static org.junit.Assert.*;
++
+ /**
+- * Test that Openwire marshalling will validate Throwable types during
+- * unmarshalling commands that contain a Throwable
++ * Test that Openwire marshalling will validate commands correctly
+ */
+ @RunWith(Parameterized.class)
+ public class OpenWireValidationTest {
+@@ -53,7 +59,7 @@
+ // This will make sure that we don't forget to update this test to include
+ // any future versions that are generated
+ assertTrue("List of Openwire versions does not include latest version",
+- versions.contains((int)CommandTypes.PROTOCOL_VERSION));
++ versions.contains((int) CommandTypes.PROTOCOL_VERSION));
+
+ return versionObjs;
+ }
+@@ -63,20 +69,97 @@
+ }
+
+ @Test
++ public void testLooseUnmarshalByteSequenceValidation() throws Exception { ++ testUnmarshalByteSequenceValidation(false);
++ }
++
++ @Test
++ public void testTightUnmarshalByteSequenceValidation() throws Exception { ++ testUnmarshalByteSequenceValidation(true);
++ }
++
++ @Test
++ public void testLooseUnmarshalByteArray() throws Exception {
++ testUnmarshalByteArray(false);
++ }
++
++ @Test
++ public void testTightUnmarshalByteArray() throws Exception {
++ testUnmarshalByteArray(true);
++ }
++
++ // WireFormatInfo eventually delegates to BaseDataStreamMarshaller#tightUnmarshalByteSequence() and
++ // BaseDataStreamMarshaller#looseUnmarshalByteSequence()
++ private void testUnmarshalByteSequenceValidation(boolean tightEncoding) throws Exception {
++ WireFormatInfo wfi = new WireFormatInfo();
++ wfi.setProperty("prop1", "val1");
++ testUnmarshal(wfi, tightEncoding);
++ }
++
++ // PartialCommand eventually delegates to BaseDataStreamMarshaller#tightUnmarshalByteArray()
++ // and BaseDataStreamMarshaller#looseUnmarshalByteArray()
++ private void testUnmarshalByteArray(boolean tightEncoding) throws Exception {
++ PartialCommand pc = new PartialCommand();
++ pc.setData("bytes".getBytes(StandardCharsets.UTF_8));
++ testUnmarshal(pc, tightEncoding);
++ }
++
++ private void testUnmarshal(Command command, boolean tightEncoding) throws Exception {
++ var format = setupWireFormat(tightEncoding);
++ ByteSequence bss = format.marshal(command);
++ try {
[continued in next message]
--- SoupGate-Win32 v1.05
* Origin: you cannot sedate... all the things you hate (1:229/2)