forked from wangziqi/ruoyi-vue-pro
feat(education): admit secure import assets
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package cn.iocoder.yudao.module.infra.api.file;
|
||||
|
||||
import cn.iocoder.yudao.module.infra.service.file.FileService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class FileApiImplTest {
|
||||
|
||||
@Test
|
||||
void storesBoundedContentAsPublicDescriptor() {
|
||||
FileService fileService = mock(FileService.class);
|
||||
when(fileService.createFile(new byte[]{1, 2, 3}, "questions.csv", "education/imports", "text/csv"))
|
||||
.thenReturn("https://storage.example/internal/object");
|
||||
FileApiImpl api = new FileApiImpl(fileService);
|
||||
|
||||
FileDescriptor descriptor = api.createFile(new FileContent(
|
||||
new byte[]{1, 2, 3}, "questions.csv", "education/imports", "text/csv"));
|
||||
|
||||
assertEquals("https://storage.example/internal/object", descriptor.reference());
|
||||
assertEquals("questions.csv", descriptor.name());
|
||||
assertEquals("text/csv", descriptor.contentType());
|
||||
assertEquals(3, descriptor.size());
|
||||
verify(fileService).createFile(new byte[]{1, 2, 3}, "questions.csv", "education/imports", "text/csv");
|
||||
}
|
||||
|
||||
@Test
|
||||
void scannerUnavailableNeverReportsClean() {
|
||||
FileApiImpl api = new FileApiImpl(mock(FileService.class));
|
||||
|
||||
assertEquals(FileScanStatus.UNAVAILABLE,
|
||||
api.scan(new FileDescriptor("opaque", "questions.csv", "text/csv", 3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsContentOutsidePublicContractBound() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new FileContent(new byte[FileContent.MAX_CONTENT_BYTES + 1], "large.csv", null, "text/csv"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user