From abd7805dc5c7884095dbe6144689c87e54a8a6fe Mon Sep 17 00:00:00 2001 From: Graeme Arthur <2030310+graeme@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:26:00 +0200 Subject: [PATCH] Add integration test for rules --- DuckDuckGo.xcodeproj/project.pbxproj | 12 ++++++ .../CSVImporterIntegrationTests.swift | 43 ++++++++++++++++++- .../login_deduplication_starting_data.csv | 18 ++++++++ .../login_deduplication_test_data.csv | 18 ++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 IntegrationTests/DataImport/login_deduplication_starting_data.csv create mode 100644 IntegrationTests/DataImport/login_deduplication_test_data.csv diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index 854d1fb271..adb6250714 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -2566,6 +2566,10 @@ EECE10E529DD77E60044D027 /* FeatureFlag.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECE10E429DD77E60044D027 /* FeatureFlag.swift */; }; EECE10E629DD77E60044D027 /* FeatureFlag.swift in Sources */ = {isa = PBXBuildFile; fileRef = EECE10E429DD77E60044D027 /* FeatureFlag.swift */; }; EED735362BB46B6000F173D6 /* AutocompleteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EED735352BB46B6000F173D6 /* AutocompleteTests.swift */; }; + EED9A6752C37FE6900E0FAB9 /* login_deduplication_test_data.csv in Resources */ = {isa = PBXBuildFile; fileRef = EED9A6732C37FE6800E0FAB9 /* login_deduplication_test_data.csv */; }; + EED9A6762C37FE6900E0FAB9 /* login_deduplication_test_data.csv in Resources */ = {isa = PBXBuildFile; fileRef = EED9A6732C37FE6800E0FAB9 /* login_deduplication_test_data.csv */; }; + EED9A6772C37FE6900E0FAB9 /* login_deduplication_starting_data.csv in Resources */ = {isa = PBXBuildFile; fileRef = EED9A6742C37FE6900E0FAB9 /* login_deduplication_starting_data.csv */; }; + EED9A6782C37FE6900E0FAB9 /* login_deduplication_starting_data.csv in Resources */ = {isa = PBXBuildFile; fileRef = EED9A6742C37FE6900E0FAB9 /* login_deduplication_starting_data.csv */; }; EEDE50112BA360C80017F3C4 /* NetworkProtection+VPNAgentConvenienceInitializers.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEDE50102BA360C80017F3C4 /* NetworkProtection+VPNAgentConvenienceInitializers.swift */; }; EEDE50122BA360C80017F3C4 /* NetworkProtection+VPNAgentConvenienceInitializers.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEDE50102BA360C80017F3C4 /* NetworkProtection+VPNAgentConvenienceInitializers.swift */; }; EEE0E1CD2C32F5690058E148 /* CSVImporterIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EEE0E1CC2C32F5690058E148 /* CSVImporterIntegrationTests.swift */; }; @@ -4125,6 +4129,8 @@ EEC7BE2D2BC6C09400F86835 /* AddressBarKeyboardShortcutsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddressBarKeyboardShortcutsTests.swift; sourceTree = ""; }; EECE10E429DD77E60044D027 /* FeatureFlag.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureFlag.swift; sourceTree = ""; }; EED735352BB46B6000F173D6 /* AutocompleteTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutocompleteTests.swift; sourceTree = ""; }; + EED9A6732C37FE6800E0FAB9 /* login_deduplication_test_data.csv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = login_deduplication_test_data.csv; sourceTree = ""; }; + EED9A6742C37FE6900E0FAB9 /* login_deduplication_starting_data.csv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = login_deduplication_starting_data.csv; sourceTree = ""; }; EEDE50102BA360C80017F3C4 /* NetworkProtection+VPNAgentConvenienceInitializers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NetworkProtection+VPNAgentConvenienceInitializers.swift"; sourceTree = ""; }; EEE0E1CC2C32F5690058E148 /* CSVImporterIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSVImporterIntegrationTests.swift; sourceTree = ""; }; EEE0E1CE2C32F6530058E148 /* mock_login_data_large.csv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = mock_login_data_large.csv; sourceTree = ""; }; @@ -8282,6 +8288,8 @@ EEE0E1CB2C32F53C0058E148 /* DataImport */ = { isa = PBXGroup; children = ( + EED9A6742C37FE6900E0FAB9 /* login_deduplication_starting_data.csv */, + EED9A6732C37FE6800E0FAB9 /* login_deduplication_test_data.csv */, EEE0E1CE2C32F6530058E148 /* mock_login_data_large.csv */, EEE0E1CC2C32F5690058E148 /* CSVImporterIntegrationTests.swift */, ); @@ -9058,8 +9066,10 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + EED9A6782C37FE6900E0FAB9 /* login_deduplication_starting_data.csv in Resources */, EEE0E1D02C32F6530058E148 /* mock_login_data_large.csv in Resources */, B64E42AC2B909DC9006C1346 /* test.pdf in Resources */, + EED9A6762C37FE6900E0FAB9 /* login_deduplication_test_data.csv in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -9074,8 +9084,10 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + EED9A6772C37FE6900E0FAB9 /* login_deduplication_starting_data.csv in Resources */, EEE0E1CF2C32F6530058E148 /* mock_login_data_large.csv in Resources */, B64E42AB2B909DC9006C1346 /* test.pdf in Resources */, + EED9A6752C37FE6900E0FAB9 /* login_deduplication_test_data.csv in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/IntegrationTests/DataImport/CSVImporterIntegrationTests.swift b/IntegrationTests/DataImport/CSVImporterIntegrationTests.swift index 00f9097e6e..4262af0a47 100644 --- a/IntegrationTests/DataImport/CSVImporterIntegrationTests.swift +++ b/IntegrationTests/DataImport/CSVImporterIntegrationTests.swift @@ -19,14 +19,32 @@ import Foundation import XCTest @testable import DuckDuckGo_Privacy_Browser +import BrowserServicesKit final class CSVImporterIntegrationTests: XCTestCase { - override func setUp() { + override func setUpWithError() throws { super.setUp() + try clearDB() executionTimeAllowance = 10 } + override func tearDownWithError() throws { + try clearDB() + super.tearDown() + } + + func clearDB() throws { + let vault = try AutofillSecureVaultFactory.makeVault(reporter: SecureVaultReporter.shared) + + let accounts = try vault.accounts() + for accountID in accounts.compactMap(\.id) { + if let accountID = Int64(accountID) { + try vault.deleteWebsiteCredentialsFor(accountId: accountID) + } + } + } + func testImportPasswordsPerformance() async throws { let csvURL = Bundle(for: Self.self).url(forResource: "mock_login_data_large", withExtension: "csv")! let csvImporter = CSVImporter( @@ -49,4 +67,27 @@ final class CSVImporterIntegrationTests: XCTestCase { wait(for: [expectation]) } } + + // Deduplication rules: https://app.asana.com/0/0/1207598052765977/f + func testImportingPasswords_deduplicatesAccordingToDefinedRules() async throws { + let startingDataURL = Bundle(for: Self.self).url(forResource: "login_deduplication_starting_data", withExtension: "csv")! + let startingDataImporter = CSVImporter( + fileURL: startingDataURL, + loginImporter: SecureVaultLoginImporter(), + defaultColumnPositions: nil + ) + _ = await startingDataImporter.importData(types: [.passwords]).result + + let testDataURL = Bundle(for: Self.self).url(forResource: "login_deduplication_test_data", withExtension: "csv")! + let testDataImporter = CSVImporter( + fileURL: testDataURL, + loginImporter: SecureVaultLoginImporter(), + defaultColumnPositions: nil + ) + let importTask = testDataImporter.importData(types: [.passwords]) + let result = await importTask.result + let summary = try result.get()[.passwords]?.get() + + XCTAssertEqual(summary?.duplicate, 4) + } } diff --git a/IntegrationTests/DataImport/login_deduplication_starting_data.csv b/IntegrationTests/DataImport/login_deduplication_starting_data.csv new file mode 100644 index 0000000000..5387e2626f --- /dev/null +++ b/IntegrationTests/DataImport/login_deduplication_starting_data.csv @@ -0,0 +1,18 @@ +title,username,password,url,notes +Strict duplicate,isillitoe0,iL8>{M(t,http://lycos.com,"Quisque porta volutpat erat. Quisque erat eros, viverra eget, congue eget, semper rutrum, nulla. Nunc purus. Phasellus in felis. Donec semper sapien a libero. Nam dui. Proin leo odio, porttitor id, consequat in, consequat ut, nulla. Sed accumsan felis." +Strict antithesis,aschermick1,"hS0#,JU>",https://icio.us,"Donec ut dolor. Morbi vel lectus in quam fringilla rhoncus. Mauris enim leo, rhoncus sed, vestibulum sit amet, cursus id, turpis." +Differing usernames,karran3,rP9*0X%Xj0sD,https://gov.uk,Nil imported title \ No newline at end of file diff --git a/IntegrationTests/DataImport/login_deduplication_test_data.csv b/IntegrationTests/DataImport/login_deduplication_test_data.csv new file mode 100644 index 0000000000..1a11e27794 --- /dev/null +++ b/IntegrationTests/DataImport/login_deduplication_test_data.csv @@ -0,0 +1,18 @@ +title,username,password,url,notes,,,, +Strict duplicate,isillitoe0,iL8>{M(t,http://lycos.com,"Quisque porta volutpat erat. Quisque erat eros, viverra eget, congue eget, semper rutrum, nulla. Nunc purus. Phasellus in felis. Donec semper sapien a libero. Nam dui. Proin leo odio, porttitor id, consequat in, consequat ut, nulla. Sed accumsan felis.",,,, +Complete antithesis,abrimbleh,iU3*~0DzuU9>0sD,https://icio.us,"Quisque erat eros, viverra eget, congue eget, semper rutrum, nulla. Nunc purus. Phasellus in felis. Donec semper sapien a libero. Nam dui. Proin leo odio, porttitor id, consequat in, consequat ut, nulla. Sed accumsan felis. Ut at dolor quis odio consequat varius. Integer ac leo. Pellentesque ultrices mattis odio.Hatity",caizic2,yN1{Yv%nkJ=,http://aboutads.info/diam/nam/tristique/tortor.png?ac=sapien&nulla=a,"Duis consequat dui nec nisi volutpat eleifend. Donec ut dolor. Morbi vel lectus in quam fringilla rhoncus. Mauris enim leo, rhoncus sed, vestibulum sit amet, cursus id, turpis. Integer aliquet, massa id lobortis convallis, tortor risus dapibus augue, vel accumsan tellus nisi eu orci. Mauris lacinia sapien quis libero. Nullam sit amet turpis elementum ligula vehicula consequat." +Differing usernames,wblindmann1,rP9*0X%Xj0sD,https://gov.uk,Nil imported title,,,, \ No newline at end of file