Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksim_Hadalau authored and Maksim_Hadalau committed Dec 19, 2023
1 parent 266041c commit 9653f7c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/epam/aidial/core/util/UrlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/epam/aidial/core/FileApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -234,10 +234,10 @@ public void testFileUpload(Vertx vertx, VertxTestContext context) {
}).compose((mapper) -> {
Promise<Void> 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());
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/com/epam/aidial/core/util/UrlUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
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 {

@Test
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"));
}

Expand All @@ -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"));
}
}

0 comments on commit 9653f7c

Please sign in to comment.