11import { by , device , element , expect , waitFor } from 'detox' ;
22import { matchLoadInfo } from '../utils/matchLoadInfo' ;
3- import cp from 'child_process' ;
3+ import {
4+ waitForAuthValidity ,
5+ enterBiometrics ,
6+ enterPasscode ,
7+ } from '../utils/authHelpers' ;
48
59describe ( 'Access Control' , ( ) => {
610 beforeEach ( async ( ) => {
711 await device . launchApp ( { newInstance : true } ) ;
812 } ) ;
913 [ 'genericPassword' , 'internetCredentials' ] . forEach ( ( type ) => {
14+ it (
15+ ':android:should save and retrieve username and password with passcode - ' +
16+ type ,
17+ async ( ) => {
18+ await expect ( element ( by . text ( 'Keychain Example' ) ) ) . toExist ( ) ;
19+ await element ( by . id ( 'usernameInput' ) ) . typeText ( 'testUsernamePasscode' ) ;
20+ await element ( by . id ( 'passwordInput' ) ) . typeText ( 'testPasswordPasscode' ) ;
21+ // Hide keyboard
22+ await element ( by . text ( 'Keychain Example' ) ) . tap ( ) ;
23+ await element ( by . text ( 'Passcode' ) ) . tap ( ) ;
24+
25+ await expect ( element ( by . text ( 'Save' ) ) ) . toBeVisible ( ) ;
26+
27+ await element ( by . text ( 'Save' ) ) . tap ( ) ;
28+ await enterPasscode ( ) ;
29+ // Hide keyboard if open
30+ await element ( by . text ( 'Keychain Example' ) ) . tap ( ) ;
31+ await waitFor ( element ( by . text ( / ^ C r e d e n t i a l s s a v e d ! .* $ / ) ) )
32+ . toExist ( )
33+ . withTimeout ( 4000 ) ;
34+
35+ await waitForAuthValidity ( ) ;
36+ await element ( by . text ( 'Load' ) ) . tap ( ) ;
37+ await enterPasscode ( ) ;
38+ // Hide keyboard if open
39+ await element ( by . text ( 'Keychain Example' ) ) . tap ( ) ;
40+ await matchLoadInfo (
41+ 'testUsernamePasscode' ,
42+ 'testPasswordPasscode' ,
43+ 'KeystoreAESGCM'
44+ ) ;
45+ }
46+ ) ;
1047 it (
1148 ' should save and retrieve username and password with biometrics - ' +
1249 type ,
@@ -29,23 +66,17 @@ describe('Access Control', () => {
2966 }
3067
3168 await expect ( element ( by . text ( 'Save' ) ) ) . toBeVisible ( ) ;
32- if ( device . getPlatform ( ) === 'android' ) {
33- setTimeout ( ( ) => {
34- cp . spawnSync ( 'adb' , [ '-e' , 'emu' , 'finger' , 'touch' , '1' ] ) ;
35- } , 1000 ) ;
36- }
3769 await element ( by . text ( 'Save' ) ) . tap ( ) ;
70+ await enterBiometrics ( ) ;
71+
3872 await waitFor ( element ( by . text ( / ^ C r e d e n t i a l s s a v e d ! .* $ / ) ) )
3973 . toExist ( )
4074 . withTimeout ( 3000 ) ;
41- // Biometric prompt is not available in the IOS simulator
42- // https://github.com/oblador/react-native-keychain/issues/340
43- if ( device . getPlatform ( ) === 'android' ) {
44- setTimeout ( ( ) => {
45- cp . spawnSync ( 'adb' , [ '-e' , 'emu' , 'finger' , 'touch' , '1' ] ) ;
46- } , 1000 ) ;
47- }
75+
76+ await waitForAuthValidity ( ) ;
4877 await element ( by . text ( 'Load' ) ) . tap ( ) ;
78+ await enterBiometrics ( ) ;
79+
4980 await matchLoadInfo ( 'testUsernameBiometrics' , 'testPasswordBiometrics' ) ;
5081 }
5182 ) ;
@@ -58,57 +89,12 @@ describe('Access Control', () => {
5889 await expect (
5990 element ( by . text ( 'hasGenericPassword: true' ) )
6091 ) . toBeVisible ( ) ;
61- // Biometric prompt is not available in the IOS simulator
62- // https://github.com/oblador/react-native-keychain/issues/340
63- if ( device . getPlatform ( ) === 'android' ) {
64- setTimeout ( ( ) => {
65- cp . spawnSync ( 'adb' , [ '-e' , 'emu' , 'finger' , 'touch' , '1' ] ) ;
66- } , 1000 ) ;
67- }
6892 await element ( by . text ( 'Load' ) ) . tap ( ) ;
93+ await enterBiometrics ( ) ;
6994 await matchLoadInfo ( 'testUsernameBiometrics' , 'testPasswordBiometrics' ) ;
7095 }
7196 ) ;
7297
73- it (
74- ':android:should save and retrieve username and password with passcode - ' +
75- type ,
76- async ( ) => {
77- await expect ( element ( by . text ( 'Keychain Example' ) ) ) . toExist ( ) ;
78- await element ( by . id ( 'usernameInput' ) ) . typeText ( 'testUsernamePasscode' ) ;
79- await element ( by . id ( 'passwordInput' ) ) . typeText ( 'testPasswordPasscode' ) ;
80- // Hide keyboard
81- await element ( by . text ( 'Keychain Example' ) ) . tap ( ) ;
82- await element ( by . text ( 'Passcode' ) ) . tap ( ) ;
83-
84- await expect ( element ( by . text ( 'Save' ) ) ) . toBeVisible ( ) ;
85- setTimeout ( ( ) => {
86- cp . spawnSync ( 'adb' , [ 'shell' , 'input' , 'text' , '1111' ] ) ;
87- } , 1500 ) ;
88- setTimeout ( ( ) => {
89- cp . spawnSync ( 'adb' , [ 'shell' , 'input' , 'keyevent' , '66' ] ) ;
90- } , 3500 ) ;
91- await element ( by . text ( 'Save' ) ) . tap ( ) ;
92- await waitFor ( element ( by . text ( / ^ C r e d e n t i a l s s a v e d ! .* $ / ) ) )
93- . toExist ( )
94- . withTimeout ( 4000 ) ;
95-
96- setTimeout ( ( ) => {
97- cp . spawnSync ( 'adb' , [ 'shell' , 'input' , 'text' , '1111' ] ) ;
98- } , 1500 ) ;
99- setTimeout ( ( ) => {
100- cp . spawnSync ( 'adb' , [ 'shell' , 'input' , 'keyevent' , '66' ] ) ;
101- } , 3000 ) ;
102-
103- await element ( by . text ( 'Load' ) ) . tap ( ) ;
104- await matchLoadInfo (
105- 'testUsernamePasscode' ,
106- 'testPasswordPasscode' ,
107- 'KeystoreAESGCM'
108- ) ;
109- }
110- ) ;
111-
11298 it (
11399 'should save and retrieve username and password without biometrics - ' +
114100 type ,
0 commit comments