diff --git a/src/credentials-manager/__tests__/credentials-manager.spec.js b/src/credentials-manager/__tests__/credentials-manager.spec.js index 1ccd0377..c8bb4376 100644 --- a/src/credentials-manager/__tests__/credentials-manager.spec.js +++ b/src/credentials-manager/__tests__/credentials-manager.spec.js @@ -165,24 +165,4 @@ describe('credentials manager tests', () => { newNativeModule.mockRestore(); }); }); - - describe('test enabling local authentication', () => { - it('enable local authentication for iOS', async () => { - Platform.OS = 'ios'; - const newNativeModule = jest - .spyOn(credentialsManager.Auth0Module, 'enableLocalAuthentication') - .mockImplementation(() => {}); - await expect(credentialsManager.requireLocalAuthentication()).resolves; - newNativeModule.mockRestore(); - }); - - it('enable local authentication for Android', async () => { - Platform.OS = 'android'; - const newNativeModule = jest - .spyOn(credentialsManager.Auth0Module, 'enableLocalAuthentication') - .mockImplementation(() => {}); - await expect(credentialsManager.requireLocalAuthentication()).resolves; - newNativeModule.mockRestore(); - }); - }); }); diff --git a/src/hooks/__tests__/use-auth0.spec.jsx b/src/hooks/__tests__/use-auth0.spec.jsx index a3884d2c..e172a934 100644 --- a/src/hooks/__tests__/use-auth0.spec.jsx +++ b/src/hooks/__tests__/use-auth0.spec.jsx @@ -68,7 +68,6 @@ const mockAuth0 = { }, credentialsManager: { getCredentials: jest.fn().mockResolvedValue(mockCredentials), - requireLocalAuthentication: jest.fn().mockResolvedValue(), clearCredentials: jest.fn().mockResolvedValue(), saveCredentials: jest.fn().mockResolvedValue(), hasValidCredentials: jest.fn(), @@ -1051,61 +1050,6 @@ describe('The useAuth0 hook', () => { expect(result.current.error).toEqual(thrownError); }); - it('can require local authentication', async () => { - const { result } = renderHook(() => useAuth0(), { - wrapper, - }); - - await waitFor(() => expect(result.current.isLoading).toBe(false)); - - result.current.requireLocalAuthentication(); - - expect( - mockAuth0.credentialsManager.requireLocalAuthentication - ).toHaveBeenCalled(); - }); - - it('can require local authentication with options', async () => { - const { result } = renderHook(() => useAuth0(), { - wrapper, - }); - - await waitFor(() => expect(result.current.isLoading).toBe(false)); - - result.current.requireLocalAuthentication( - 'title', - 'description', - 'cancel', - 'fallback', - LocalAuthenticationStrategy.deviceOwner - ); - - expect( - mockAuth0.credentialsManager.requireLocalAuthentication - ).toHaveBeenCalledWith( - 'title', - 'description', - 'cancel', - 'fallback', - LocalAuthenticationStrategy.deviceOwner - ); - }); - - it('dispatches an error when requireLocalAuthentication fails', async () => { - const { result } = renderHook(() => useAuth0(), { - wrapper, - }); - const thrownError = new Error('requireLocalAuthentication failed'); - - mockAuth0.credentialsManager.requireLocalAuthentication.mockRejectedValue( - thrownError - ); - - result.current.requireLocalAuthentication(); - await waitFor(() => expect(result.current.isLoading).toBe(false)); - expect(result.current.error).toEqual(thrownError); - }); - it('calls hasValidCredentials with correct parameters', async () => { const { result } = renderHook(() => useAuth0(), { wrapper, diff --git a/src/webauth/__tests__/agent.spec.js b/src/webauth/__tests__/agent.spec.js index a7d2021f..3642beda 100644 --- a/src/webauth/__tests__/agent.spec.js +++ b/src/webauth/__tests__/agent.spec.js @@ -2,6 +2,12 @@ import * as nativeUtils from '../../utils/nativeHelper'; import Agent from '../agent'; import { NativeModules, Platform, Linking } from 'react-native'; +const localAuthenticationOptions = { + title: 'Authenticate With Your Biometrics', + evaluationPolicy: 1, + authenticationLevel: 0, +}; + jest.mock('react-native', () => { // Require the original module to not be mocked... return { @@ -58,9 +64,15 @@ describe('Agent', () => { clientId: clientId, domain: domain, }, - { customScheme: 'test' } + { customScheme: 'test' }, + localAuthenticationOptions + ); + expect(mock).toBeCalledWith( + NativeModules.A0Auth0, + clientId, + domain, + localAuthenticationOptions ); - expect(mock).toBeCalledWith(NativeModules.A0Auth0, clientId, domain); }); it('should ensure login is called with proper parameters', async () => { @@ -91,9 +103,15 @@ describe('Agent', () => { ephemeralSession: true, safariViewControllerPresentationStyle: 0, additionalParameters: { test: 'test' }, - } + }, + localAuthenticationOptions + ); + expect(mock).toBeCalledWith( + NativeModules.A0Auth0, + clientId, + domain, + localAuthenticationOptions ); - expect(mock).toBeCalledWith(NativeModules.A0Auth0, clientId, domain); expect(mockLogin).toBeCalledWith( 'test', 'test://test.com/ios/com.my.app/callback', @@ -128,9 +146,15 @@ describe('Agent', () => { }, { redirectUrl: 'redirect://redirect.com', - } + }, + localAuthenticationOptions + ); + expect(mock).toBeCalledWith( + NativeModules.A0Auth0, + clientId, + domain, + localAuthenticationOptions ); - expect(mock).toBeCalledWith(NativeModules.A0Auth0, clientId, domain); expect(mockLogin).toBeCalledWith( 'com.my.app.auth0', 'redirect://redirect.com', @@ -173,9 +197,15 @@ describe('Agent', () => { clientId: clientId, domain: domain, }, - { customScheme: 'test' } + { customScheme: 'test' }, + localAuthenticationOptions + ); + expect(mock).toBeCalledWith( + NativeModules.A0Auth0, + clientId, + domain, + localAuthenticationOptions ); - expect(mock).toBeCalledWith(NativeModules.A0Auth0, clientId, domain); }); it('should ensure logout is called with proper parameters', async () => { @@ -195,9 +225,15 @@ describe('Agent', () => { { customScheme: 'test', federated: true, - } + }, + localAuthenticationOptions + ); + expect(mock).toBeCalledWith( + NativeModules.A0Auth0, + clientId, + domain, + localAuthenticationOptions ); - expect(mock).toBeCalledWith(NativeModules.A0Auth0, clientId, domain); expect(mockLogin).toBeCalledWith( 'test', true, @@ -221,9 +257,15 @@ describe('Agent', () => { }, { returnToUrl: 'redirect://redirect.com', - } + }, + localAuthenticationOptions + ); + expect(mock).toBeCalledWith( + NativeModules.A0Auth0, + clientId, + domain, + localAuthenticationOptions ); - expect(mock).toBeCalledWith(NativeModules.A0Auth0, clientId, domain); expect(mockLogin).toBeCalledWith( 'com.my.app.auth0', false, diff --git a/src/webauth/__tests__/webauth.spec.js b/src/webauth/__tests__/webauth.spec.js index f2098c0d..45092a45 100644 --- a/src/webauth/__tests__/webauth.spec.js +++ b/src/webauth/__tests__/webauth.spec.js @@ -11,7 +11,12 @@ describe('WebAuth', () => { const domain = 'auth0.com'; const baseUrl = 'https://' + domain; const auth = new Auth({ baseUrl: baseUrl, clientId: clientId }); - const webauth = new WebAuth(auth); + const localAuthenticationOptions = { + title: 'Authenticate With Your Biometrics', + evaluationPolicy: 1, + authenticationLevel: 0, + }; + const webauth = new WebAuth(auth, localAuthenticationOptions); describe('authorize', () => { it('should authorize with provided parameters', async () => { @@ -49,7 +54,12 @@ describe('WebAuth', () => { ).resolves.toMatchSnapshot(); expect(showMock).toHaveBeenCalledWith( { clientId, domain }, - { ...parameters, ...options, safariViewControllerPresentationStyle: -2 } + { + ...parameters, + ...options, + safariViewControllerPresentationStyle: -2, + }, + localAuthenticationOptions ); showMock.mockRestore(); }); @@ -88,7 +98,8 @@ describe('WebAuth', () => { ).resolves.toMatchSnapshot(); expect(showMock).toHaveBeenCalledWith( { clientId, domain }, - { ...parameters, ...options, safariViewControllerPresentationStyle: 0 } + { ...parameters, ...options, safariViewControllerPresentationStyle: 0 }, + localAuthenticationOptions ); showMock.mockRestore(); }); @@ -130,7 +141,8 @@ describe('WebAuth', () => { ...parameters, ...options, safariViewControllerPresentationStyle: undefined, - } + }, + localAuthenticationOptions ); showMock.mockRestore(); }); @@ -173,7 +185,8 @@ describe('WebAuth', () => { ...parameters, ...options, safariViewControllerPresentationStyle: undefined, - } + }, + localAuthenticationOptions ); showMock.mockRestore(); }); @@ -216,7 +229,8 @@ describe('WebAuth', () => { ...parameters, ...options, safariViewControllerPresentationStyle: 0, - } + }, + localAuthenticationOptions ); showMock.mockRestore(); }); @@ -234,10 +248,15 @@ describe('WebAuth', () => { const showMock = jest .spyOn(webauth.agent, 'logout') .mockImplementation(() => Promise.resolve()); - await webauth.clearSession(parameters, options); + await webauth.clearSession( + parameters, + options, + localAuthenticationOptions + ); expect(showMock).toHaveBeenCalledWith( { clientId, domain }, - { ...parameters, ...options } + { ...parameters, ...options }, + localAuthenticationOptions ); showMock.mockRestore(); });