Skip to content

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

Update tests (#2159)

Leendert de Borst86d814c1c03e
diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs
index 646e9e16c..de73b5056 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard1/EmailDecryptionTests.cs
@@ -69,8 +69,8 @@ public class EmailDecryptionTests : ClientPlaywrightTest
var claim = await ApiDbContext.EmailClaims.Where(x => x.Address == email).FirstOrDefaultAsync();
Assert.That(claim, Is.Not.Null, "Claim for email address not found in database. Check if item creation and claim creation are working correctly.");
- // Assert that the users public key was created on the server.
- var publicKey = await ApiDbContext.UserEncryptionKeys.Where(x => x.UserId == claim.UserId).FirstOrDefaultAsync();
+ // Assert that the public key of the manifest carrying the claim was created on the server.
+ var publicKey = await ApiDbContext.VaultManifestDeliveryKeys.Where(k => k.IsPrimary && ApiDbContext.EmailClaimLinks.Any(l => l.EmailClaimId == claim.Id && l.VaultManifestId == k.VaultManifestId)).FirstOrDefaultAsync();
Assert.That(publicKey, Is.Not.Null, "Public key for user not found in database. Check if public key creation is working correctly.");
Assert.That(publicKey.PublicKey, Has.Length.GreaterThanOrEqualTo(100), "Public key exists but length does not match expected. Check if public key creation is working correctly.");
@@ -166,8 +166,8 @@ public class EmailDecryptionTests : ClientPlaywrightTest
var claim = await ApiDbContext.EmailClaims.Where(x => x.Address == email).FirstOrDefaultAsync();
Assert.That(claim, Is.Not.Null, "Claim for email address not found in database. Check if item creation and claim creation are working correctly.");
- // Assert that the users public key was created on the server.
- var publicKey = await ApiDbContext.UserEncryptionKeys.Where(x => x.UserId == claim.UserId).FirstOrDefaultAsync();
+ // Assert that the public key of the manifest carrying the claim was created on the server.
+ var publicKey = await ApiDbContext.VaultManifestDeliveryKeys.Where(k => k.IsPrimary && ApiDbContext.EmailClaimLinks.Any(l => l.EmailClaimId == claim.Id && l.VaultManifestId == k.VaultManifestId)).FirstOrDefaultAsync();
Assert.That(publicKey, Is.Not.Null, "Public key for user not found in database. Check if public key creation is working correctly.");
Assert.That(publicKey!.PublicKey, Has.Length.GreaterThanOrEqualTo(100), "Public key exists but length does not match expected. Check if public key creation is working correctly.");
@@ -509,17 +509,6 @@ public class EmailDecryptionTests : ClientPlaywrightTest
await _testHostBuilder.DisposeAsync();
}
- /// <summary>
- /// Checks whether an alias is still carried by any vault. There is no disabled flag on the claim: a link that is
- /// not removed is what says the alias is live, and paused counts as live because the user still has the alias.
- /// </summary>
- /// <param name="emailClaimId">The email claim to check.</param>
- /// <returns>True while at least one manifest still carries the alias.</returns>
- private async Task<bool> IsClaimLiveAsync(Guid emailClaimId)
- {
- return await ApiDbContext.EmailClaimLinks.AsNoTracking().AnyAsync(l => l.EmailClaimId == emailClaimId && l.State != EmailClaimLinkState.Removed);
- }
-
/// <summary>
/// Sends a message to the SMTP server.
/// </summary>
@@ -538,4 +527,15 @@ public class EmailDecryptionTests : ClientPlaywrightTest
await client.DisconnectAsync(true);
}
}
+
+ /// <summary>
+ /// Checks whether an alias is still carried by any vault. There is no disabled flag on the claim: a link that is
+ /// not removed is what says the alias is live, and paused counts as live because the user still has the alias.
+ /// </summary>
+ /// <param name="emailClaimId">The email claim to check.</param>
+ /// <returns>True while at least one manifest still carries the alias.</returns>
+ private async Task<bool> IsClaimLiveAsync(Guid emailClaimId)
+ {
+ return await ApiDbContext.EmailClaimLinks.AsNoTracking().AnyAsync(l => l.EmailClaimId == emailClaimId && l.State != EmailClaimLinkState.Removed);
+ }
}
diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbUpgradeTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbUpgradeTests.cs
index 57640d22e..4fb09d9fd 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbUpgradeTests.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard2/DbUpgradeTests.cs
@@ -49,12 +49,11 @@ public class DbUpgradeTests : ClientPlaywrightTest
// Overwrite the user's current vault with the static 1.0.0 vault (the current row is updated in place;
// the VaultManifests table holds exactly one row per manifest).
- var currentVault = ApiDbContext.VaultManifests.First(x => x.OwnerUserId == user.Id);
+ var currentVault = ApiDbContext.VaultManifests.First(x => x.OwnerGroupId == user.PersonalGroupId);
currentVault.CopyPayloadFrom(
new VaultManifestsHistory
{
ManifestId = currentVault.ManifestId,
- OwnerUserId = user.Id,
StorageFormat = VaultManifestBase.LegacyStorageFormat,
Version = "1.0.0",
RevisionNumber = 2,
diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/ResetVaultTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/ResetVaultTests.cs
index 36648c805..a5622c156 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/ResetVaultTests.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Client/Shard5/ResetVaultTests.cs
@@ -74,7 +74,7 @@ public class ResetVaultTests : ClientPlaywrightTest
await WaitForUrlAsync("items", "successfully reset");
// Check API that the latest vault has no items.
- var latestVault = await ApiDbContext.VaultManifests.Where(x => x.User.UserName == TestUserUsername).OrderByDescending(x => x.CreatedAt).FirstAsync();
+ var latestVault = await ApiDbContext.VaultManifests.Where(x => ApiDbContext.AliasVaultUsers.Any(u => u.UserName == TestUserUsername && u.PersonalGroupId == x.OwnerGroupId)).OrderByDescending(x => x.CreatedAt).FirstAsync();
Assert.That(latestVault.CredentialsCount, Is.EqualTo(0), "Latest vault should have no items after reset.");
// Create a new item entry.
@@ -87,7 +87,7 @@ public class ResetVaultTests : ClientPlaywrightTest
});
// Check that the now latest vault has one item, and only one active claimed alias.
- latestVault = await ApiDbContext.VaultManifests.Where(x => x.User.UserName == TestUserUsername).OrderByDescending(x => x.CreatedAt).FirstAsync();
+ latestVault = await ApiDbContext.VaultManifests.Where(x => ApiDbContext.AliasVaultUsers.Any(u => u.UserName == TestUserUsername && u.PersonalGroupId == x.OwnerGroupId)).OrderByDescending(x => x.CreatedAt).FirstAsync();
Assert.Multiple(() =>
{
Assert.That(latestVault.CredentialsCount, Is.EqualTo(1), "Latest vault should have one item after reset.");
diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/TestVaultGeneratorTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/TestVaultGeneratorTests.cs
index 34e06f737..eeb0c137e 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/TestVaultGeneratorTests.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/TestVaultGeneratorTests.cs
@@ -122,17 +122,14 @@ public class TestVaultGeneratorTests : BrowserExtensionPlaywrightTest
}
// Get the user's vault from the database
- var user = await ApiDbContext.AliasVaultUsers
- .Include(u => u.VaultManifests)
- .FirstOrDefaultAsync(u => u.UserName == TestUserUsername);
+ var user = await ApiDbContext.AliasVaultUsers.FirstOrDefaultAsync(u => u.UserName == TestUserUsername);
+ var vault = user == null ? null : await ApiDbContext.VaultManifests.FirstOrDefaultAsync(x => x.OwnerGroupId == user.PersonalGroupId);
- if (user == null || !user.VaultManifests.Any())
+ if (vault == null)
{
throw new Exception("Could not find user or vault in database");
}
- var vault = user.VaultManifests.OrderByDescending(x => x.RevisionNumber).First();
-
var outputDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty;
var vaultOutputDir = Path.Combine(outputDir, "output");
diff --git a/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/VaultUpgradeTests.cs b/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/VaultUpgradeTests.cs
index e77807c09..1b52bc8f3 100644
--- a/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/VaultUpgradeTests.cs
+++ b/apps/server/Tests/AliasVault.E2ETests/Tests/Extensions/VaultUpgradeTests.cs
@@ -52,12 +52,11 @@ public class VaultUpgradeTests : BrowserExtensionPlaywrightTest
// Overwrite the user's current vault with the static 1.0.0 vault (the current row is updated in place;
// the VaultManifests table holds exactly one row per manifest).
- var currentVault = ApiDbContext.VaultManifests.First(x => x.OwnerUserId == user.Id);
+ var currentVault = ApiDbContext.VaultManifests.First(x => x.OwnerGroupId == user.PersonalGroupId);
currentVault.CopyPayloadFrom(
new VaultManifestsHistory
{
ManifestId = currentVault.ManifestId,
- OwnerUserId = user.Id,
StorageFormat = VaultManifestBase.LegacyStorageFormat,
Version = "1.0.0",
RevisionNumber = 2,