feat: enhance message decryption for IRC clients and improve attachment handling

This commit is contained in:
HueByte
2026-07-16 16:35:34 +02:00
parent aae788028e
commit b62729dc95
6 changed files with 63 additions and 4 deletions
@@ -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()
{