Skip to content

Commit

Permalink
feat: check resource key size (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
artsiomkorzun authored Feb 8, 2024
1 parent 5480b21 commit ba607b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
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;

@Data
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class ResourceDescription {

private static final int MAX_PATH_SIZE = 900;

ResourceType type;
String name;
List<String> parentFolders;
Expand Down Expand Up @@ -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;
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/test/java/com/epam/aidial/core/ResourceApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit ba607b9

Please sign in to comment.