mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 08:01:10 +00:00
Removes the option to disable theme scripts
This commit is contained in:
1 parent
531450b3db
commit
15945c2e56
17 files changed
+15
-201
No files matched your search
-3
@@ -37,10 +37,8 @@ public class GetThemeSettingsQueryHandlerTests
|
||||
// Arrange
|
||||
GetThemeSettingsQuery query = _getThemeSettingsQueryFixture.Create();
|
||||
long maxArchiveBytes = 50_000_000;
|
||||
bool allowThemeScripts = false;
|
||||
string defaultThemeId = "default-theme";
|
||||
_mockThemeService.MaxArchiveBytes.Returns(maxArchiveBytes);
|
||||
_mockThemeService.AllowThemeScripts.Returns(allowThemeScripts);
|
||||
_mockThemeService.DefaultThemeId.Returns(defaultThemeId);
|
||||
|
||||
// Act
|
||||
@@ -49,7 +47,6 @@ public class GetThemeSettingsQueryHandlerTests
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(maxArchiveBytes, result.Value.MaxArchiveBytes);
|
||||
Assert.Equal(allowThemeScripts, result.Value.AllowThemeScripts);
|
||||
Assert.Equal(defaultThemeId, result.Value.DefaultThemeId);
|
||||
}
|
||||
}
|
||||
@@ -51,8 +51,7 @@ public class ThemeServiceTests : IDisposable
|
||||
maxArchiveBytes: 8 * 1024 * 1024,
|
||||
maxExpandedBytes: 24 * 1024 * 1024,
|
||||
maxSingleFileBytes: 6 * 1024 * 1024,
|
||||
maxEntries: 250,
|
||||
allowThemeScripts: false);
|
||||
maxEntries: 250);
|
||||
_sut = CreateSut(_options);
|
||||
}
|
||||
|
||||
@@ -76,52 +75,6 @@ public class ThemeServiceTests : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AllowThemeScripts_WhenConfiguredFalse_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
ThemeEngineOptionsDto options = _themeEngineOptionsDtoFixture.Create(
|
||||
storagePath: Path.Combine(_testRootPath, "themes"),
|
||||
bundledThemesPath: Path.Combine(_testRootPath, "bundled"),
|
||||
defaultThemeId: "lumina-default",
|
||||
maxArchiveBytes: 8 * 1024 * 1024,
|
||||
maxExpandedBytes: 24 * 1024 * 1024,
|
||||
maxSingleFileBytes: 6 * 1024 * 1024,
|
||||
maxEntries: 250,
|
||||
allowThemeScripts: false);
|
||||
options.AllowThemeScripts = false;
|
||||
ThemeService sut = CreateSut(options);
|
||||
|
||||
// Act
|
||||
bool result = sut.AllowThemeScripts;
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AllowThemeScripts_WhenConfiguredTrue_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
ThemeEngineOptionsDto options = _themeEngineOptionsDtoFixture.Create(
|
||||
storagePath: Path.Combine(_testRootPath, "themes"),
|
||||
bundledThemesPath: Path.Combine(_testRootPath, "bundled"),
|
||||
defaultThemeId: "lumina-default",
|
||||
maxArchiveBytes: 8 * 1024 * 1024,
|
||||
maxExpandedBytes: 24 * 1024 * 1024,
|
||||
maxSingleFileBytes: 6 * 1024 * 1024,
|
||||
maxEntries: 250,
|
||||
allowThemeScripts: false);
|
||||
options.AllowThemeScripts = true;
|
||||
ThemeService sut = CreateSut(options);
|
||||
|
||||
// Act
|
||||
bool result = sut.AllowThemeScripts;
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MaxArchiveBytes_WhenConfigured_ShouldReturnConfiguredValue()
|
||||
{
|
||||
@@ -133,8 +86,7 @@ public class ThemeServiceTests : IDisposable
|
||||
maxArchiveBytes: 8 * 1024 * 1024,
|
||||
maxExpandedBytes: 24 * 1024 * 1024,
|
||||
maxSingleFileBytes: 6 * 1024 * 1024,
|
||||
maxEntries: 250,
|
||||
allowThemeScripts: false);
|
||||
maxEntries: 250);
|
||||
options.MaxArchiveBytes = 12345;
|
||||
ThemeService sut = CreateSut(options);
|
||||
|
||||
@@ -156,8 +108,7 @@ public class ThemeServiceTests : IDisposable
|
||||
maxArchiveBytes: 8 * 1024 * 1024,
|
||||
maxExpandedBytes: 24 * 1024 * 1024,
|
||||
maxSingleFileBytes: 6 * 1024 * 1024,
|
||||
maxEntries: 250,
|
||||
allowThemeScripts: false);
|
||||
maxEntries: 250);
|
||||
options.DefaultThemeId = "custom-default";
|
||||
ThemeService sut = CreateSut(options);
|
||||
|
||||
@@ -288,8 +239,7 @@ public class ThemeServiceTests : IDisposable
|
||||
maxArchiveBytes: 8 * 1024 * 1024,
|
||||
maxExpandedBytes: 24 * 1024 * 1024,
|
||||
maxSingleFileBytes: 6 * 1024 * 1024,
|
||||
maxEntries: 250,
|
||||
allowThemeScripts: false);
|
||||
maxEntries: 250);
|
||||
options.MaxArchiveBytes = 128;
|
||||
ThemeService sut = CreateSut(options);
|
||||
byte[] archive = _themePackFixture.Create();
|
||||
@@ -453,8 +403,7 @@ public class ThemeServiceTests : IDisposable
|
||||
maxArchiveBytes: 8 * 1024 * 1024,
|
||||
maxExpandedBytes: 24 * 1024 * 1024,
|
||||
maxSingleFileBytes: 6 * 1024 * 1024,
|
||||
maxEntries: 250,
|
||||
allowThemeScripts: false);
|
||||
maxEntries: 250);
|
||||
options.MaxEntries = 2;
|
||||
ThemeService sut = CreateSut(options);
|
||||
byte[] archive = _themePackFixture.Create();
|
||||
@@ -478,8 +427,7 @@ public class ThemeServiceTests : IDisposable
|
||||
maxArchiveBytes: 8 * 1024 * 1024,
|
||||
maxExpandedBytes: 24 * 1024 * 1024,
|
||||
maxSingleFileBytes: 6 * 1024 * 1024,
|
||||
maxEntries: 250,
|
||||
allowThemeScripts: false);
|
||||
maxEntries: 250);
|
||||
options.MaxSingleFileBytes = 10;
|
||||
ThemeService sut = CreateSut(options);
|
||||
string manifestJson = _themePackFixture.CreateManifestJson();
|
||||
@@ -506,8 +454,7 @@ public class ThemeServiceTests : IDisposable
|
||||
maxArchiveBytes: 8 * 1024 * 1024,
|
||||
maxExpandedBytes: 24 * 1024 * 1024,
|
||||
maxSingleFileBytes: 6 * 1024 * 1024,
|
||||
maxEntries: 250,
|
||||
allowThemeScripts: false);
|
||||
maxEntries: 250);
|
||||
options.MaxSingleFileBytes = 400;
|
||||
options.MaxExpandedBytes = 300;
|
||||
ThemeService sut = CreateSut(options);
|
||||
@@ -1039,48 +986,6 @@ public class ThemeServiceTests : IDisposable
|
||||
Assert.Equal(DEFAULT_TEMPLATE, result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTemplateAsync_WhenScriptsAreDisabled_ShouldStripScriptElements()
|
||||
{
|
||||
// Arrange
|
||||
byte[] archive = _themePackFixture.Create(defaultTemplateContent: "<script>alert('xss')</script><p>safe content</p>");
|
||||
await InstallValidThemeAsync(archive);
|
||||
|
||||
// Act
|
||||
Result<string> result = await _sut.GetTemplateAsync("test-theme", "unknown-page", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.Equal("<p>safe content</p>", result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetTemplateAsync_WhenScriptsAreEnabled_ShouldPreserveScriptElements()
|
||||
{
|
||||
// Arrange
|
||||
ThemeEngineOptionsDto options = _themeEngineOptionsDtoFixture.Create(
|
||||
storagePath: Path.Combine(_testRootPath, "themes"),
|
||||
bundledThemesPath: Path.Combine(_testRootPath, "bundled"),
|
||||
defaultThemeId: "lumina-default",
|
||||
maxArchiveBytes: 8 * 1024 * 1024,
|
||||
maxExpandedBytes: 24 * 1024 * 1024,
|
||||
maxSingleFileBytes: 6 * 1024 * 1024,
|
||||
maxEntries: 250,
|
||||
allowThemeScripts: false);
|
||||
options.AllowThemeScripts = true;
|
||||
ThemeService sut = CreateSut(options);
|
||||
const string TEMPLATE_WITH_SCRIPT = "<script>alert('xss')</script><p>safe content</p>";
|
||||
byte[] archive = _themePackFixture.Create(defaultTemplateContent: TEMPLATE_WITH_SCRIPT);
|
||||
await InstallValidThemeAsync(archive, sut);
|
||||
|
||||
// Act
|
||||
Result<string> result = await sut.GetTemplateAsync("test-theme", "unknown-page", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.Equal(TEMPLATE_WITH_SCRIPT, result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAssetAsync_WhenAssetExists_ShouldReturnFileBytesAndContentType()
|
||||
{
|
||||
@@ -1146,7 +1051,7 @@ public class ThemeServiceTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAssetAsync_WhenScriptsAreDisabledAndAssetIsJavaScript_ShouldReturnThemeFilesUnreadable()
|
||||
public async Task GetAssetAsync_WhenAssetIsJavaScript_ShouldReturnJavaScriptContentType()
|
||||
{
|
||||
// Arrange
|
||||
byte[] archive = _themePackFixture.Create(additionalFiles: new Dictionary<string, string>
|
||||
@@ -1158,35 +1063,6 @@ public class ThemeServiceTests : IDisposable
|
||||
// Act
|
||||
Result<ThemeAssetDto> result = await _sut.GetAssetAsync("test-theme", "assets/app.js", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal("ThemeFilesUnreadable", result.FirstError.Description);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetAssetAsync_WhenScriptsAreEnabledAndAssetIsJavaScript_ShouldReturnJavaScriptContentType()
|
||||
{
|
||||
// Arrange
|
||||
ThemeEngineOptionsDto options = _themeEngineOptionsDtoFixture.Create(
|
||||
storagePath: Path.Combine(_testRootPath, "themes"),
|
||||
bundledThemesPath: Path.Combine(_testRootPath, "bundled"),
|
||||
defaultThemeId: "lumina-default",
|
||||
maxArchiveBytes: 8 * 1024 * 1024,
|
||||
maxExpandedBytes: 24 * 1024 * 1024,
|
||||
maxSingleFileBytes: 6 * 1024 * 1024,
|
||||
maxEntries: 250,
|
||||
allowThemeScripts: false);
|
||||
options.AllowThemeScripts = true;
|
||||
ThemeService sut = CreateSut(options);
|
||||
byte[] archive = _themePackFixture.Create(additionalFiles: new Dictionary<string, string>
|
||||
{
|
||||
["assets/app.js"] = "console.log('hello');"
|
||||
});
|
||||
await InstallValidThemeAsync(archive, sut);
|
||||
|
||||
// Act
|
||||
Result<ThemeAssetDto> result = await sut.GetAssetAsync("test-theme", "assets/app.js", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsSuccess);
|
||||
Assert.Equal("application/javascript", result.Value.ContentType);
|
||||
|
||||
+1
-2
@@ -53,7 +53,7 @@ public class GetThemesEndpointTests
|
||||
_mockApiHttpClient.GetAsync<ThemeResponseDto>(ApiRoutes.Themes.GET_CURRENT_THEME, Arg.Any<CancellationToken>())
|
||||
.Returns(currentTheme);
|
||||
_mockApiHttpClient.GetAsync<ThemeSettingsResponseDto>(ApiRoutes.Themes.GET_THEME_SETTINGS, Arg.Any<CancellationToken>())
|
||||
.Returns(_themeSettingsResponseDtoFixture.Create(maxArchiveBytes: 10 * 1024 * 1024, allowThemeScripts: true));
|
||||
.Returns(_themeSettingsResponseDtoFixture.Create(maxArchiveBytes: 10 * 1024 * 1024));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, CancellationToken.None);
|
||||
@@ -67,7 +67,6 @@ public class GetThemesEndpointTests
|
||||
Assert.Equal(2, data.GetProperty("themes").GetArrayLength());
|
||||
Assert.Equal("editorial-paper", data.GetProperty("themes")[0].GetProperty("id").GetString());
|
||||
Assert.Equal("lumina-default", data.GetProperty("currentThemeId").GetString());
|
||||
Assert.True(data.GetProperty("allowThemeScripts").GetBoolean());
|
||||
Assert.Equal(10 * 1024 * 1024, data.GetProperty("maxArchiveBytes").GetInt64());
|
||||
Assert.Equal(10.0, data.GetProperty("maxArchiveMegabytes").GetDouble());
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public class ThemeServiceTests
|
||||
public async Task GetThemeSettingsAsync_WhenApiReturnsSettings_ShouldReturnSettings()
|
||||
{
|
||||
// Arrange
|
||||
ThemeSettingsResponseDto settings = _themeSettingsResponseDtoFixture.Create(maxArchiveBytes: 10 * 1024 * 1024, allowThemeScripts: true);
|
||||
ThemeSettingsResponseDto settings = _themeSettingsResponseDtoFixture.Create(maxArchiveBytes: 10 * 1024 * 1024);
|
||||
_mockApiHttpClient.GetAsync<ThemeSettingsResponseDto>(ApiRoutes.Themes.GET_THEME_SETTINGS, Arg.Any<CancellationToken>())
|
||||
.Returns(settings);
|
||||
|
||||
|
||||
Reference in new issue
Block a user