Skip to content

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

Update swift logic to test for specific credential values (#771)

Leendert de Borst83f64c505e24
diff --git a/mobile-app/ios/Autofill/CredentialProviderView.swift b/mobile-app/ios/Autofill/CredentialProviderView.swift
index 25b6f0512..a99a1bb27 100644
--- a/mobile-app/ios/Autofill/CredentialProviderView.swift
+++ b/mobile-app/ios/Autofill/CredentialProviderView.swift
@@ -356,9 +356,22 @@ class CredentialProviderViewModel: ObservableObject {
isDeleted: false
)
+ let alias = Alias(
+ id: UUID(),
+ gender: nil,
+ firstName: nil,
+ lastName: nil,
+ nickName: nil,
+ birthDate: Date(),
+ email: nil,
+ createdAt: Date(),
+ updatedAt: Date(),
+ isDeleted: false
+ )
+
let credential = Credential(
id: UUID(),
- aliasId: UUID(), // This should be provided by the system
+ alias: alias,
service: service,
username: newUsername,
notes: nil,
diff --git a/mobile-app/ios/VaultStore/Models/Credential.swift b/mobile-app/ios/VaultStore/Models/Credential.swift
index 5abb73d2a..6a02a9696 100644
--- a/mobile-app/ios/VaultStore/Models/Credential.swift
+++ b/mobile-app/ios/VaultStore/Models/Credential.swift
@@ -2,7 +2,7 @@ import Foundation
public struct Credential: Codable {
public let id: UUID
- public let aliasId: UUID
+ public let alias: Alias?
public let service: Service
public let username: String?
public let notes: String?
@@ -13,7 +13,7 @@ public struct Credential: Codable {
public init(
id: UUID,
- aliasId: UUID,
+ alias: Alias?,
service: Service,
username: String?,
notes: String?,
@@ -23,7 +23,7 @@ public struct Credential: Codable {
isDeleted: Bool
) {
self.id = id
- self.aliasId = aliasId
+ self.alias = alias
self.service = service
self.username = username
self.notes = notes
@@ -85,4 +85,41 @@ public struct Password: Codable {
self.updatedAt = updatedAt
self.isDeleted = isDeleted
}
+}
+
+public struct Alias: Codable, Hashable {
+ public let id: UUID
+ public let gender: String?
+ public let firstName: String?
+ public let lastName: String?
+ public let nickName: String?
+ public let birthDate: Date
+ public let email: String?
+ public let createdAt: Date
+ public let updatedAt: Date
+ public let isDeleted: Bool
+
+ public init(
+ id: UUID,
+ gender: String?,
+ firstName: String?,
+ lastName: String?,
+ nickName: String?,
+ birthDate: Date,
+ email: String?,
+ createdAt: Date,
+ updatedAt: Date,
+ isDeleted: Bool
+ ) {
+ self.id = id
+ self.gender = gender
+ self.firstName = firstName
+ self.lastName = lastName
+ self.nickName = nickName
+ self.birthDate = birthDate
+ self.email = email
+ self.createdAt = createdAt
+ self.updatedAt = updatedAt
+ self.isDeleted = isDeleted
+ }
}
\ No newline at end of file
diff --git a/mobile-app/ios/VaultStore/VaultStore.swift b/mobile-app/ios/VaultStore/VaultStore.swift
index cb819df74..1c656c427 100644
--- a/mobile-app/ios/VaultStore/VaultStore.swift
+++ b/mobile-app/ios/VaultStore/VaultStore.swift
@@ -398,18 +398,28 @@ public class VaultStore {
lp.Value as password_value,
lp.CreatedAt as password_created_at,
lp.UpdatedAt as password_updated_at,
- lp.IsDeleted as password_is_deleted
+ lp.IsDeleted as password_is_deleted,
+ a.Id as alias_id,
+ a.Gender as alias_gender,
+ a.FirstName as alias_first_name,
+ a.LastName as alias_last_name,
+ a.NickName as alias_nick_name,
+ a.BirthDate as alias_birth_date,
+ a.Email as alias_email,
+ a.CreatedAt as alias_created_at,
+ a.UpdatedAt as alias_updated_at,
+ a.IsDeleted as alias_is_deleted
FROM Credentials c
LEFT JOIN Services s ON s.Id = c.ServiceId AND s.IsDeleted = 0
LEFT JOIN LatestPasswords lp ON lp.CredentialId = c.Id AND lp.rn = 1
+ LEFT JOIN Aliases a ON a.Id = c.AliasId AND a.IsDeleted = 0
WHERE c.IsDeleted = 0
ORDER BY c.CreatedAt DESC
"""
var result: [Credential] = []
for row in try db.prepare(query) {
- guard let idString = row[0] as? String,
- let aliasIdString = row[1] as? String else {
+ guard let idString = row[0] as? String else {
continue
}
@@ -450,6 +460,32 @@ public class VaultStore {
isDeleted: serviceIsDeleted
)
+ var alias: Alias? = nil
+ if let aliasIdString = row[19] as? String,
+ let aliasCreatedAtString = row[26] as? String,
+ let aliasUpdatedAtString = row[27] as? String,
+ let aliasIsDeletedInt64 = row[28] as? Int64,
+ let aliasCreatedAt = parseDateString(aliasCreatedAtString),
+ let aliasUpdatedAt = parseDateString(aliasUpdatedAtString),
+ let aliasBirthDateString = row[24] as? String,
+ let aliasBirthDate = parseDateString(aliasBirthDateString) {
+
+ let aliasIsDeleted = aliasIsDeletedInt64 == 1
+
+ alias = Alias(
+ id: UUID(uuidString: aliasIdString)!,
+ gender: row[20] as? String,
+ firstName: row[21] as? String,
+ lastName: row[22] as? String,
+ nickName: row[23] as? String,
+ birthDate: aliasBirthDate,
+ email: row[25] as? String,
+ createdAt: aliasCreatedAt,
+ updatedAt: aliasUpdatedAt,
+ isDeleted: aliasIsDeleted
+ )
+ }
+
var password: Password? = nil
if let passwordIdString = row[14] as? String,
let passwordValue = row[15] as? String,
@@ -473,7 +509,7 @@ public class VaultStore {
let credential = Credential(
id: UUID(uuidString: idString)!,
- aliasId: UUID(uuidString: aliasIdString)!,
+ alias: alias,
service: service,
username: row[2] as? String,
notes: row[3] as? String,
diff --git a/mobile-app/ios/VaultStoreTests/VaultStoreTests.swift b/mobile-app/ios/VaultStoreTests/VaultStoreTests.swift
index e265e95ee..b317aff5e 100644
--- a/mobile-app/ios/VaultStoreTests/VaultStoreTests.swift
+++ b/mobile-app/ios/VaultStoreTests/VaultStoreTests.swift
@@ -2,7 +2,7 @@ import XCTest
class VaultStoreTests: XCTestCase {
var vaultStore: VaultStore!
- let testEncryptionKeyBase64 = "qXcA7cJMA9gN0gfrvlbGL8/iUcay1ihT32N8i33DR/U=" // 32 bytes for AES-256
+ let testEncryptionKeyBase64 = "/9So3C83JLDIfjsF0VQOc4rz1uAFtIseW7yrUuztAD0=" // 32 bytes for AES-256
override func setUp() {
super.setUp()
@@ -39,7 +39,7 @@ class VaultStoreTests: XCTestCase {
let encryptedDb = try loadTestDatabase()
// TODO: get metadata via vault generation and pass it here so we have all info we need for all tests.
try vaultStore.storeEncryptedDatabase(encryptedDb, metadata: "")
-
+
// Initialize the database
try vaultStore.initializeDatabase()
@@ -57,6 +57,45 @@ class VaultStoreTests: XCTestCase {
}
}
+ /**
+ * This test verifies that the Gmail credential details are correct including
+ * the expectedlogo binary data.
+ */
+ func testGetGmailCredentialDetails() async throws {
+ // First, store the encryption key
+ try vaultStore.storeEncryptionKey(base64Key: testEncryptionKeyBase64)
+
+ // Load and store the encrypted database
+ let encryptedDb = try loadTestDatabase()
+ try vaultStore.storeEncryptedDatabase(encryptedDb, metadata: "")
+
+ // Initialize the database
+ try vaultStore.initializeDatabase()
+
+ // Get all credentials
+ let credentials = try vaultStore.getAllCredentials()
+
+ // Find the Gmail credential
+ let gmailCredential = credentials.first { $0.service.name == "Gmail Test Account" }
+ XCTAssertNotNil(gmailCredential, "Gmail Test Account credential should exist")
+
+ if let gmail = gmailCredential {
+ // Verify all expected properties
+ XCTAssertEqual(gmail.service.name, "Gmail Test Account")
+ XCTAssertEqual(gmail.service.url, "https://google.com")
+ XCTAssertEqual(gmail.username, "[email protected]")
+ XCTAssertEqual(gmail.alias?.firstName, "Test")
+ XCTAssertEqual(gmail.alias?.lastName, "User")
+ XCTAssertEqual(gmail.notes, "Test Gmail account for unit testing")
+
+ // Verify logo exists and has sufficient size
+ XCTAssertNotNil(gmail.service.logo, "Service logo should not be nil")
+ if let logoData = gmail.service.logo {
+ XCTAssertGreaterThan(logoData.count, 1024, "Logo data should exceed 1KB in size")
+ }
+ }
+ }
+
// Helper method to load test database file
private func loadTestDatabase() throws -> String {
// Look in the root of the test bundle Resources
diff --git a/src/Tests/AliasVault.E2ETests/Common/PlaywrightInputHelper.cs b/src/Tests/AliasVault.E2ETests/Common/PlaywrightInputHelper.cs
index 601361566..d80ab7526 100644
--- a/src/Tests/AliasVault.E2ETests/Common/PlaywrightInputHelper.cs
+++ b/src/Tests/AliasVault.E2ETests/Common/PlaywrightInputHelper.cs
@@ -78,7 +78,7 @@ public class PlaywrightInputHelper(IPage page)
/// <returns>Async task.</returns>
public async Task FillInputFields(Dictionary<string, string>? fieldValues = null)
{
- var inputFields = page.Locator("input");
+ var inputFields = page.Locator("input, textarea");
var count = await inputFields.CountAsync();
for (int i = 0; i < count; i++)
{
diff --git a/src/Tests/AliasVault.E2ETests/Tests/Extensions/TestVaultGeneratorTests.cs b/src/Tests/AliasVault.E2ETests/Tests/Extensions/TestVaultGeneratorTests.cs
index 6058d7801..01e384bb4 100644
--- a/src/Tests/AliasVault.E2ETests/Tests/Extensions/TestVaultGeneratorTests.cs
+++ b/src/Tests/AliasVault.E2ETests/Tests/Extensions/TestVaultGeneratorTests.cs
@@ -7,6 +7,7 @@
namespace AliasVault.E2ETests.Tests.Extensions;
+using System.Diagnostics;
using System.Reflection;
using AliasVault.Cryptography.Client;
using Microsoft.EntityFrameworkCore;
@@ -58,6 +59,7 @@ public class TestVaultGeneratorTests : BrowserExtensionPlaywrightTest
new Dictionary<string, string>
{
{ "service-name", "Gmail Test Account" },
+ { "service-url", "https://google.com" },
{ "username", "[email protected]" },
{ "first-name", "Test" },
{ "last-name", "User" },
@@ -159,8 +161,18 @@ public class TestVaultGeneratorTests : BrowserExtensionPlaywrightTest
Console.WriteLine($"Encryption Settings: {vault.EncryptionSettings}");
Console.WriteLine($"Decryption Key (Base64): {decryptionKeyBase64}");
Console.WriteLine("\nInstructions:");
- Console.WriteLine("1. Copy the encrypted vault file from the location above");
- Console.WriteLine("2. Use the decryption key (Base64) in your unit tests");
+ Console.WriteLine("1. Copy the updated encrypted vault file from the location above to the test project(s)");
+ Console.WriteLine("2. Copy the updated decryption key (Base64) in the unit tests (it changes each time)");
Console.WriteLine("3. The vault contains 5 test credentials that can be used for verification");
+
+ // Open file explorer at the output location
+ if (OperatingSystem.IsMacOS())
+ {
+ Process.Start("open", vaultOutputDir);
+ }
+ else if (OperatingSystem.IsWindows())
+ {
+ Process.Start("explorer.exe", vaultOutputDir);
+ }
}
}