[GitHub] [cxf] theobisproject opened a new pull request #688: CXF-8324: Allow wider range of values for attachment properties

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] [cxf] theobisproject opened a new pull request #688: CXF-8324: Allow wider range of values for attachment properties

GitBox

theobisproject opened a new pull request #688:
URL: https://github.com/apache/cxf/pull/688


   Provide better error if the given value is not allowed
   Document allowed values for properties
   
   I also had to do some special handling if someone provides a BigInteger which has a larger value than `Long.MAX_VALUE`.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [cxf] coheigea commented on a change in pull request #688: CXF-8324: Allow wider range of values for attachment properties

GitBox

coheigea commented on a change in pull request #688:
URL: https://github.com/apache/cxf/pull/688#discussion_r469078906



##########
File path: core/src/test/java/org/apache/cxf/attachment/AttachmentUtilTest.java
##########
@@ -122,4 +133,204 @@ public void testCreateContentID() throws Exception {
         assertNotEquals(AttachmentUtil.createContentID(null), AttachmentUtil.createContentID(null));
     }
 
+    private CachedOutputStream testSetStreamedAttachmentProperties(final String property, final Object value)
+            throws IOException {
+        return testSetStreamedAttachmentProperties(property, value, new CachedOutputStream());
+    }
+
+    private CachedOutputStream testSetStreamedAttachmentProperties(final String property, final Object value,
+            final CachedOutputStream cos) throws IOException {
+        Message message = new MessageImpl();
+        message.put(property, value);
+        AttachmentUtil.setStreamedAttachmentProperties(message, cos);
+
+        return cos;
+    }
+
+    @Test
+    public void bigIntAsAttachmentMemoryThreshold() throws IOException {
+        BigInteger bigInteger = new BigInteger(String.valueOf(Long.MAX_VALUE));
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, bigInteger)) {
+            assertEquals(bigInteger.longValue(), cos.getThreshold());
+        }
+        // Overflow long value
+        bigInteger = bigInteger.add(BigInteger.ONE);
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, bigInteger)) {
+            assertEquals(AttachmentDeserializer.THRESHOLD, cos.getThreshold());
+        }
+    }
+
+    @Test
+    public void longAsAttachmentMemoryThreshold() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, Long.MAX_VALUE)) {
+            assertEquals(Long.MAX_VALUE, cos.getThreshold());
+        }
+    }
+
+    @Test
+    public void integerAsAttachmentMemoryThreshold() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, Integer.MAX_VALUE)) {
+            assertEquals(Integer.MAX_VALUE, cos.getThreshold());
+        }
+    }
+
+    @Test
+    public void shortAsAttachmentMemoryThreshold() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, Short.MAX_VALUE)) {
+            assertEquals(Short.MAX_VALUE, cos.getThreshold());
+        }
+    }
+
+    @Test
+    public void byteAsAttachmentMemoryThreshold() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, Byte.MAX_VALUE)) {
+            assertEquals(Byte.MAX_VALUE, cos.getThreshold());
+        }
+    }
+
+    @Test
+    public void numberStringAsAttachmentMemoryThreshold() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, "12345")) {
+            assertEquals(12345, cos.getThreshold());
+        }
+    }
+
+    @Test(expected = IOException.class)
+    public void nonNumberStringAsAttachmentMemoryThreshold() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, "test")) {
+            // Will throw exception
+        }
+    }
+
+    @Test(expected = IOException.class)
+    public void objectAsAttachmentMemoryThreshold() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, new Object())) {
+            // Will throw exception
+        }
+    }
+
+    @Test
+    public void bigIntAsAttachmentMaxSize() throws IOException {
+        CachedOutputStream cos = createMock(CachedOutputStream.class);
+        BigInteger bigInteger = new BigInteger(String.valueOf(Long.MAX_VALUE));
+        cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, bigInteger, cos);
+        replay(cos);
+        cos.setMaxSize(bigInteger.longValue());
+        cos.setThreshold(102400L);
+        verify(cos);
+        // Overflow long value
+        bigInteger = bigInteger.add(BigInteger.ONE);
+        cos = createMock(CachedOutputStream.class);
+        cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, bigInteger, cos);
+        replay(cos);
+        cos.setThreshold(102400L);
+        verify(cos);
+    }
+
+    @Test
+    public void longAsAttachmentMaxSize() throws IOException {
+        CachedOutputStream cos = createMock(CachedOutputStream.class);
+        cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, Long.MAX_VALUE, cos);
+        replay(cos);
+        cos.setMaxSize(Long.MAX_VALUE);
+        cos.setThreshold(102400L);
+        verify(cos);
+    }
+
+    @Test
+    public void integerAsAttachmentMaxSize() throws IOException {
+        CachedOutputStream cos = createMock(CachedOutputStream.class);
+        cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, Integer.MAX_VALUE, cos);
+        replay(cos);
+        cos.setMaxSize(Integer.MAX_VALUE);
+        cos.setThreshold(102400L);
+        verify(cos);
+    }
+
+    @Test
+    public void shortAsAttachmentMaxSize() throws IOException {
+        CachedOutputStream cos = createMock(CachedOutputStream.class);
+        cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, Short.MAX_VALUE, cos);
+        replay(cos);
+        cos.setMaxSize(Short.MAX_VALUE);
+        cos.setThreshold(102400L);
+        verify(cos);
+    }
+
+    @Test
+    public void byteAsAttachmentMaxSize() throws IOException {
+        CachedOutputStream cos = createMock(CachedOutputStream.class);
+        cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, Byte.MAX_VALUE, cos);
+        replay(cos);
+        cos.setMaxSize(Byte.MAX_VALUE);
+        cos.setThreshold(102400L);
+        verify(cos);
+    }
+
+    @Test
+    public void numberStringAsAttachmentMaxSize() throws IOException {
+        CachedOutputStream cos = createMock(CachedOutputStream.class);
+        cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, "12345", cos);
+        replay(cos);
+        cos.setMaxSize(12345);
+        cos.setThreshold(102400L);
+        verify(cos);
+    }
+
+    @Test(expected = IOException.class)
+    public void nonNumberStringAsAttachmentMaxSize() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE,
+                "test")) {
+            // Will throw exception
+        }
+    }
+
+    @Test(expected = IOException.class)
+    public void objectAsAttachmentMaxSize() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE,
+                new Object())) {
+            // Will throw exception
+        }
+    }
+
+    @Test
+    public void fileAsAttachmentDirectory() throws IOException {
+        File attachmentDirectory = new File("/dev/null");
+        CachedOutputStream cos = createMock(CachedOutputStream.class);
+        cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_DIRECTORY, attachmentDirectory,
+                cos);
+        replay(cos);
+        cos.setOutputDir(attachmentDirectory);
+        cos.setThreshold(102400L);
+        verify(cos);
+    }
+
+    @Test
+    public void stringAsAttachmentDirectory() throws IOException {
+        String attachmentDirectory = "/dev/null";

Review comment:
       Maybe for /dev/null we could instead just use something like Files.createTempDirectory instead - I'm not sure if the former would work properly on windows?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [cxf] theobisproject commented on a change in pull request #688: CXF-8324: Allow wider range of values for attachment properties

GitBox
In reply to this post by GitBox

theobisproject commented on a change in pull request #688:
URL: https://github.com/apache/cxf/pull/688#discussion_r469084741



##########
File path: core/src/test/java/org/apache/cxf/attachment/AttachmentUtilTest.java
##########
@@ -122,4 +133,204 @@ public void testCreateContentID() throws Exception {
         assertNotEquals(AttachmentUtil.createContentID(null), AttachmentUtil.createContentID(null));
     }
 
+    private CachedOutputStream testSetStreamedAttachmentProperties(final String property, final Object value)
+            throws IOException {
+        return testSetStreamedAttachmentProperties(property, value, new CachedOutputStream());
+    }
+
+    private CachedOutputStream testSetStreamedAttachmentProperties(final String property, final Object value,
+            final CachedOutputStream cos) throws IOException {
+        Message message = new MessageImpl();
+        message.put(property, value);
+        AttachmentUtil.setStreamedAttachmentProperties(message, cos);
+
+        return cos;
+    }
+
+    @Test
+    public void bigIntAsAttachmentMemoryThreshold() throws IOException {
+        BigInteger bigInteger = new BigInteger(String.valueOf(Long.MAX_VALUE));
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, bigInteger)) {
+            assertEquals(bigInteger.longValue(), cos.getThreshold());
+        }
+        // Overflow long value
+        bigInteger = bigInteger.add(BigInteger.ONE);
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, bigInteger)) {
+            assertEquals(AttachmentDeserializer.THRESHOLD, cos.getThreshold());
+        }
+    }
+
+    @Test
+    public void longAsAttachmentMemoryThreshold() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, Long.MAX_VALUE)) {
+            assertEquals(Long.MAX_VALUE, cos.getThreshold());
+        }
+    }
+
+    @Test
+    public void integerAsAttachmentMemoryThreshold() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, Integer.MAX_VALUE)) {
+            assertEquals(Integer.MAX_VALUE, cos.getThreshold());
+        }
+    }
+
+    @Test
+    public void shortAsAttachmentMemoryThreshold() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, Short.MAX_VALUE)) {
+            assertEquals(Short.MAX_VALUE, cos.getThreshold());
+        }
+    }
+
+    @Test
+    public void byteAsAttachmentMemoryThreshold() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, Byte.MAX_VALUE)) {
+            assertEquals(Byte.MAX_VALUE, cos.getThreshold());
+        }
+    }
+
+    @Test
+    public void numberStringAsAttachmentMemoryThreshold() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, "12345")) {
+            assertEquals(12345, cos.getThreshold());
+        }
+    }
+
+    @Test(expected = IOException.class)
+    public void nonNumberStringAsAttachmentMemoryThreshold() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, "test")) {
+            // Will throw exception
+        }
+    }
+
+    @Test(expected = IOException.class)
+    public void objectAsAttachmentMemoryThreshold() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(
+                AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, new Object())) {
+            // Will throw exception
+        }
+    }
+
+    @Test
+    public void bigIntAsAttachmentMaxSize() throws IOException {
+        CachedOutputStream cos = createMock(CachedOutputStream.class);
+        BigInteger bigInteger = new BigInteger(String.valueOf(Long.MAX_VALUE));
+        cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, bigInteger, cos);
+        replay(cos);
+        cos.setMaxSize(bigInteger.longValue());
+        cos.setThreshold(102400L);
+        verify(cos);
+        // Overflow long value
+        bigInteger = bigInteger.add(BigInteger.ONE);
+        cos = createMock(CachedOutputStream.class);
+        cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, bigInteger, cos);
+        replay(cos);
+        cos.setThreshold(102400L);
+        verify(cos);
+    }
+
+    @Test
+    public void longAsAttachmentMaxSize() throws IOException {
+        CachedOutputStream cos = createMock(CachedOutputStream.class);
+        cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, Long.MAX_VALUE, cos);
+        replay(cos);
+        cos.setMaxSize(Long.MAX_VALUE);
+        cos.setThreshold(102400L);
+        verify(cos);
+    }
+
+    @Test
+    public void integerAsAttachmentMaxSize() throws IOException {
+        CachedOutputStream cos = createMock(CachedOutputStream.class);
+        cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, Integer.MAX_VALUE, cos);
+        replay(cos);
+        cos.setMaxSize(Integer.MAX_VALUE);
+        cos.setThreshold(102400L);
+        verify(cos);
+    }
+
+    @Test
+    public void shortAsAttachmentMaxSize() throws IOException {
+        CachedOutputStream cos = createMock(CachedOutputStream.class);
+        cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, Short.MAX_VALUE, cos);
+        replay(cos);
+        cos.setMaxSize(Short.MAX_VALUE);
+        cos.setThreshold(102400L);
+        verify(cos);
+    }
+
+    @Test
+    public void byteAsAttachmentMaxSize() throws IOException {
+        CachedOutputStream cos = createMock(CachedOutputStream.class);
+        cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, Byte.MAX_VALUE, cos);
+        replay(cos);
+        cos.setMaxSize(Byte.MAX_VALUE);
+        cos.setThreshold(102400L);
+        verify(cos);
+    }
+
+    @Test
+    public void numberStringAsAttachmentMaxSize() throws IOException {
+        CachedOutputStream cos = createMock(CachedOutputStream.class);
+        cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, "12345", cos);
+        replay(cos);
+        cos.setMaxSize(12345);
+        cos.setThreshold(102400L);
+        verify(cos);
+    }
+
+    @Test(expected = IOException.class)
+    public void nonNumberStringAsAttachmentMaxSize() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE,
+                "test")) {
+            // Will throw exception
+        }
+    }
+
+    @Test(expected = IOException.class)
+    public void objectAsAttachmentMaxSize() throws IOException {
+        try (CachedOutputStream cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE,
+                new Object())) {
+            // Will throw exception
+        }
+    }
+
+    @Test
+    public void fileAsAttachmentDirectory() throws IOException {
+        File attachmentDirectory = new File("/dev/null");
+        CachedOutputStream cos = createMock(CachedOutputStream.class);
+        cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_DIRECTORY, attachmentDirectory,
+                cos);
+        replay(cos);
+        cos.setOutputDir(attachmentDirectory);
+        cos.setThreshold(102400L);
+        verify(cos);
+    }
+
+    @Test
+    public void stringAsAttachmentDirectory() throws IOException {
+        String attachmentDirectory = "/dev/null";

Review comment:
       As long as nobody want's to access the file this works on Windows. A File instance does not validate the path when creating it.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]


Reply | Threaded
Open this post in threaded view
|

[GitHub] [cxf] coheigea merged pull request #688: CXF-8324: Allow wider range of values for attachment properties

GitBox
In reply to this post by GitBox

coheigea merged pull request #688:
URL: https://github.com/apache/cxf/pull/688


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[hidden email]