1
1
import { by , device , element , expect , waitFor } from 'detox' ;
2
2
import { matchLoadInfo } from '../utils/matchLoadInfo' ;
3
- import cp from 'child_process' ;
3
+ import {
4
+ waitForAuthValidity ,
5
+ enterBiometrics ,
6
+ enterPasscode ,
7
+ } from '../utils/authHelpers' ;
4
8
5
9
describe ( 'Access Control' , ( ) => {
6
10
beforeEach ( async ( ) => {
7
11
await device . launchApp ( { newInstance : true } ) ;
8
12
} ) ;
9
13
[ '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
+ ) ;
10
47
it (
11
48
' should save and retrieve username and password with biometrics - ' +
12
49
type ,
@@ -29,23 +66,17 @@ describe('Access Control', () => {
29
66
}
30
67
31
68
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
- }
37
69
await element ( by . text ( 'Save' ) ) . tap ( ) ;
70
+ await enterBiometrics ( ) ;
71
+
38
72
await waitFor ( element ( by . text ( / ^ C r e d e n t i a l s s a v e d ! .* $ / ) ) )
39
73
. toExist ( )
40
74
. 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 ( ) ;
48
77
await element ( by . text ( 'Load' ) ) . tap ( ) ;
78
+ await enterBiometrics ( ) ;
79
+
49
80
await matchLoadInfo ( 'testUsernameBiometrics' , 'testPasswordBiometrics' ) ;
50
81
}
51
82
) ;
@@ -58,57 +89,12 @@ describe('Access Control', () => {
58
89
await expect (
59
90
element ( by . text ( 'hasGenericPassword: true' ) )
60
91
) . 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
- }
68
92
await element ( by . text ( 'Load' ) ) . tap ( ) ;
93
+ await enterBiometrics ( ) ;
69
94
await matchLoadInfo ( 'testUsernameBiometrics' , 'testPasswordBiometrics' ) ;
70
95
}
71
96
) ;
72
97
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
-
112
98
it (
113
99
'should save and retrieve username and password without biometrics - ' +
114
100
type ,
0 commit comments