diff --git a/src/main/java/com/epam/aidial/core/storage/ResourceDescription.java b/src/main/java/com/epam/aidial/core/storage/ResourceDescription.java index fb5361b03..a74ba2ddb 100644 --- a/src/main/java/com/epam/aidial/core/storage/ResourceDescription.java +++ b/src/main/java/com/epam/aidial/core/storage/ResourceDescription.java @@ -7,6 +7,7 @@ import lombok.Data; import org.apache.commons.lang3.StringUtils; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -14,6 +15,9 @@ @Data @AllArgsConstructor(access = AccessLevel.PRIVATE) public class ResourceDescription { + + private static final int MAX_PATH_SIZE = 900; + ResourceType type; String name; List parentFolders; @@ -95,7 +99,11 @@ public static ResourceDescription fromEncoded(ResourceType type, String bucketNa verify(isValidFilename(element), "Invalid path provided " + urlEncodedRelativePath) ); - return from(type, bucketName, bucketLocation, urlEncodedRelativePath, elements, BlobStorageUtil.isFolder(urlEncodedRelativePath)); + ResourceDescription resource = from(type, bucketName, bucketLocation, urlEncodedRelativePath, elements, BlobStorageUtil.isFolder(urlEncodedRelativePath)); + verify(resource.getAbsoluteFilePath().getBytes(StandardCharsets.UTF_8).length <= MAX_PATH_SIZE, + "Resource path exceeds max allowed size: " + MAX_PATH_SIZE); + + return resource; } /** diff --git a/src/test/java/com/epam/aidial/core/ResourceApiTest.java b/src/test/java/com/epam/aidial/core/ResourceApiTest.java index 5fcc7723f..d184e0241 100644 --- a/src/test/java/com/epam/aidial/core/ResourceApiTest.java +++ b/src/test/java/com/epam/aidial/core/ResourceApiTest.java @@ -166,7 +166,13 @@ void testWorkflow() { } @Test - void testLimit() { + void testMaxKeySize() { + Response response = request(HttpMethod.PUT, "/" + "1".repeat(900), "body"); + verify(response, 400, "Resource path exceeds max allowed size: 900"); + } + + @Test + void testMaxContentSize() { Response response = request(HttpMethod.PUT, "/folder/big", "1".repeat(1024 * 1024 + 1)); verify(response, 413, "Resource size: 1048577 exceeds max limit: 1048576"); }