mirror of https://github.com/halo-dev/halo
Refactor logging configuration and enhance URI handling in attachment upload process
parent
b6ab744d15
commit
0fc9b3bbc2
|
@ -317,7 +317,6 @@ class LocalAttachmentUploadHandler implements AttachmentHandler {
|
|||
return Optional.empty();
|
||||
}
|
||||
var uriStr = annotations.get(Constant.URI_ANNO_KEY);
|
||||
// the uriStr is encoded before.
|
||||
var uri = UriComponentsBuilder.fromUri(externalUrl.get())
|
||||
// The URI has been encoded before, so there is no need to encode it again.
|
||||
.path(uriStr)
|
||||
|
|
|
@ -7,6 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Clock;
|
||||
|
@ -34,6 +35,7 @@ import run.halo.app.core.extension.attachment.Attachment;
|
|||
import run.halo.app.core.extension.attachment.Policy;
|
||||
import run.halo.app.core.extension.attachment.endpoint.UploadOption;
|
||||
import run.halo.app.extension.ConfigMap;
|
||||
import run.halo.app.infra.ExternalUrlSupplier;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class LocalAttachmentUploadHandlerTest {
|
||||
|
@ -44,6 +46,9 @@ class LocalAttachmentUploadHandlerTest {
|
|||
@Mock
|
||||
AttachmentRootGetter attachmentRootGetter;
|
||||
|
||||
@Mock
|
||||
ExternalUrlSupplier externalUrlSupplier;
|
||||
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
|
@ -52,6 +57,7 @@ class LocalAttachmentUploadHandlerTest {
|
|||
@BeforeEach
|
||||
void setUp() {
|
||||
uploadHandler.setClock(clock);
|
||||
when(externalUrlSupplier.get()).thenReturn(URI.create("/"));
|
||||
}
|
||||
|
||||
public static Stream<Arguments> testUploadWithRenameStrategy() {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package run.halo.app.core.endpoint.theme;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.net.URI;
|
||||
|
@ -13,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
|||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import reactor.core.publisher.Mono;
|
||||
import run.halo.app.core.attachment.ThumbnailService;
|
||||
import run.halo.app.core.attachment.ThumbnailSize;
|
||||
|
||||
/**
|
||||
* Tests for {@link ThumbnailEndpoint}.
|
||||
|
@ -39,13 +39,12 @@ class ThumbnailEndpointTest {
|
|||
|
||||
@Test
|
||||
void thumbnailUriNotAccessible() {
|
||||
when(thumbnailService.get(any(), any()))
|
||||
.thenReturn(Mono.just(URI.create("/thumbnail-not-found.png")));
|
||||
when(thumbnailService.get(URI.create("/myavatar.png"), ThumbnailSize.L))
|
||||
.thenReturn(Mono.empty());
|
||||
webClient.get()
|
||||
.uri("/thumbnails/-/via-uri?size=l&uri=/myavatar.png")
|
||||
.exchange()
|
||||
.expectAll(responseSpec -> responseSpec.expectHeader().location("/myavatar.png"))
|
||||
.expectStatus()
|
||||
.is3xxRedirection();
|
||||
.expectHeader().location("/myavatar.png")
|
||||
.expectStatus().is3xxRedirection();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package run.halo.app.theme.finders.impl;
|
|||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
|
Loading…
Reference in New Issue