Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into perf/improve-social-login
- Loading branch information
Showing
11 changed files
with
140 additions
and
31 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
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
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
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
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
57 changes: 57 additions & 0 deletions
57
application/src/test/java/run/halo/app/theme/ThemeConfigurationTest.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,57 @@ | ||
package run.halo.app.theme; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
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 run.halo.app.infra.ThemeRootGetter; | ||
import run.halo.app.infra.exception.AccessDeniedException; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ThemeConfigurationTest { | ||
@Mock | ||
private ThemeRootGetter themeRootGetter; | ||
|
||
@InjectMocks | ||
private ThemeConfiguration themeConfiguration; | ||
|
||
private final Path themeRoot = Paths.get("/tmp/.halo/themes"); | ||
|
||
@BeforeEach | ||
void setUp() { | ||
when(themeRootGetter.get()).thenReturn(themeRoot); | ||
} | ||
|
||
@Test | ||
void themeAssets() { | ||
Path path = themeConfiguration.getThemeAssetsPath("fake-theme", "hello.jpg"); | ||
assertThat(path).isEqualTo(themeRoot.resolve("fake-theme/templates/assets/hello.jpg")); | ||
|
||
path = themeConfiguration.getThemeAssetsPath("fake-theme", "./hello.jpg"); | ||
assertThat(path).isEqualTo(themeRoot.resolve("fake-theme/templates/assets/./hello.jpg")); | ||
|
||
assertThatThrownBy(() -> { | ||
themeConfiguration.getThemeAssetsPath("fake-theme", "../../hello.jpg"); | ||
}).isInstanceOf(AccessDeniedException.class) | ||
.hasMessage( | ||
"403 FORBIDDEN \"Directory traversal detected: /tmp/" | ||
+ ".halo/themes/fake-theme/templates/assets/../../hello.jpg\""); | ||
|
||
path = themeConfiguration.getThemeAssetsPath("fake-theme", "%2e%2e/f.jpg"); | ||
assertThat(path).isEqualTo(themeRoot.resolve("fake-theme/templates/assets/%2e%2e/f.jpg")); | ||
|
||
path = themeConfiguration.getThemeAssetsPath("fake-theme", "f/./../p.jpg"); | ||
assertThat(path).isEqualTo(themeRoot.resolve("fake-theme/templates/assets/f/./../p.jpg")); | ||
|
||
path = themeConfiguration.getThemeAssetsPath("fake-theme", "f../p.jpg"); | ||
assertThat(path).isEqualTo(themeRoot.resolve("fake-theme/templates/assets/f../p.jpg")); | ||
} | ||
} |
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