Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add attachment upload test scaffolding (#287)
Leendert de Borst827f677af895
diff --git a/src/Tests/AliasVault.E2ETests/AliasVault.E2ETests.csproj b/src/Tests/AliasVault.E2ETests/AliasVault.E2ETests.csprojindex e5b9f6ae6..d98b671d2 100644--- a/src/Tests/AliasVault.E2ETests/AliasVault.E2ETests.csproj+++ b/src/Tests/AliasVault.E2ETests/AliasVault.E2ETests.csproj@@ -23,6 +23,7 @@<ItemGroup><AdditionalFiles Include="..\..\stylecop.json" Link="stylecop.json" /><EmbeddedResource Include="TestData\AliasClientDb_encrypted_base64_1.0.0.txt" />+ <EmbeddedResource Include="TestData\TestAttachment.txt" /></ItemGroup><ItemGroup>diff --git a/src/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs b/src/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.csindex 72703b63a..c6e50dcb5 100644--- a/src/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs+++ b/src/Tests/AliasVault.E2ETests/Common/ClientPlaywrightTest.cs@@ -175,8 +175,9 @@ public class ClientPlaywrightTest : PlaywrightTest/// Create new credential entry./// </summary>/// <param name="formValues">Dictionary with html element ids and values to input as field value.</param>+ /// <param name="customLogic">Optional custom logic to execute after filling input fields.</param>/// <returns>Async task.</returns>- protected async Task CreateCredentialEntry(Dictionary<string, string>? formValues = null)+ protected async Task CreateCredentialEntry(Dictionary<string, string>? formValues = null, Func<Task>? customLogic = null){// Advance the time by 1 second to ensure the credential is created with a unique timestamp.// This is required for certain tests that check for the latest credential and/or latest vault.@@ -193,6 +194,12 @@ public class ClientPlaywrightTest : PlaywrightTestawait InputHelper.FillInputFields(formValues);await InputHelper.FillEmptyInputFieldsWithRandom();+ // Execute custom logic if provided+ if (customLogic != null)+ {+ await customLogic();+ }+var submitButton = Page.Locator("text=Save Credentials").First;await submitButton.ClickAsync();await WaitForUrlAsync("credentials/**", "Credentials created successfully");diff --git a/src/Tests/AliasVault.E2ETests/Common/ResourceReaderUtility.cs b/src/Tests/AliasVault.E2ETests/Common/ResourceReaderUtility.csindex 56d3a268e..ef477aac0 100644--- a/src/Tests/AliasVault.E2ETests/Common/ResourceReaderUtility.cs+++ b/src/Tests/AliasVault.E2ETests/Common/ResourceReaderUtility.cs@@ -7,7 +7,9 @@namespace AliasVault.E2ETests.Common;+using System.IO;using System.Reflection;+using System.Threading.Tasks;/// <summary>/// Utility for reading strings from project embedded resources used in tests.@@ -20,7 +22,7 @@ public static class ResourceReaderUtility/// <param name="resourceName">Name of the embedded resource.</param>/// <returns>Contents of embedded resource as string.</returns>/// <exception cref="InvalidOperationException">Thrown when resource is not found with that name.</exception>- public static async Task<string> ReadEmbeddedResourceAsync(string resourceName)+ public static async Task<string> ReadEmbeddedResourceStringAsync(string resourceName){var assembly = Assembly.GetExecutingAssembly();@@ -34,6 +36,27 @@ public static class ResourceReaderUtilityreturn await reader.ReadToEndAsync();}+ /// <summary>+ /// Reads byte array from embedded resource.+ /// </summary>+ /// <param name="resourceName">Name of the embedded resource.</param>+ /// <returns>Contents of embedded resource as byte array.</returns>+ /// <exception cref="InvalidOperationException">Thrown when resource is not found with that name.</exception>+ public static async Task<byte[]> ReadEmbeddedResourceBytesAsync(string resourceName)+ {+ var assembly = Assembly.GetExecutingAssembly();++ using var stream = assembly.GetManifestResourceStream(resourceName);+ if (stream == null)+ {+ throw new InvalidOperationException($"Resource {resourceName} not found in {assembly.FullName}");+ }++ using var memoryStream = new MemoryStream();+ await stream.CopyToAsync(memoryStream);+ return memoryStream.ToArray();+ }+/// <summary>/// Get all embedded resource names in current assembly./// </summary>diff --git a/src/Tests/AliasVault.E2ETests/TestData/README.md b/src/Tests/AliasVault.E2ETests/TestData/README.mdindex 5dd809950..e8feb543b 100644--- a/src/Tests/AliasVault.E2ETests/TestData/README.md+++ b/src/Tests/AliasVault.E2ETests/TestData/README.md@@ -4,3 +4,4 @@ using the `ResourceReaderUtility` class.Index:- `AliasClientDb_encrypted_base64_1.0.0` - Encrypted vault blob with client db version 1.0.0 used to test client db upgrade paths. This vault contains two test credentials that are checked in the tests after local client db upgrade.+- `TestAttachment.txt` - Test attachment file that is uploaded during test.diff --git a/src/Tests/AliasVault.E2ETests/TestData/TestAttachment.txt b/src/Tests/AliasVault.E2ETests/TestData/TestAttachment.txtnew file mode 100644index 000000000..40081da24--- /dev/null+++ b/src/Tests/AliasVault.E2ETests/TestData/TestAttachment.txt@@ -0,0 +1 @@+Test attachment contentdiff --git a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbUpgradeTests.cs b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbUpgradeTests.csindex bf3920b1d..0b67517c7 100644--- a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbUpgradeTests.cs+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbUpgradeTests.cs@@ -53,7 +53,7 @@ public class DbUpgradeTests : ClientPlaywrightTestUpdatedAt = DateTime.UtcNow,EncryptionType = "Argon2Id",EncryptionSettings = "{\"DegreeOfParallelism\":4,\"MemorySize\":8192,\"Iterations\":1}",- VaultBlob = await ResourceReaderUtility.ReadEmbeddedResourceAsync("AliasVault.E2ETests.TestData.AliasClientDb_encrypted_base64_1.0.0.txt"),+ VaultBlob = await ResourceReaderUtility.ReadEmbeddedResourceStringAsync("AliasVault.E2ETests.TestData.AliasClientDb_encrypted_base64_1.0.0.txt"),Salt = "1a73a8ef3a1c6dd891674c415962d87246450f8ca5004ecca24be770a4d7b1f7",Verifier = "ab284d4e6da07a2bc95fb4b9dcd0e192988cc45f51e4c51605e42d4fc1055f8398e579755f4772a045abdbded8ae47ae861faa9ff7cb98155103d7038b9713b12d80dff9134067f02564230ab2f5a550ae293b8b7049516a7dc3f918156cde7190bee7e9c84398b2b5b63aeea763cd776b3e9708fb1f66884340451187ca8aacfced19ea28bc94ae28eefa720aae7a3185b139cf6349c2d43e8147f1edadd249c7e125ce15e775c45694d9796ee3f9b8c5beacd37e777a2ea1e745c781b5c085b7e3826f6abe303a14f539cd8d9519661a91cc4e7d44111b8bc9aac1cf1a51ad76658502b436da746844348dfcfb2581c4e4c340058c116a06f975f57a689df4",});diff --git a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard5/AttachmentTests.cs b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard5/AttachmentTests.csnew file mode 100644index 000000000..a7c2ddf7d--- /dev/null+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard5/AttachmentTests.cs@@ -0,0 +1,56 @@+//-----------------------------------------------------------------------+// <copyright file="AttachmentTests.cs" company="lanedirt">+// Copyright (c) lanedirt. All rights reserved.+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasVault.E2ETests.Tests.Client.Shard5;++/// <summary>+/// End-to-end tests for uploading and downloading attachments.+/// </summary>+[Parallelizable(ParallelScope.Self)]+[Category("ClientTests")]+[TestFixture]+public class AttachmentTests : ClientPlaywrightTest+{+ /// <summary>+ /// Test that adding an attachment works correctly and can be downloaded afterwards.+ /// </summary>+ /// <returns>Async task.</returns>+ [Test]+ public async Task UploadAttachment()+ {+ // Create a new alias with service name = "Test Service".+ var serviceName = "Test Service";+ await CreateCredentialEntry(+ new Dictionary<string, string>+ {+ { "service-name", serviceName },+ },+ async () =>+ {+ // Upload file.+ var fileInput = Page.Locator("input[type='file']");+ var fileContent = await ResourceReaderUtility.ReadEmbeddedResourceBytesAsync("AliasVault.E2ETests.TestData.TestAttachment.txt");++ // Create a temporary file with the content and original file name+ var originalFileName = "TestAttachment.txt";+ var tempFilePath = Path.Combine(Path.GetTempPath(), originalFileName);+ await File.WriteAllBytesAsync(tempFilePath, fileContent);++ // Set the file input using the temporary file+ await fileInput.SetInputFilesAsync(tempFilePath);++ await Task.Delay(5000); // Reduced delay for faster test execution++ // Delete the temporary file+ File.Delete(tempFilePath);+ });++ // Check that the service name is present in the content.+ var pageContent = await Page.TextContentAsync("body");+ Assert.That(pageContent, Does.Contain(serviceName), "Created credential service name does not appear on alias page.");+ }+}diff --git a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard5/AuthPasswordChangeTest.cs b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard5/AuthPasswordChangeTests.cssimilarity index 96%rename from src/Tests/AliasVault.E2ETests/Tests/Client/Shard5/AuthPasswordChangeTest.csrename to src/Tests/AliasVault.E2ETests/Tests/Client/Shard5/AuthPasswordChangeTests.csindex be2e207c0..353549fe4 100644--- a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard5/AuthPasswordChangeTest.cs+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard5/AuthPasswordChangeTests.cs@@ -1,5 +1,5 @@//------------------------------------------------------------------------// <copyright file="AuthPasswordChangeTest.cs" company="lanedirt">+// <copyright file="AuthPasswordChangeTests.cs" company="lanedirt">// Copyright (c) lanedirt. All rights reserved.// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.// </copyright>@@ -14,7 +14,7 @@ namespace AliasVault.E2ETests.Tests.Client.Shard5;[Category("ClientTests")][TestFixture]-public class AuthPasswordChangeTest : ClientPlaywrightTest+public class AuthPasswordChangeTests : ClientPlaywrightTest{/// <summary>/// Test if changing password works correctly.diff --git a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard5/UnlockTests.cs b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard5/UnlockTests.csindex dedad1ec7..549a3c0b7 100644--- a/src/Tests/AliasVault.E2ETests/Tests/Client/Shard5/UnlockTests.cs+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/Shard5/UnlockTests.cs@@ -5,7 +5,7 @@// </copyright>//------------------------------------------------------------------------namespace AliasVault.E2ETests.Tests.Client;+namespace AliasVault.E2ETests.Tests.Client.Shard5;/// <summary>/// End-to-end tests for the database unlock functionality.