Make db init test work (#771)

This commit is contained in:
Leendert de Borst
2025-04-25 20:45:00 +02:00
parent 51b3956caf
commit cb61b73553
3 changed files with 31 additions and 56 deletions

View File

@@ -2,7 +2,7 @@ import XCTest
class VaultStoreTests: XCTestCase {
var vaultStore: VaultStore!
let testEncryptionKey = "testEncryptionKey1234567890123456789012" // 32 bytes for AES-256
let testEncryptionKeyBase64 = "qXcA7cJMA9gN0gfrvlbGL8/iUcay1ihT32N8i33DR/U=" // 32 bytes for AES-256
override func setUp() {
super.setUp()
@@ -17,7 +17,12 @@ class VaultStoreTests: XCTestCase {
func testDatabaseInitialization() async throws {
// First, store the encryption key
try vaultStore.storeEncryptionKey(base64Key: testEncryptionKey)
try vaultStore.storeEncryptionKey(base64Key: testEncryptionKeyBase64)
// Load and store the encrypted database
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: "")
// Then try to initialize the database
try vaultStore.initializeDatabase()
@@ -28,8 +33,13 @@ class VaultStoreTests: XCTestCase {
func testGetAllCredentials() async throws {
// First, store the encryption key
try vaultStore.storeEncryptionKey(base64Key: testEncryptionKey)
try vaultStore.storeEncryptionKey(base64Key: testEncryptionKeyBase64)
// Load and store the encrypted database
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()
@@ -48,12 +58,15 @@ class VaultStoreTests: XCTestCase {
}
// Helper method to load test database file
private func loadTestDatabase() throws -> Data {
// TODO: Add your test database file to the test bundle
// and load it here
guard let testDbPath = Bundle(for: type(of: self)).path(forResource: "test_db", ofType: "sqlite") else {
throw NSError(domain: "VaultStoreTests", code: 1, userInfo: [NSLocalizedDescriptionKey: "Test database file not found"])
private func loadTestDatabase() throws -> String {
// Look in the root of the test bundle Resources
guard let testDbPath = Bundle(for: type(of: self))
.path(forResource: "test-encrypted-vault", ofType: "txt")
else {
throw NSError(domain: "VaultStoreTests",
code: 1,
userInfo: [NSLocalizedDescriptionKey: "Test database file not found"])
}
return try Data(contentsOf: URL(fileURLWithPath: testDbPath))
return try String(contentsOfFile: testDbPath, encoding: .utf8)
}
}

View File

@@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 60;
objectVersion = 70;
objects = {
/* Begin PBXBuildFile section */
@@ -94,7 +94,7 @@
/* End PBXFileReference section */
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
CE9A5BBB2DBBB60D00CB0A4C /* Exceptions for "Models" folder in "VaultStoreTests" target */ = {
CE9A5BBB2DBBB60D00CB0A4C /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
AuthMethods.swift,
@@ -102,7 +102,7 @@
);
target = CE9A5BAF2DBBB47200CB0A4C /* VaultStoreTests */;
};
CEE9098F2DA548C7008D568F /* Exceptions for "Autofill" folder in "Autofill" target */ = {
CEE9098F2DA548C7008D568F /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
Info.plist,
@@ -112,41 +112,9 @@
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
/* Begin PBXFileSystemSynchronizedRootGroup section */
CE9A5B592DBAE06400CB0A4C /* Models */ = {
isa = PBXFileSystemSynchronizedRootGroup;
exceptions = (
CE9A5BBB2DBBB60D00CB0A4C /* Exceptions for "Models" folder in "VaultStoreTests" target */,
);
explicitFileTypes = {
};
explicitFolders = (
);
path = Models;
sourceTree = "<group>";
};
CE9A5BB12DBBB47200CB0A4C /* VaultStoreTests */ = {
isa = PBXFileSystemSynchronizedRootGroup;
exceptions = (
);
explicitFileTypes = {
};
explicitFolders = (
);
path = VaultStoreTests;
sourceTree = "<group>";
};
CEE909812DA548C7008D568F /* Autofill */ = {
isa = PBXFileSystemSynchronizedRootGroup;
exceptions = (
CEE9098F2DA548C7008D568F /* Exceptions for "Autofill" folder in "Autofill" target */,
);
explicitFileTypes = {
};
explicitFolders = (
);
path = Autofill;
sourceTree = "<group>";
};
CE9A5B592DBAE06400CB0A4C /* Models */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (CE9A5BBB2DBBB60D00CB0A4C /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = Models; sourceTree = "<group>"; };
CE9A5BB12DBBB47200CB0A4C /* VaultStoreTests */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = VaultStoreTests; sourceTree = "<group>"; };
CEE909812DA548C7008D568F /* Autofill */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (CEE9098F2DA548C7008D568F /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = Autofill; sourceTree = "<group>"; };
/* End PBXFileSystemSynchronizedRootGroup section */
/* Begin PBXFrameworksBuildPhase section */
@@ -788,10 +756,7 @@
LIBRARY_SEARCH_PATHS = "$(SDKROOT)/usr/lib/swift\"$(inherited)\"";
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
OTHER_LDFLAGS = "$(inherited) ";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG";
@@ -846,10 +811,7 @@
);
LIBRARY_SEARCH_PATHS = "$(SDKROOT)/usr/lib/swift\"$(inherited)\"";
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
OTHER_LDFLAGS = "$(inherited) ";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;

View File

@@ -134,7 +134,7 @@ public class TestVaultGeneratorTests : BrowserExtensionPlaywrightTest
// Ensure the output directory exists
Directory.CreateDirectory(vaultOutputDir);
var tempVaultPath = Path.Combine(vaultOutputDir, "test-vault.encrypted.blob");
var tempVaultPath = Path.Combine(vaultOutputDir, "test-encrypted-vault.txt");
await File.WriteAllTextAsync(tempVaultPath, vault.VaultBlob);
// Generate the decryption key using the same method as the login page