Skip to content

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

Add settings mutate endpoint for browser extension e2e tests (#1786)

Leendert de Borst631e5369a56a
diff --git a/apps/browser-extension/tests/global-setup.ts b/apps/browser-extension/tests/global-setup.ts
index a7cac314b..f4dce6f99 100644
--- a/apps/browser-extension/tests/global-setup.ts
+++ b/apps/browser-extension/tests/global-setup.ts
@@ -11,6 +11,28 @@ import { isApiAvailable } from './helpers/test-api';
*/
const DEFAULT_API_URL = process.env.ALIASVAULT_API_URL || 'http://localhost:5092';
+/**
+ * Set a server setting via the DEBUG-only test controller.
+ * Fails loudly if the endpoint is missing — a Release build of the API is not
+ * testable with this suite because the tests share one IP against a persistent DB.
+ */
+async function setServerSetting(apiUrl: string, key: string, value: string): Promise<void> {
+ const url = `${apiUrl.replace(/\/$/, '')}/v1/Test/server-settings`;
+ const response = await fetch(url, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ key, value }),
+ });
+
+ if (!response.ok) {
+ throw new Error(
+ `Failed to set server setting "${key}" via ${url} (status ${response.status}). ` +
+ 'The test controller is only compiled into DEBUG builds and only active when ASPNETCORE_ENVIRONMENT=Development. ' +
+ 'Rebuild the API in Debug/Development to run the e2e suite.'
+ );
+ }
+}
+
export default async function globalSetup(): Promise<void> {
console.log(`Checking API availability at ${DEFAULT_API_URL}...`);
@@ -24,5 +46,8 @@ export default async function globalSetup(): Promise<void> {
);
}
- console.log('API is available. Proceeding with tests...');
+ // Tests all register from the same source IP, so we disable the rate limit.
+ await setServerSetting(DEFAULT_API_URL, 'MaxRegistrationsPerIpPer24Hours', '0');
+
+ console.log('API is available and test settings applied. Proceeding with tests...');
}
diff --git a/apps/server/AliasVault.Api/Controllers/Tests/SetServerSettingRequest.cs b/apps/server/AliasVault.Api/Controllers/Tests/SetServerSettingRequest.cs
new file mode 100644
index 000000000..c7918ba07
--- /dev/null
+++ b/apps/server/AliasVault.Api/Controllers/Tests/SetServerSettingRequest.cs
@@ -0,0 +1,27 @@
+//-----------------------------------------------------------------------
+// <copyright file="SetServerSettingRequest.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Api.Controllers.Tests;
+
+#if DEBUG
+
+/// <summary>
+/// Request to set a server setting by key/value from the E2E TestController.
+/// </summary>
+public class SetServerSettingRequest
+{
+ /// <summary>
+ /// Gets the setting key to update (e.g. "MaxRegistrationsPerIpPer24Hours").
+ /// </summary>
+ public required string Key { get; init; } = string.Empty;
+
+ /// <summary>
+ /// Gets the value to assign to the setting. Null clears the value.
+ /// </summary>
+ public string? Value { get; init; }
+}
+#endif
diff --git a/apps/server/AliasVault.Api/Controllers/Tests/TestController.cs b/apps/server/AliasVault.Api/Controllers/Tests/TestController.cs
index c82f3234e..153e8ac2e 100644
--- a/apps/server/AliasVault.Api/Controllers/Tests/TestController.cs
+++ b/apps/server/AliasVault.Api/Controllers/Tests/TestController.cs
@@ -16,6 +16,7 @@ namespace AliasVault.Api.Controllers.Tests;
using AliasServerDb;
using AliasVault.Api.Controllers.Abstracts;
+using AliasVault.Shared.Server.Services;
using Asp.Versioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
@@ -31,11 +32,13 @@ using Microsoft.EntityFrameworkCore;
/// <param name="userManager">UserManager instance.</param>
/// <param name="environment">IWebHostEnvironment instance.</param>
/// <param name="dbContextFactory">DbContext factory instance.</param>
+/// <param name="serverSettingsService">ServerSettingsService instance.</param>
[ApiVersion("1")]
public class TestController(
UserManager<AliasVaultUser> userManager,
IWebHostEnvironment environment,
- IAliasServerDbContextFactory dbContextFactory) : AuthenticatedRequestController(userManager)
+ IAliasServerDbContextFactory dbContextFactory,
+ ServerSettingsService serverSettingsService) : AuthenticatedRequestController(userManager)
{
/// <summary>
/// Authenticated test request. Used to verify authentication is working.
@@ -411,5 +414,61 @@ public class TestController(
message = $"User {user.UserName} has been unblocked",
});
}
+
+ /// <summary>
+ /// Set a server setting by key/value. Used by E2E tests to tune runtime limits
+ /// (e.g. disabling the per-IP registration rate limit by setting it to 0).
+ /// Anonymous endpoint for E2E tests that cannot access auth tokens.
+ /// Only available in DEBUG builds.
+ /// </summary>
+ /// <param name="request">The setting to update.</param>
+ /// <returns>OK with the updated key and value.</returns>
+ [AllowAnonymous]
+ [HttpPost("server-settings")]
+ public async Task<IActionResult> SetServerSetting([FromBody] SetServerSettingRequest request)
+ {
+ if (!environment.IsDevelopment())
+ {
+ return NotFound();
+ }
+
+ if (string.IsNullOrWhiteSpace(request.Key))
+ {
+ return BadRequest("Key is required");
+ }
+
+ await serverSettingsService.SetSettingAsync(request.Key, request.Value);
+
+ return Ok(new
+ {
+ key = request.Key,
+ value = request.Value,
+ });
+ }
+
+ /// <summary>
+ /// Get a server setting by key.
+ /// Anonymous endpoint for E2E tests that cannot access auth tokens.
+ /// Only available in DEBUG builds.
+ /// </summary>
+ /// <param name="key">The setting key to read.</param>
+ /// <returns>OK with the current key and value (value may be null if unset).</returns>
+ [AllowAnonymous]
+ [HttpGet("server-settings/{key}")]
+ public async Task<IActionResult> GetServerSetting(string key)
+ {
+ if (!environment.IsDevelopment())
+ {
+ return NotFound();
+ }
+
+ var value = await serverSettingsService.GetSettingAsync(key);
+
+ return Ok(new
+ {
+ key,
+ value,
+ });
+ }
}
#endif