Skip to content

Commit a610d90

Browse files
committed
fix: add mock for MZKeychainWrapper
1 parent dbe8916 commit a610d90

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

firefox-ios/Client.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,7 @@
12561256
B2FEA68F2B460D9E0058E616 /* AddressAutofillSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2FEA68E2B460D9E0058E616 /* AddressAutofillSettingsViewModel.swift */; };
12571257
B2FEA6912B4661BE0058E616 /* AddressAutofillToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2FEA6902B4661BE0058E616 /* AddressAutofillToggle.swift */; };
12581258
B640467E29B9B58200C5C7B6 /* TabLocationViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B640467D29B9B58200C5C7B6 /* TabLocationViewTests.swift */; };
1259+
BA03AE592D41715900C7FA7B /* MockMZKeychainWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA03AE582D41714B00C7FA7B /* MockMZKeychainWrapper.swift */; };
12591260
BA1C68BA2B7E9EA0000D9397 /* WKFrameInfoExtensionsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA1C68B92B7E9EA0000D9397 /* WKFrameInfoExtensionsTest.swift */; };
12601261
BA1C68BC2B7ED153000D9397 /* MockWebKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA1C68BB2B7ED153000D9397 /* MockWebKit.swift */; };
12611262
BA7A14842C2CCEB3008DF1D9 /* EditAddressWebViewManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA7A14832C2CCEB3008DF1D9 /* EditAddressWebViewManager.swift */; };
@@ -8443,6 +8444,7 @@
84438444
B9CF4F8ABA948EB090A67608 /* cs */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = cs; path = cs.lproj/ClearPrivateDataConfirm.strings; sourceTree = "<group>"; };
84448445
B9D74DA988462CC14EF29D8B /* fil */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fil; path = fil.lproj/Menu.strings; sourceTree = "<group>"; };
84458446
B9F246E38F80F257C59CEC4A /* ast */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ast; path = ast.lproj/HistoryPanel.strings; sourceTree = "<group>"; };
8447+
BA03AE582D41714B00C7FA7B /* MockMZKeychainWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockMZKeychainWrapper.swift; sourceTree = "<group>"; };
84468448
BA05405089CFDC6097258640 /* en-CA */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "en-CA"; path = "en-CA.lproj/3DTouchActions.strings"; sourceTree = "<group>"; };
84478449
BA1C68B92B7E9EA0000D9397 /* WKFrameInfoExtensionsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKFrameInfoExtensionsTest.swift; sourceTree = "<group>"; };
84488450
BA1C68BB2B7ED153000D9397 /* MockWebKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockWebKit.swift; sourceTree = "<group>"; };
@@ -10643,6 +10645,7 @@
1064310645
2FCAE21B1ABB51F800877008 /* Storage */ = {
1064410646
isa = PBXGroup;
1064510647
children = (
10648+
BA03AE582D41714B00C7FA7B /* MockMZKeychainWrapper.swift */,
1064610649
D37DE2821CA2047500A5EC69 /* CertStore.swift */,
1064710650
28C4AB711AD42D4300D9ACE3 /* Clients.swift */,
1064810651
2FCAE2411ABB531100877008 /* Cursor.swift */,
@@ -16023,6 +16026,7 @@
1602316026
B2999FED2B044A5900F0FEC1 /* UnencryptedCreditCardFields.swift in Sources */,
1602416027
15DE98FD27FCED4F00F1ECDB /* RustRemoteTabs.swift in Sources */,
1602516028
285D3B901B4386520035FD22 /* SQLiteQueue.swift in Sources */,
16029+
BA03AE592D41715900C7FA7B /* MockMZKeychainWrapper.swift in Sources */,
1602616030
394CF6CF1BAA493C00906917 /* DefaultSuggestedSites.swift in Sources */,
1602716031
B2999FEF2B044B4E00F0FEC1 /* RustAutofillEncryptionKeys.swift in Sources */,
1602816032
2FCAE2781ABB531100877008 /* Visit.swift in Sources */,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/
4+
5+
import class MozillaAppServices.MZKeychainWrapper
6+
import enum MozillaAppServices.MZKeychainItemAccessibility
7+
8+
class MockMZKeychainWrapper: MZKeychainWrapper {
9+
static let shared = MockMZKeychainWrapper()
10+
11+
private var storage: [String: Data] = [:]
12+
13+
private init() {
14+
super.init(serviceName: "Test")
15+
}
16+
17+
override func set(_ value: Data, forKey key: String, withAccessibility accessibility: MZKeychainItemAccessibility? = nil,
18+
isSynchronizable: Bool = false) -> Bool {
19+
storage[key] = value
20+
return true
21+
}
22+
23+
override func string(forKey key: String, withAccessibility accessibility: MZKeychainItemAccessibility? = nil,
24+
isSynchronizable: Bool = false) -> String? {
25+
guard let data = storage[key] else { return nil }
26+
return String(data: data, encoding: .utf8)
27+
}
28+
29+
override func data(forKey key: String, withAccessibility accessibility: MZKeychainItemAccessibility? = nil,
30+
isSynchronizable: Bool = false) -> Data? {
31+
return storage[key]
32+
}
33+
}

firefox-ios/Storage/Rust/RustLogins.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,21 @@ public enum LoginEncryptionKeyError: Error {
205205
case dbRecordCountVerificationError(String)
206206
}
207207

208+
/// Running tests on Bitrise code that reads/writes to keychain silently fails.
209+
/// SecItemAdd status: -34018 - A required entitlement isn't present.
210+
/// This should be removed if we ever have keychain support on our CI.
211+
class KeychainManager {
212+
static var shared: MZKeychainWrapper = {
213+
AppConstants.isRunningTest
214+
? MockMZKeychainWrapper.shared
215+
: MZKeychainWrapper.sharedClientAppContainerKeychain
216+
}()
217+
}
218+
208219
public class RustLoginEncryptionKeys {
209220
public let loginPerFieldKeychainKey = "appservices.key.logins.perfield"
210221

211-
let keychain = MZKeychainWrapper.sharedClientAppContainerKeychain
222+
let keychain = KeychainManager.shared
212223
let canaryPhraseKey = "canaryPhrase"
213224
let canaryPhrase = "a string for checking validity of the key"
214225

0 commit comments

Comments
 (0)