diff --git a/src/main/java/com/epam/aidial/core/util/UrlUtil.java b/src/main/java/com/epam/aidial/core/util/UrlUtil.java index e31ac197b..d57aef4e0 100644 --- a/src/main/java/com/epam/aidial/core/util/UrlUtil.java +++ b/src/main/java/com/epam/aidial/core/util/UrlUtil.java @@ -20,6 +20,9 @@ public String encodePath(String path) { public String decodePath(String path) { try { URI uri = new URI(path); + if (uri.getRawFragment() != null || uri.getRawQuery() != null) { + throw new IllegalArgumentException("Wrong path provided " + path); + } return uri.getPath(); } catch (URISyntaxException e) { throw new RuntimeException(e); diff --git a/src/test/java/com/epam/aidial/core/FileApiTest.java b/src/test/java/com/epam/aidial/core/FileApiTest.java index e43e380f5..b117afbfe 100644 --- a/src/test/java/com/epam/aidial/core/FileApiTest.java +++ b/src/test/java/com/epam/aidial/core/FileApiTest.java @@ -211,7 +211,7 @@ public void testFileUpload(Vertx vertx, VertxTestContext context) { FolderMetadata emptyFolderResponse = new FolderMetadata("7G9WZNcoY26Vy9D7bEgbv6zqbJGfyDp9KZyEbJR4XMZt", null, null, "7G9WZNcoY26Vy9D7bEgbv6zqbJGfyDp9KZyEbJR4XMZt/", List.of()); FileMetadata expectedFileMetadata = new FileMetadata("7G9WZNcoY26Vy9D7bEgbv6zqbJGfyDp9KZyEbJR4XMZt", - "file.txt", null, "7G9WZNcoY26Vy9D7bEgbv6zqbJGfyDp9KZyEbJR4XMZt/file.txt", 17, "text/custom"); + "файл.txt", null, "7G9WZNcoY26Vy9D7bEgbv6zqbJGfyDp9KZyEbJR4XMZt/%D1%84%D0%B0%D0%B9%D0%BB.txt", 17, "text/custom"); FolderMetadata expectedFolderMetadata = new FolderMetadata("7G9WZNcoY26Vy9D7bEgbv6zqbJGfyDp9KZyEbJR4XMZt", null, null, "7G9WZNcoY26Vy9D7bEgbv6zqbJGfyDp9KZyEbJR4XMZt/", List.of(expectedFileMetadata)); @@ -234,10 +234,10 @@ public void testFileUpload(Vertx vertx, VertxTestContext context) { }).compose((mapper) -> { Promise promise = Promise.promise(); // upload test file - client.put(serverPort, "localhost", "/v1/files/7G9WZNcoY26Vy9D7bEgbv6zqbJGfyDp9KZyEbJR4XMZt/file.txt") + client.put(serverPort, "localhost", "/v1/files/7G9WZNcoY26Vy9D7bEgbv6zqbJGfyDp9KZyEbJR4XMZt/%D1%84%D0%B0%D0%B9%D0%BB.txt") .putHeader("Api-key", "proxyKey2") .as(BodyCodec.json(FileMetadata.class)) - .sendMultipartForm(generateMultipartForm("file.txt", TEST_FILE_CONTENT, "text/custom"), + .sendMultipartForm(generateMultipartForm("файл.txt", TEST_FILE_CONTENT, "text/custom"), context.succeeding(response -> { context.verify(() -> { assertEquals(200, response.statusCode()); diff --git a/src/test/java/com/epam/aidial/core/util/UrlUtilTest.java b/src/test/java/com/epam/aidial/core/util/UrlUtilTest.java index 68082676c..7b64e7641 100644 --- a/src/test/java/com/epam/aidial/core/util/UrlUtilTest.java +++ b/src/test/java/com/epam/aidial/core/util/UrlUtilTest.java @@ -3,6 +3,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class UrlUtilTest { @@ -10,6 +11,7 @@ public class UrlUtilTest { public void testPathEncoding() { assertEquals("folder%201", UrlUtil.encodePath("folder 1")); assertEquals("folder%20%23", UrlUtil.encodePath("folder #")); + assertEquals("%D1%84%D0%B0%D0%B9%D0%BB.txt", UrlUtil.encodePath("файл.txt")); assertEquals("fo$l+=d,e%23r%201", UrlUtil.encodePath("fo$l+=d,e#r 1")); } @@ -19,5 +21,8 @@ public void testPathDecoding() { assertEquals("folder #", UrlUtil.decodePath("folder%20%23")); assertEquals("fo$l+=d,e#r 1", UrlUtil.decodePath("fo$l+=d,e%23r%201")); assertEquals("fo$l+=d,e#r 1", UrlUtil.decodePath("fo%24l%2B%3Dd%2Ce%23r%201")); + assertEquals("файл.txt", UrlUtil.decodePath("%D1%84%D0%B0%D0%B9%D0%BB.txt")); + assertThrows(IllegalArgumentException.class, () -> UrlUtil.decodePath("/folder1/file#5.txt")); + assertThrows(IllegalArgumentException.class, () -> UrlUtil.decodePath("/folder1/q?file=5.txt")); } }