Skip to content

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

Update E2E test config (#80)

Leendert de Borstc131372e37a3
diff --git a/src/AliasVault.Admin/Program.cs b/src/AliasVault.Admin/Program.cs
index 29ddd623b..1f89236f0 100644
--- a/src/AliasVault.Admin/Program.cs
+++ b/src/AliasVault.Admin/Program.cs
@@ -77,7 +77,7 @@ builder.Services.AddIdentityCore<AdminUser>(options =>
options.SignIn.RequireConfirmedAccount = false;
options.User.RequireUniqueEmail = false;
options.Lockout.MaxFailedAccessAttempts = 10;
- options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(15);
+ options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
})
.AddRoles<AdminRole>()
.AddEntityFrameworkStores<AliasServerDbContext>()
diff --git a/src/AliasVault.Api/Program.cs b/src/AliasVault.Api/Program.cs
index 6e298effc..db22e9692 100644
--- a/src/AliasVault.Api/Program.cs
+++ b/src/AliasVault.Api/Program.cs
@@ -53,7 +53,7 @@ builder.Services.AddIdentity<AliasVaultUser, AliasVaultRole>(options =>
options.Password.RequiredUniqueChars = 0;
options.SignIn.RequireConfirmedAccount = false;
options.Lockout.MaxFailedAccessAttempts = 10;
- options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(15);
+ options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
options.Tokens.ProviderMap.Add("AliasVault", new TokenProviderDescriptor(typeof(DataProtectorTokenProvider<AliasVaultUser>)));
})
.AddEntityFrameworkStores<AliasServerDbContext>()
diff --git a/src/Tests/AliasVault.E2ETests/Infrastructure/WebApplicationAdminFactoryFixture.cs b/src/Tests/AliasVault.E2ETests/Infrastructure/WebApplicationAdminFactoryFixture.cs
index e258b568a..f8124dd50 100644
--- a/src/Tests/AliasVault.E2ETests/Infrastructure/WebApplicationAdminFactoryFixture.cs
+++ b/src/Tests/AliasVault.E2ETests/Infrastructure/WebApplicationAdminFactoryFixture.cs
@@ -80,74 +80,92 @@ public class WebApplicationAdminFactoryFixture<TEntryPoint> : WebApplicationFact
}
/// <inheritdoc />
- protected override void ConfigureWebHost(IWebHostBuilder builder)
+ protected override IHost CreateHost(IHostBuilder builder)
{
- builder.UseUrls(HostUrl);
+ var dummyHost = builder.Build();
- // Set static environment variables for the test.
- // These are used in the Admin project to set the admin password hash and last password change date.
- // An admin user will automatically be created with these values if the database is empty.
- Environment.SetEnvironmentVariable("ADMIN_PASSWORD_HASH", "AQAAAAIAAYagAAAAEKWfKfa2gh9Z72vjAlnNP1xlME7FsunRznzyrfqFte40FToufRwa3kX8wwDwnEXZag==");
- Environment.SetEnvironmentVariable("ADMIN_PASSWORD_GENERATED", "2024-01-01T00:00:00Z");
- Environment.SetEnvironmentVariable("DATA_PROTECTION_CERT_PASS", "Development");
+ builder.ConfigureWebHost(webHostBuilder => webHostBuilder.UseKestrel());
- builder.ConfigureServices((context, services) =>
- {
- // Remove the existing DbContextFactory registration
- var dbContextFactoryDescriptor = services.SingleOrDefault(
- d => d.ServiceType == typeof(IDbContextFactory<AliasServerDbContext>));
+ var host = builder.Build();
+ host.Start();
- services.Remove(dbContextFactoryDescriptor ?? throw new InvalidOperationException("No IDbContextFactory<AliasServerDbContext> registered."));
+ // Get the DbContextFactory instance and store it for later use during tests.
+ _dbContextFactory = host.Services.GetRequiredService<IDbContextFactory<AliasServerDbContext>>();
- // Remove the existing DbConnection registration.
- var dbConnectionDescriptor = services.SingleOrDefault(
- d => d.ServiceType == typeof(DbConnection));
+ // This delay prevents "ERR_CONNECTION_REFUSED" errors
+ // which happened like 1 out of 10 times when running tests.
+ Thread.Sleep(100);
- services.Remove(dbConnectionDescriptor ?? throw new InvalidOperationException("No DbContextOptions<AliasServerDbContext> registered."));
+ return dummyHost;
+ }
- // Remove the existing VersionedContentService registration.
- var versionedContentServiceDescriptor = services.SingleOrDefault(
- d => d.ServiceType == typeof(VersionedContentService));
+ /// <inheritdoc />
+ protected override void ConfigureWebHost(IWebHostBuilder builder)
+ {
+ builder.UseUrls(HostUrl);
- // Add the DbConnection as a singleton
- services.AddSingleton(_dbConnection);
+ SetEnvironmentVariables();
- // Add the DbContextFactory
- services.AddDbContextFactory<AliasServerDbContext>((container, options) =>
- {
- var connection = container.GetRequiredService<DbConnection>();
- options.UseSqlite(connection).UseLazyLoadingProxies();
- });
-
- // Add the VersionedContentService
- services.AddSingleton(new VersionedContentService("../../../../../AliasVault.Admin/wwwroot"));
-
- // Enable detailed errors for server-side Blazor.
- services.AddServerSideBlazor()
- .AddCircuitOptions(options =>
- {
- options.DetailedErrors = true;
- });
+ builder.ConfigureServices(services =>
+ {
+ RemoveExistingRegistrations(services);
+ AddNewRegistrations(services);
});
}
- /// <inheritdoc />
- protected override IHost CreateHost(IHostBuilder builder)
+ /// <summary>
+ /// Sets the required environment variables for testing.
+ /// </summary>
+ private static void SetEnvironmentVariables()
{
- var dummyHost = builder.Build();
+ Environment.SetEnvironmentVariable("ADMIN_PASSWORD_HASH", "AQAAAAIAAYagAAAAEKWfKfa2gh9Z72vjAlnNP1xlME7FsunRznzyrfqFte40FToufRwa3kX8wwDwnEXZag==");
+ Environment.SetEnvironmentVariable("ADMIN_PASSWORD_GENERATED", "2024-01-01T00:00:00Z");
+ Environment.SetEnvironmentVariable("DATA_PROTECTION_CERT_PASS", "Development");
+ }
- builder.ConfigureWebHost(webHostBuilder => webHostBuilder.UseKestrel());
+ /// <summary>
+ /// Removes existing service registrations.
+ /// </summary>
+ /// <param name="services">The <see cref="IServiceCollection"/> to modify.</param>
+ private static void RemoveExistingRegistrations(IServiceCollection services)
+ {
+ var descriptorsToRemove = new[]
+ {
+ services.SingleOrDefault(d => d.ServiceType == typeof(IDbContextFactory<AliasServerDbContext>)),
+ services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions<AliasServerDbContext>)),
+ services.SingleOrDefault(d => d.ServiceType == typeof(VersionedContentService)),
+ };
- var host = builder.Build();
- host.Start();
+ foreach (var descriptor in descriptorsToRemove)
+ {
+ if (descriptor != null)
+ {
+ services.Remove(descriptor);
+ }
+ }
+ }
- // Get the DbContextFactory instance and store it for later use during tests.
- _dbContextFactory = host.Services.GetRequiredService<IDbContextFactory<AliasServerDbContext>>();
+ /// <summary>
+ /// Adds new service registrations.
+ /// </summary>
+ /// <param name="services">The <see cref="IServiceCollection"/> to modify.</param>
+ private void AddNewRegistrations(IServiceCollection services)
+ {
+ // Add the DbConnection as a singleton
+ services.AddSingleton(_dbConnection);
- // This delay prevents "ERR_CONNECTION_REFUSED" errors
- // which happened like 1 out of 10 times when running tests.
- Thread.Sleep(100);
+ // Add the DbContextFactory
+ services.AddDbContextFactory<AliasServerDbContext>((container, options) =>
+ {
+ var connection = container.GetRequiredService<DbConnection>();
+ options.UseSqlite(connection).UseLazyLoadingProxies();
+ });
- return dummyHost;
+ // Add the VersionedContentService
+ services.AddSingleton(new VersionedContentService("../../../../../AliasVault.Admin/wwwroot"));
+
+ // Configure ServerSideBlazor with detailed errors
+ services.AddServerSideBlazor()
+ .AddCircuitOptions(options => options.DetailedErrors = true);
}
}
diff --git a/src/Tests/AliasVault.E2ETests/Infrastructure/WebApplicationApiFactoryFixture.cs b/src/Tests/AliasVault.E2ETests/Infrastructure/WebApplicationApiFactoryFixture.cs
index e4a183457..b9d77fae8 100644
--- a/src/Tests/AliasVault.E2ETests/Infrastructure/WebApplicationApiFactoryFixture.cs
+++ b/src/Tests/AliasVault.E2ETests/Infrastructure/WebApplicationApiFactoryFixture.cs
@@ -85,66 +85,90 @@ public class WebApplicationApiFactoryFixture<TEntryPoint> : WebApplicationFactor
}
/// <inheritdoc />
- protected override void ConfigureWebHost(IWebHostBuilder builder)
+ protected override IHost CreateHost(IHostBuilder builder)
{
- builder.UseUrls(HostUrl);
-
- // Set required environment variables to debug values.
- Environment.SetEnvironmentVariable("JWT_KEY", "12345678901234567890123456789012");
- Environment.SetEnvironmentVariable("DATA_PROTECTION_CERT_PASS", "Development");
+ var dummyHost = builder.Build();
- builder.ConfigureServices((context, services) =>
- {
- // Remove the existing DbContextFactory registration
- var timeProviderDescriptor = services.SingleOrDefault(
- d => d.ServiceType == typeof(ITimeProvider));
+ builder.ConfigureWebHost(webHostBuilder => webHostBuilder.UseKestrel());
- services.Remove(timeProviderDescriptor ?? throw new InvalidOperationException("No ITimeProvider registered."));
+ var host = builder.Build();
+ host.Start();
- // Remove the existing DbContextFactory registration
- var dbContextFactoryDescriptor = services.SingleOrDefault(
- d => d.ServiceType == typeof(IDbContextFactory<AliasServerDbContext>));
+ // Get the DbContextFactory instance and store it for later use during tests.
+ _dbContextFactory = host.Services.GetRequiredService<IDbContextFactory<AliasServerDbContext>>();
- services.Remove(dbContextFactoryDescriptor ?? throw new InvalidOperationException("No IDbContextFactory<AliasServerDbContext> registered."));
+ // This delay prevents "ERR_CONNECTION_REFUSED" errors
+ // which happened like 1 out of 10 times when running tests.
+ Thread.Sleep(100);
- // Remove the existing DbConnection registration.
- var dbConnectionDescriptor = services.SingleOrDefault(
- d => d.ServiceType == typeof(DbConnection));
+ return dummyHost;
+ }
- services.Remove(dbConnectionDescriptor ?? throw new InvalidOperationException("No DbContextOptions<AliasServerDbContext> registered."));
+ /// <inheritdoc />
+ protected override void ConfigureWebHost(IWebHostBuilder builder)
+ {
+ builder.UseUrls(HostUrl);
- // Add the DbConnection as a singleton
- services.AddSingleton(_dbConnection);
+ SetEnvironmentVariables();
- // Add the DbContextFactory
- services.AddDbContextFactory<AliasServerDbContext>((container, options) =>
- {
- var connection = container.GetRequiredService<DbConnection>();
- options.UseSqlite(connection).UseLazyLoadingProxies();
- });
+ builder.ConfigureServices((context, services) =>
+ {
+ // Remove existing registrations
+ RemoveExistingRegistrations(services);
- // Add TestTimeProvider
- services.AddSingleton<ITimeProvider>(TimeProvider);
+ // Add new registrations
+ AddNewRegistrations(services);
});
}
- /// <inheritdoc />
- protected override IHost CreateHost(IHostBuilder builder)
+ /// <summary>
+ /// Sets the required environment variables for testing.
+ /// </summary>
+ private static void SetEnvironmentVariables()
{
- var dummyHost = builder.Build();
+ Environment.SetEnvironmentVariable("JWT_KEY", "12345678901234567890123456789012");
+ Environment.SetEnvironmentVariable("DATA_PROTECTION_CERT_PASS", "Development");
+ }
- builder.ConfigureWebHost(webHostBuilder => webHostBuilder.UseKestrel());
+ /// <summary>
+ /// Removes existing service registrations.
+ /// </summary>
+ /// <param name="services">The <see cref="IServiceCollection"/> to modify.</param>
+ private static void RemoveExistingRegistrations(IServiceCollection services)
+ {
+ var descriptorsToRemove = new[]
+ {
+ services.SingleOrDefault(d => d.ServiceType == typeof(ITimeProvider)),
+ services.SingleOrDefault(d => d.ServiceType == typeof(IDbContextFactory<AliasServerDbContext>)),
+ services.SingleOrDefault(d => d.ServiceType == typeof(DbContextOptions<AliasServerDbContext>)),
+ };
- var host = builder.Build();
- host.Start();
+ foreach (var descriptor in descriptorsToRemove)
+ {
+ if (descriptor != null)
+ {
+ services.Remove(descriptor);
+ }
+ }
+ }
- // Get the DbContextFactory instance and store it for later use during tests.
- _dbContextFactory = host.Services.GetRequiredService<IDbContextFactory<AliasServerDbContext>>();
+ /// <summary>
+ /// Adds new service registrations.
+ /// </summary>
+ /// <param name="services">The <see cref="IServiceCollection"/> to modify.</param>
+ private void AddNewRegistrations(IServiceCollection services)
+ {
+ // Add the DbConnection as a singleton
+ services.AddSingleton(_dbConnection);
- // This delay prevents "ERR_CONNECTION_REFUSED" errors
- // which happened like 1 out of 10 times when running tests.
- Thread.Sleep(100);
+ // Add the DbContextFactory
+ services.AddDbContextFactory<AliasServerDbContext>((container, options) =>
+ {
+ var connection = container.GetRequiredService<DbConnection>();
+ options.UseSqlite(connection).UseLazyLoadingProxies();
+ });
- return dummyHost;
+ // Add TestTimeProvider
+ services.AddSingleton<ITimeProvider>(TimeProvider);
}
}