Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Refactor (#151)

Leendert de Borstdee2044ed642
diff --git a/src/AliasVault.Client/Main/Components/Email/EmailModal.razor b/src/AliasVault.Client/Main/Components/Email/EmailModal.razor
index dbe05e0f6..581698ef2 100644
--- a/src/AliasVault.Client/Main/Components/Email/EmailModal.razor
+++ b/src/AliasVault.Client/Main/Components/Email/EmailModal.razor
@@ -258,7 +258,10 @@
var decryptedBytes = await EmailService.DecryptEmailAttachment(Email, bytes);
// Offer the decrypted attachment as download to the user's browser.
- await JsInteropService.DownloadFileFromStream(attachment.Filename, decryptedBytes);
+ if (decryptedBytes != null)
+ {
+ await JsInteropService.DownloadFileFromStream(attachment.Filename, decryptedBytes);
+ }
}
else
{
diff --git a/src/AliasVault.Client/Services/EmailService.cs b/src/AliasVault.Client/Services/EmailService.cs
index cda086fb6..a88bc03b3 100644
--- a/src/AliasVault.Client/Services/EmailService.cs
+++ b/src/AliasVault.Client/Services/EmailService.cs
@@ -67,7 +67,7 @@ public sealed class EmailService(DbService dbService, JsInteropService jsInterop
/// <param name="email">The email containing the encryption information.</param>
/// <param name="encryptedBytes">The encrypted attachment bytes.</param>
/// <returns>Decrypted attachment bytes.</returns>
- public async Task<byte[]> DecryptEmailAttachment(EmailApiModel email, byte[] encryptedBytes)
+ public async Task<byte[]?> DecryptEmailAttachment(EmailApiModel email, byte[] encryptedBytes)
{
await EnsureEncryptionKeys();
var privateKey = _encryptionKeys.First(x => x.PublicKey == email.EncryptionKey);
@@ -82,7 +82,7 @@ public sealed class EmailService(DbService dbService, JsInteropService jsInterop
{
globalNotificationService.AddErrorMessage(ex.Message, true);
logger.LogError(ex, "Error decrypting email attachment.");
- throw;
+ return null;
}
}
diff --git a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs
index 1ece18987..9f58605c2 100644
--- a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs
+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs
@@ -208,11 +208,14 @@ public class EmailDecryptionTests : ClientPlaywrightTest
// Assert that the attachment content is encrypted
var attachmentContent = Encoding.UTF8.GetString(attachmentReceived!.Bytes);
- Assert.That(attachmentContent, Does.Not.Contain("This is an attachment."), "Attachment content stored as plain text in database. Check attachment encryption logic.");
- Assert.That(attachmentContent, Is.Not.Empty, "Attachment content is empty. Check attachment encryption logic.");
+ Assert.Multiple(() =>
+ {
+ Assert.That(attachmentContent, Does.Not.Contain("This is an attachment."), "Attachment content stored as plain text in database. Check attachment encryption logic.");
+ Assert.That(attachmentContent, Is.Not.Empty, "Attachment content is empty. Check attachment encryption logic.");
+ });
// Assert that subject is not stored as plain text in the database.
- Assert.That(emailReceived.Subject, Does.Not.Contain(textSubject), "Email subject stored as plain text in database. Check email encryption logic.");
+ Assert.That(emailReceived!.Subject, Does.Not.Contain(textSubject), "Email subject stored as plain text in database. Check email encryption logic.");
// Attempt to click on email refresh button to get new emails.
await Page.Locator("id=recent-email-refresh").First.ClickAsync();