Apply all pending fixes: JWT auth config, image scaling, dashboard cover, script removal, logging improvements
This commit is contained in:
@@ -267,6 +267,74 @@ public class EpubReaderServiceTests : IDisposable
|
||||
colonResult.Errors.First().Message.Should().Contain("Invalid resource path");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RewriteImageUrls_PreservesImgPrefix()
|
||||
{
|
||||
// Arrange
|
||||
var method = typeof(EpubReaderService).GetMethod("RewriteImageUrls", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
|
||||
method.Should().NotBeNull();
|
||||
|
||||
var input = "<img class=\"epub_cover_page_img\" src=\"cover.jpg\" />";
|
||||
var ebookId = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
var result = (string)method.Invoke(null, new object[] { input, ebookId, "OEBPS/cover-page.xhtml" });
|
||||
|
||||
// Assert
|
||||
result.Should().StartWith("<img class=\"epub_cover_page_img\" src=\"/api/epub/");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RewriteImageUrls_NormalizesSvgImageTags()
|
||||
{
|
||||
// Arrange
|
||||
var method = typeof(EpubReaderService).GetMethod("RewriteImageUrls", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
|
||||
method.Should().NotBeNull();
|
||||
|
||||
var inputXlink = "<image xlink:href=\"images/fig1.jpg\" width=\"100%\" />";
|
||||
var inputHref = "<image href=\"images/fig2.jpg\" />";
|
||||
var ebookId = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
var resultXlink = (string)method.Invoke(null, new object[] { inputXlink, ebookId, "OEBPS/chapter1.xhtml" });
|
||||
var resultHref = (string)method.Invoke(null, new object[] { inputHref, ebookId, "OEBPS/chapter1.xhtml" });
|
||||
|
||||
// Assert
|
||||
resultXlink.Should().Contain("<img src=\"/api/epub/");
|
||||
resultXlink.Should().Contain("width=\"100%\"");
|
||||
resultXlink.Should().NotContain("<image");
|
||||
resultXlink.Should().NotContain("xlink:href");
|
||||
|
||||
resultHref.Should().Contain("<img src=\"/api/epub/");
|
||||
resultHref.Should().NotContain("<image");
|
||||
resultHref.Should().NotContain("href=");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("<p><br /></p>")]
|
||||
[InlineData("<p> </p>")]
|
||||
[InlineData("<p> <br> </p>")]
|
||||
[InlineData("<br>")]
|
||||
[InlineData(" ")]
|
||||
public void EmptyBlockRegex_MatchesEmptyBlocks(string input)
|
||||
{
|
||||
// Arrange
|
||||
var field = typeof(EpubReaderService).GetField("EmptyBlockRegex", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
|
||||
field.Should().NotBeNull();
|
||||
var regex = (System.Text.RegularExpressions.Regex)field.GetValue(null);
|
||||
regex.Should().NotBeNull();
|
||||
|
||||
var method = typeof(EpubReaderService).GetMethod("SanitizeParagraph", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
|
||||
method.Should().NotBeNull();
|
||||
|
||||
// Act
|
||||
var sanitized = (string)method.Invoke(null, new object[] { input });
|
||||
var isMatch = regex.IsMatch(sanitized);
|
||||
|
||||
// Assert
|
||||
isMatch.Should().BeTrue();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_connection.Close();
|
||||
|
||||
Reference in New Issue
Block a user