|
| 1 | +const mockKeychainPasswords = {}; |
| 2 | + |
| 3 | +const getGenericPassword = jest.fn(({ service }) => { |
| 4 | + return { password: mockKeychainPasswords[service] }; |
| 5 | +}); |
| 6 | + |
| 7 | +const setGenericPassword = jest.fn((key, value) => { |
| 8 | + mockKeychainPasswords[key] = value; |
| 9 | +}); |
| 10 | + |
| 11 | +const keychainMock = { |
| 12 | + SECURITY_LEVEL: { |
| 13 | + SECURE_SOFTWARE: 'MOCK_SECURITY_LEVEL_SECURE_SOFTWARE', |
| 14 | + SECURE_HARDWARE: 'MOCK_SECURITY_LEVEL_SECURE_HARDWARE', |
| 15 | + ANY: 'MOCK_SECURITY_LEVEL_ANY', |
| 16 | + }, |
| 17 | + ACCESSIBLE: { |
| 18 | + WHEN_UNLOCKED: 'MOCK_AccessibleWhenUnlocked', |
| 19 | + AFTER_FIRST_UNLOCK: 'MOCK_AccessibleAfterFirstUnlock', |
| 20 | + ALWAYS: 'MOCK_AccessibleAlways', |
| 21 | + WHEN_PASSCODE_SET_THIS_DEVICE_ONLY: |
| 22 | + 'MOCK_AccessibleWhenPasscodeSetThisDeviceOnly', |
| 23 | + WHEN_UNLOCKED_THIS_DEVICE_ONLY: 'MOCK_AccessibleWhenUnlockedThisDeviceOnly', |
| 24 | + AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY: |
| 25 | + 'MOCK_AccessibleAfterFirstUnlockThisDeviceOnly', |
| 26 | + }, |
| 27 | + ACCESS_CONTROL: { |
| 28 | + USER_PRESENCE: 'MOCK_UserPresence', |
| 29 | + BIOMETRY_ANY: 'MOCK_BiometryAny', |
| 30 | + BIOMETRY_CURRENT_SET: 'MOCK_BiometryCurrentSet', |
| 31 | + DEVICE_PASSCODE: 'MOCK_DevicePasscode', |
| 32 | + APPLICATION_PASSWORD: 'MOCK_ApplicationPassword', |
| 33 | + BIOMETRY_ANY_OR_DEVICE_PASSCODE: 'MOCK_BiometryAnyOrDevicePasscode', |
| 34 | + BIOMETRY_CURRENT_SET_OR_DEVICE_PASSCODE: |
| 35 | + 'MOCK_BiometryCurrentSetOrDevicePasscode', |
| 36 | + }, |
| 37 | + AUTHENTICATION_TYPE: { |
| 38 | + DEVICE_PASSCODE_OR_BIOMETRICS: |
| 39 | + 'MOCK_AuthenticationWithBiometricsDevicePasscode', |
| 40 | + BIOMETRICS: 'MOCK_AuthenticationWithBiometrics', |
| 41 | + }, |
| 42 | + STORAGE_TYPE: { |
| 43 | + FB: 'MOCK_FacebookConceal', |
| 44 | + AES: 'MOCK_KeystoreAESCBC', |
| 45 | + RSA: 'MOCK_KeystoreRSAECB', |
| 46 | + KC: 'MOCK_keychain', |
| 47 | + }, |
| 48 | + getGenericPassword, |
| 49 | + setGenericPassword, |
| 50 | + resetGenericPassword: jest.fn().mockResolvedValue(true), |
| 51 | + hasGenericPassword: jest.fn().mockResolvedValue(true), |
| 52 | + getAllGenericPasswordServices: jest |
| 53 | + .fn() |
| 54 | + .mockResolvedValue(['mockService1', 'mockService2']), |
| 55 | + setInternetCredentials: jest.fn().mockResolvedValue({ |
| 56 | + service: 'mockService', |
| 57 | + storage: 'mockStorage', |
| 58 | + }), |
| 59 | + getInternetCredentials: jest.fn().mockResolvedValue({ |
| 60 | + username: 'mockUser', |
| 61 | + password: 'mockPassword', |
| 62 | + service: 'mockService', |
| 63 | + storage: 'mockStorage', |
| 64 | + }), |
| 65 | + resetInternetCredentials: jest.fn().mockResolvedValue(true), |
| 66 | + getSupportedBiometryType: jest.fn().mockResolvedValue('MOCK_TouchID'), |
| 67 | + canImplyAuthentication: jest.fn().mockResolvedValue(true), |
| 68 | + getSecurityLevel: jest.fn().mockResolvedValue('MOCK_SECURE_SOFTWARE'), |
| 69 | +}; |
| 70 | + |
| 71 | +export default keychainMock; |
0 commit comments