diff --git a/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor b/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor
index fbaab63de..ce7e642a6 100644
--- a/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor
+++ b/src/AliasVault.Client/Main/Pages/Credentials/AddEdit.razor
@@ -66,7 +66,7 @@ else
Notes
diff --git a/src/AliasVault.Client/Services/SettingsService.cs b/src/AliasVault.Client/Services/SettingsService.cs
index 242cf70c5..30ba2722a 100644
--- a/src/AliasVault.Client/Services/SettingsService.cs
+++ b/src/AliasVault.Client/Services/SettingsService.cs
@@ -184,11 +184,7 @@ public class SettingsService
{
string value = GetSetting(key);
- try
- {
- return CastSetting(value);
- }
- catch (InvalidOperationException ex)
+ if (string.IsNullOrEmpty(value))
{
// If no value is available in database but default value is set, return default value.
if (defaultValue is not null)
@@ -197,6 +193,15 @@ public class SettingsService
}
// No value in database and no default value set, throw exception.
+ throw new InvalidOperationException($"Setting {key} is not set and no default value is provided");
+ }
+
+ try
+ {
+ return CastSetting(value);
+ }
+ catch (InvalidOperationException ex)
+ {
throw new InvalidOperationException($"Failed to cast setting {key} to type {typeof(T)}", ex);
}
}
diff --git a/src/Tests/AliasVault.E2ETests/Tests/Client/CredentialTest.cs b/src/Tests/AliasVault.E2ETests/Tests/Client/CredentialTest.cs
index 6a3f70285..d1a65829a 100644
--- a/src/Tests/AliasVault.E2ETests/Tests/Client/CredentialTest.cs
+++ b/src/Tests/AliasVault.E2ETests/Tests/Client/CredentialTest.cs
@@ -86,4 +86,47 @@ public class CredentialTest : ClientPlaywrightTest
Assert.That(pageContent, Does.Contain("Credentials updated"), "Credential update confirmation message not shown.");
Assert.That(pageContent, Does.Contain(serviceNameAfter), "Credential not updated correctly.");
}
+
+ ///
+ /// Test if generating a new identity on the create new credential screen works.
+ ///
+ /// Async task.
+ [Test]
+ public async Task GenerateIdentityTest()
+ {
+ // Create a new alias with service name = "Test Service".
+ var serviceName = "Test Service";
+
+ await NavigateUsingBlazorRouter("add-credentials");
+ await WaitForUrlAsync("add-credentials", "Add credentials");
+
+ await InputHelper.FillInputFields(
+ fieldValues: new Dictionary
+ {
+ { "service-name", serviceName },
+ });
+
+ // Wait for button with text "Generate Random Identity" to appear.
+ var generateButton = Page.Locator("text=Generate Random Identity");
+ Assert.That(generateButton, Is.Not.Null, "Generate button not found.");
+
+ // Press the button to generate a random identity.
+ await generateButton.First.ClickAsync();
+
+ // Wait for the identity fields to be filled.
+ await Task.Delay(1000);
+
+ // Verify that the identity fields are filled.
+ var username = await Page.InputValueAsync("#username");
+ var firstName = await Page.InputValueAsync("#first-name");
+ var lastName = await Page.InputValueAsync("#last-name");
+
+ Assert.Multiple(
+ () =>
+ {
+ Assert.That(username, Is.Not.Null.And.Not.Empty, "Username not generated.");
+ Assert.That(firstName, Is.Not.Null.And.Not.Empty, "First name not generated.");
+ Assert.That(lastName, Is.Not.Null.And.Not.Empty, "Last name not generated.");
+ });
+ }
}