-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: redirect to original image if thumbnail is inaccessible (#6556
) #### What type of PR is this? /kind improvement /area core /milestone 2.19.x #### What this PR does / why we need it: 获取缩略图时检查缩略图链接是否可访问否则重定向到原图链接 #### Does this PR introduce a user-facing change? ```release-note 获取缩略图时检查缩略图链接是否可访问否则重定向到原图链接 ```
- Loading branch information
Showing
3 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
application/src/test/java/run/halo/app/theme/endpoint/ThumbnailEndpointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package run.halo.app.theme.endpoint; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.net.URI; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
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; | ||
|
||
/** | ||
* Tests for {@link ThumbnailEndpoint}. | ||
* | ||
* @author guqing | ||
* @since 2.19.0 | ||
*/ | ||
@ExtendWith(MockitoExtension.class) | ||
class ThumbnailEndpointTest { | ||
|
||
WebTestClient webClient; | ||
|
||
@Mock | ||
private ThumbnailService thumbnailService; | ||
|
||
@InjectMocks | ||
private ThumbnailEndpoint endpoint; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
webClient = WebTestClient.bindToRouterFunction(endpoint.endpoint()) | ||
.build(); | ||
} | ||
|
||
@Test | ||
void thumbnailUriNotAccessible() { | ||
when(thumbnailService.generate(any(), any())) | ||
.thenReturn(Mono.just(URI.create("/thumbnail-not-found.png"))); | ||
webClient.get() | ||
.uri("/thumbnails/-/via-uri?size=l&uri=/myavatar.png") | ||
.exchange() | ||
.expectAll(responseSpec -> responseSpec.expectHeader().location("/myavatar.png")) | ||
.expectStatus() | ||
.is3xxRedirection(); | ||
} | ||
} |