From 6c68419073b43fb29114a3af4e402c729084ed84 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Tue, 27 Jul 2021 17:41:30 +0100 Subject: [PATCH] Polishing contribution Closes gh-27216 --- .../SynchronossPartHttpMessageReader.java | 2 +- ...SynchronossPartHttpMessageReaderTests.java | 38 ++++++++----------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/SynchronossPartHttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/SynchronossPartHttpMessageReader.java index 4a77c1b5313..032b787d887 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/SynchronossPartHttpMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/SynchronossPartHttpMessageReader.java @@ -356,7 +356,7 @@ public class SynchronossPartHttpMessageReader extends LoggingCodecSupport implem this.isFilePart = (MultipartUtils.getFileName(headers) != null); this.partSize = 0; if (maxParts > 0 && index > maxParts) { - throw new DecodingException("Too many parts (" + index + "/" + maxParts + " allowed)"); + throw new DecodingException("Too many parts: Part[" + index + "] but maxParts=" + maxParts); } return this.storageFactory.newStreamStorageForPartBody(headers, index); } diff --git a/spring-web/src/test/java/org/springframework/http/codec/multipart/SynchronossPartHttpMessageReaderTests.java b/spring-web/src/test/java/org/springframework/http/codec/multipart/SynchronossPartHttpMessageReaderTests.java index 5948be6f5a1..10dbdba63a7 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/multipart/SynchronossPartHttpMessageReaderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/multipart/SynchronossPartHttpMessageReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -165,37 +165,31 @@ public class SynchronossPartHttpMessageReaderTests extends AbstractLeakCheckingT @Test void readTooManyParts() { - testMultipartExceptions(reader -> reader.setMaxParts(1), ex -> { - assertThat(ex) - .isInstanceOf(DecodingException.class) - .hasMessageStartingWith("Failure while parsing part[2]"); - assertThat(ex.getCause()) - .hasMessage("Too many parts (2/1 allowed)"); - } + testMultipartExceptions(reader -> reader.setMaxParts(1), + ex -> assertThat(ex) + .isInstanceOf(DecodingException.class) + .hasMessageStartingWith("Failure while parsing part[2]") + .hasRootCauseMessage("Too many parts: Part[2] but maxParts=1") ); } @Test void readFilePartTooBig() { - testMultipartExceptions(reader -> reader.setMaxDiskUsagePerPart(5), ex -> { - assertThat(ex) - .isInstanceOf(DecodingException.class) - .hasMessageStartingWith("Failure while parsing part[1]"); - assertThat(ex.getCause()) - .hasMessage("Part[1] exceeded the disk usage limit of 5 bytes"); - } + testMultipartExceptions(reader -> reader.setMaxDiskUsagePerPart(5), + ex -> assertThat(ex) + .isInstanceOf(DecodingException.class) + .hasMessageStartingWith("Failure while parsing part[1]") + .hasRootCauseMessage("Part[1] exceeded the disk usage limit of 5 bytes") ); } @Test void readPartHeadersTooBig() { - testMultipartExceptions(reader -> reader.setMaxInMemorySize(1), ex -> { - assertThat(ex) - .isInstanceOf(DecodingException.class) - .hasMessageStartingWith("Failure while parsing part[1]"); - assertThat(ex.getCause()) - .hasMessage("Part[1] exceeded the in-memory limit of 1 bytes"); - } + testMultipartExceptions(reader -> reader.setMaxInMemorySize(1), + ex -> assertThat(ex) + .isInstanceOf(DecodingException.class) + .hasMessageStartingWith("Failure while parsing part[1]") + .hasRootCauseMessage("Part[1] exceeded the in-memory limit of 1 bytes") ); }