Skip to content

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

Refactor (#190)

Leendert de Borstd77c28184c69
diff --git a/.github/workflows/dotnet-e2e-admin-tests.yml b/.github/workflows/dotnet-e2e-admin-tests.yml
index 70ab08b93..040ee69ea 100644
--- a/.github/workflows/dotnet-e2e-admin-tests.yml
+++ b/.github/workflows/dotnet-e2e-admin-tests.yml
@@ -30,8 +30,16 @@ jobs:
- name: Wait for database to be up
run: |
- # Wait for a few seconds
- sleep 5
+ timeout=30
+ while ! nc -z localhost 5433; do
+ if [ "$timeout" -le "0" ]; then
+ echo "Timed out waiting for database"
+ exit 1
+ fi
+ echo "Waiting for database to be available on port 5433..."
+ sleep 1
+ timeout=$((timeout-1))
+ done
- name: Ensure browsers are installed
run: pwsh src/Tests/AliasVault.E2ETests/bin/Debug/net9.0/playwright.ps1 install --with-deps
diff --git a/.github/workflows/dotnet-e2e-client-tests.yml b/.github/workflows/dotnet-e2e-client-tests.yml
index b10b7a18a..bfbfcdd5e 100644
--- a/.github/workflows/dotnet-e2e-client-tests.yml
+++ b/.github/workflows/dotnet-e2e-client-tests.yml
@@ -34,8 +34,16 @@ jobs:
- name: Wait for database to be up
run: |
- # Wait for a few seconds
- sleep 5
+ timeout=30
+ while ! nc -z localhost 5433; do
+ if [ "$timeout" -le "0" ]; then
+ echo "Timed out waiting for database"
+ exit 1
+ fi
+ echo "Waiting for database to be available on port 5433..."
+ sleep 1
+ timeout=$((timeout-1))
+ done
- name: Ensure browsers are installed
run: pwsh src/Tests/AliasVault.E2ETests/bin/Debug/net9.0/playwright.ps1 install --with-deps
diff --git a/.github/workflows/dotnet-e2e-misc-tests.yml b/.github/workflows/dotnet-e2e-misc-tests.yml
index d0d132a57..79cf2dc89 100644
--- a/.github/workflows/dotnet-e2e-misc-tests.yml
+++ b/.github/workflows/dotnet-e2e-misc-tests.yml
@@ -30,8 +30,16 @@ jobs:
- name: Wait for database to be up
run: |
- # Wait for a few seconds
- sleep 5
+ timeout=30
+ while ! nc -z localhost 5433; do
+ if [ "$timeout" -le "0" ]; then
+ echo "Timed out waiting for database"
+ exit 1
+ fi
+ echo "Waiting for database to be available on port 5433..."
+ sleep 1
+ timeout=$((timeout-1))
+ done
- name: Ensure browsers are installed
run: pwsh src/Tests/AliasVault.E2ETests/bin/Debug/net9.0/playwright.ps1 install --with-deps
diff --git a/.github/workflows/dotnet-integration-tests.yml b/.github/workflows/dotnet-integration-tests.yml
index add403b98..754d43ba7 100644
--- a/.github/workflows/dotnet-integration-tests.yml
+++ b/.github/workflows/dotnet-integration-tests.yml
@@ -30,8 +30,16 @@ jobs:
- name: Wait for database to be up
run: |
- # Wait for a few seconds
- sleep 5
+ timeout=30
+ while ! nc -z localhost 5433; do
+ if [ "$timeout" -le "0" ]; then
+ echo "Timed out waiting for database"
+ exit 1
+ fi
+ echo "Waiting for database to be available on port 5433..."
+ sleep 1
+ timeout=$((timeout-1))
+ done
- name: Run integration tests
run: dotnet test src/Tests/AliasVault.IntegrationTests --no-build --verbosity normal
diff --git a/docs/misc/release/create-new-release.md b/docs/misc/release/create-new-release.md
index cc0bc68f9..4c8d3dc24 100644
--- a/docs/misc/release/create-new-release.md
+++ b/docs/misc/release/create-new-release.md
@@ -12,11 +12,11 @@ Follow the steps in the checklist below to prepare a new release.
## Versioning
- [ ] Update ./src/Shared/AliasVault.Shared.Core/AppInfo.cs and update major/minor/patch to the new version. This version will be shown in the client and admin app footer.
-- [ ] Update ./install.sh `@version` in header if the install script has changed. This allows the install script to self-update when running ./install.sh update command on default installations.
+- [ ] Update ./install.sh `@version` in header if the install script has changed. This allows the install script to self-update when running the `./install.sh update` command on default installations.
## Docker Images
If docker containers have been added or removed:
-- [ ] Verify that `publish-docker-images.yml` contains all docker images that need to be published.
+- [ ] Verify that `.github/workflows/publish-docker-images.yml` contains references to all docker images that need to be published.
- [ ] Update `install.sh` and verify that the `images()` array that takes care of pulling the images from the GitHub Container Registry is updated.
## Documentation
diff --git a/src/Utilities/AliasVault.InstallCli/Program.cs b/src/Utilities/AliasVault.InstallCli/Program.cs
index ddd9efee2..9d889ff54 100644
--- a/src/Utilities/AliasVault.InstallCli/Program.cs
+++ b/src/Utilities/AliasVault.InstallCli/Program.cs
@@ -8,6 +8,7 @@
using AliasServerDb;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Metadata;
// Add return type for top-level statements
return await Run(args);
@@ -233,26 +234,7 @@ public static partial class Program
foreach (var item in items)
{
- // Check each property for MaxLength annotation
- foreach (var property in entityType!.GetProperties())
- {
- // Only process string properties
- if (property.ClrType == typeof(string))
- {
- var maxLength = property.GetMaxLength();
- if (maxLength.HasValue)
- {
- var propertyInfo = typeof(T).GetProperty(property.Name);
- var value = propertyInfo?.GetValue(item) as string;
-
- if (value?.Length > maxLength.Value)
- {
- propertyInfo?.SetValue(item, value.Substring(0, maxLength.Value));
- Console.WriteLine($"Truncated {property.Name} in {tableName} from {value.Length} to {maxLength.Value} characters");
- }
- }
- }
- }
+ HandleMaxLengthConstraints(item, entityType!, tableName);
}
const int batchSize = 50;
@@ -272,20 +254,10 @@ public static partial class Program
}
}
- // Only reset sequence if requested
+ // Handle sequence reset logic...
if (resetSequence && destinationContext.Database.ProviderName == "Npgsql.EntityFrameworkCore.PostgreSQL")
{
- var tablePgName = destinationContext.Model.FindEntityType(typeof(T))?.GetTableName();
- if (!string.IsNullOrEmpty(tablePgName))
- {
- var schema = destinationContext.Model.FindEntityType(typeof(T))?.GetSchema() ?? "public";
- var sql = $"""
- SELECT setval(pg_get_serial_sequence('{schema}."{tablePgName}"', 'Id'),
- (SELECT COALESCE(MAX("Id"::integer), 0) + 1 FROM {schema}."{tablePgName}"), false);
- """;
- await destinationContext.Database.ExecuteSqlRawAsync(sql);
- Console.WriteLine($"Reset sequence for {tableName}");
- }
+ await ResetSequence<T>(destinationContext, tableName);
}
}
@@ -296,6 +268,60 @@ public static partial class Program
}
}
+ /// <summary>
+ /// Handles max length constraints for string properties in an entity.
+ /// </summary>
+ /// <typeparam name="T">The entity type containing the properties to be processed.</typeparam>
+ /// <param name="item">The entity instance containing the properties to be processed.</param>
+ /// <param name="entityType">The entity type to be processed.</param>
+ /// <param name="tableName">The name of the table being processed (for logging purposes).</param>
+ private static void HandleMaxLengthConstraints<T>(T item, IEntityType entityType, string tableName)
+ where T : class
+ {
+ foreach (var property in entityType.GetProperties())
+ {
+ // Only process string properties
+ if (property.ClrType == typeof(string))
+ {
+ var maxLength = property.GetMaxLength();
+ if (maxLength.HasValue)
+ {
+ var propertyInfo = typeof(T).GetProperty(property.Name);
+ var value = propertyInfo?.GetValue(item) as string;
+
+ if (value?.Length > maxLength.Value)
+ {
+ propertyInfo!.SetValue(item, value.Substring(0, maxLength.Value));
+ Console.WriteLine($"Truncated {property.Name} in {tableName} from {value.Length} to {maxLength.Value} characters");
+ }
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Resets the sequence for a table in the PostgreSQL database.
+ /// </summary>
+ /// <typeparam name="T">The entity type of the table being reset.</typeparam>
+ /// <param name="destinationContext">The destination database context.</param>
+ /// <param name="tableName">The name of the table being reset (for logging purposes).</param>
+ /// <returns>A task representing the asynchronous operation.</returns>
+ private static async Task ResetSequence<T>(DbContext destinationContext, string tableName)
+ where T : class
+ {
+ var tablePgName = destinationContext.Model.FindEntityType(typeof(T))?.GetTableName();
+ if (!string.IsNullOrEmpty(tablePgName))
+ {
+ var schema = destinationContext.Model.FindEntityType(typeof(T))?.GetSchema() ?? "public";
+ var sql = $"""
+ SELECT setval(pg_get_serial_sequence('{schema}."{tablePgName}"', 'Id'),
+ (SELECT COALESCE(MAX("Id"::integer), 0) + 1 FROM {schema}."{tablePgName}"), false);
+ """;
+ await destinationContext.Database.ExecuteSqlRawAsync(sql);
+ Console.WriteLine($"Reset sequence for {tableName}");
+ }
+ }
+
/// <summary>
/// Handles a concurrency conflict by updating the original values with the database values.
/// </summary>