mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 08:36:11 +02:00
feat: enhance message decryption for IRC clients and improve attachment handling
This commit is contained in:
@@ -89,6 +89,27 @@ public class IrcBroadcasterTests
|
||||
Assert.DoesNotContain(output, l => l.Contains("$ENC$"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SendMessage_DecryptsAttachmentAsciiPreview()
|
||||
{
|
||||
var (_, stream) = AddConnectionWithCapture("bob", "general");
|
||||
|
||||
var attachment = new AttachmentDto(
|
||||
AttachmentKind.Image, "/api/files/abc", "photo.png", 1234,
|
||||
_encryption.Encrypt("line1\nline2"));
|
||||
var message = new MessageDto(
|
||||
Guid.NewGuid(), _encryption.Encrypt("look at this"), "alice", null, "general",
|
||||
DateTimeOffset.UtcNow, [attachment]);
|
||||
|
||||
await _broadcaster.SendMessageToChannelAsync("general", message);
|
||||
|
||||
var output = stream.GetOutputLines();
|
||||
Assert.Contains(output, l => l.Contains("[Image: photo.png]"));
|
||||
Assert.Contains(output, l => l.Contains("line1"));
|
||||
Assert.Contains(output, l => l.Contains("line2"));
|
||||
Assert.DoesNotContain(output, l => l.Contains("$ENC$"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SendMessage_SkipsSender()
|
||||
{
|
||||
|
||||
@@ -138,6 +138,19 @@ public class IrcMessageFormatterTests
|
||||
Assert.Equal(2, asciiLines.Count);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("$ENC$v1$abc123$def456")] // transport ciphertext a broadcast path forgot to decrypt
|
||||
[InlineData("$RC1$abc123def456")] // E2E room ciphertext the server cannot decrypt
|
||||
public void FormatMessage_ImageMessage_SkipsCiphertextPreview(string ciphertextPreview)
|
||||
{
|
||||
var msg = CreateImageMessage(ciphertextPreview, "photo.jpg", "https://example.com/photo.jpg");
|
||||
var lines = IrcMessageFormatter.FormatMessage(msg);
|
||||
|
||||
// Only the [Image: ...] header line — never the ciphertext blob
|
||||
Assert.Single(lines);
|
||||
Assert.Contains("[Image: photo.jpg]", lines[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FormatMessage_FileMessage_FormatsCorrectly()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user