mirror of
https://github.com/headporter81/specialsource-homepage-backend.git
synced 2026-12-06 07:41:09 +09:00
test : 주크박스 파일 받기 경로 탈출(../, 절대 경로)·RAR 아닌 파일 거절 확인
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f8bf46db24
commit
659644d7e8
1 file changed
+31
@@ -0,0 +1,31 @@
|
||||
package company.specialsource.controller;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/** 주크박스 파일 받기: 음악 폴더 밖이나 RAR이 아닌 파일은 절대 내주지 않음 */
|
||||
class JukeboxControllerTest {
|
||||
|
||||
@Test
|
||||
void 음악_폴더_밖은_거절(@TempDir Path root) throws Exception {
|
||||
Path music = Files.createDirectories(root.resolve("music"));
|
||||
Files.createDirectories(music.resolve("sub"));
|
||||
Files.writeString(music.resolve("sub/ok.rar"), "rar");
|
||||
Files.writeString(music.resolve("note.txt"), "txt");
|
||||
Files.writeString(root.resolve("secret.rar"), "secret"); // 음악 폴더 바깥
|
||||
JukeboxController c = new JukeboxController(music.toString());
|
||||
|
||||
assertThat(c.file("sub/ok.rar").getStatusCode().value()).isEqualTo(200);
|
||||
assertThat(c.file("../secret.rar").getStatusCode().value()).isEqualTo(404);
|
||||
assertThat(c.file("sub/../../secret.rar").getStatusCode().value()).isEqualTo(404);
|
||||
assertThat(c.file(root.resolve("secret.rar").toString()).getStatusCode().value()).isEqualTo(404); // 절대 경로
|
||||
assertThat(c.file("note.txt").getStatusCode().value()).isEqualTo(404); // RAR 아님
|
||||
assertThat(c.file("sub").getStatusCode().value()).isEqualTo(404); // 폴더
|
||||
assertThat(c.file("없는파일.rar").getStatusCode().value()).isEqualTo(404);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user