16
16
*/
17
17
18
18
// eslint-disable-next-line import/no-extraneous-dependencies
19
- import { OperationType , UserCredential , User , OAuthCredential } from '@firebase/auth-exp' ;
19
+ import {
20
+ OperationType ,
21
+ UserCredential ,
22
+ User ,
23
+ OAuthCredential
24
+ } from '@firebase/auth-exp' ;
20
25
import { expect , use } from 'chai' ;
21
26
import { IdPPage } from './util/idp_page' ;
22
27
import * as chaiAsPromised from 'chai-as-promised' ;
@@ -56,10 +61,11 @@ browserDescribe('WebDriver redirect IdP test', driver => {
56
61
expect ( redirectResult . user ) . to . eql ( currentUser ) ;
57
62
} ) ;
58
63
59
-
60
64
it ( 'can link with another account account' , async ( ) => {
61
65
// First, sign in anonymously
62
- const { user : anonUser } : UserCredential = await driver . call ( AnonFunction . SIGN_IN_ANONYMOUSLY ) ;
66
+ const { user : anonUser } : UserCredential = await driver . call (
67
+ AnonFunction . SIGN_IN_ANONYMOUSLY
68
+ ) ;
63
69
64
70
// Then, link with redirect
65
71
driver . callNoWait ( RedirectFunction . IDP_LINK_REDIRECT ) ;
@@ -89,14 +95,18 @@ browserDescribe('WebDriver redirect IdP test', driver => {
89
95
// Generate a credential, then store it on the window before logging out
90
96
await driver . reinitOnRedirect ( ) ;
91
97
const first = await driver . getUserSnapshot ( ) ;
92
- const cred : OAuthCredential = await driver . call ( RedirectFunction . GENERATE_CREDENTIAL_FROM_RESULT ) ;
98
+ const cred : OAuthCredential = await driver . call (
99
+ RedirectFunction . GENERATE_CREDENTIAL_FROM_RESULT
100
+ ) ;
93
101
expect ( cred . accessToken ) . to . be . a ( 'string' ) ;
94
102
expect ( cred . idToken ) . to . be . a ( 'string' ) ;
95
103
expect ( cred . signInMethod ) . to . eq ( 'google.com' ) ;
96
104
97
105
// We've now generated that credential. Sign out and sign back in using it
98
106
await driver . call ( CoreFunction . SIGN_OUT ) ;
99
- const { user : second } : UserCredential = await driver . call ( RedirectFunction . SIGN_IN_WITH_REDIRECT_CREDENTIAL ) ;
107
+ const { user : second } : UserCredential = await driver . call (
108
+ RedirectFunction . SIGN_IN_WITH_REDIRECT_CREDENTIAL
109
+ ) ;
100
110
expect ( second . uid ) . to . eq ( first . uid ) ;
101
111
expect ( second . providerData ) . to . eql ( first . providerData ) ;
102
112
} ) ;
@@ -117,15 +127,23 @@ browserDescribe('WebDriver redirect IdP test', driver => {
117
127
// Try to sign in with an unverified Facebook account
118
128
// TODO: Convert this to the widget once unverified accounts work
119
129
// Come back and verify error / prepare for link
120
- await expect ( driver . call ( RedirectFunction . TRY_TO_SIGN_IN_UNVERIFIED , '"[email protected] "' ) ) . to . be . rejected . and . eventually . have . property ( 'code' , 'auth/account-exists-with-different-credential' ) ;
121
-
130
+ await expect (
131
+ driver . call ( RedirectFunction . TRY_TO_SIGN_IN_UNVERIFIED , '"[email protected] "' )
132
+ ) . to . be . rejected . and . eventually . have . property (
133
+ 'code' ,
134
+ 'auth/account-exists-with-different-credential'
135
+ ) ;
136
+
122
137
// Now do the link
123
138
await driver . call ( RedirectFunction . LINK_WITH_ERROR_CREDENTIAL ) ;
124
-
139
+
125
140
// Check the user for both providers
126
141
const user = await driver . getUserSnapshot ( ) ;
127
142
expect ( user . uid ) . to . eq ( original . uid ) ;
128
- expect ( user . providerData . map ( d => d . providerId ) ) . to . have . members ( [ 'google.com' , 'facebook.com' ] ) ;
143
+ expect ( user . providerData . map ( d => d . providerId ) ) . to . have . members ( [
144
+ 'google.com' ,
145
+ 'facebook.com'
146
+ ] ) ;
129
147
} ) ;
130
148
131
149
context ( 'with existing user' , ( ) => {
@@ -134,17 +152,23 @@ browserDescribe('WebDriver redirect IdP test', driver => {
134
152
135
153
beforeEach ( async ( ) => {
136
154
// Create a couple existing users
137
- let cred :
UserCredential = await driver . call ( RedirectFunction . CREATE_FAKE_GOOGLE_USER , '"[email protected] "' ) ;
155
+ let cred : UserCredential = await driver . call (
156
+ RedirectFunction . CREATE_FAKE_GOOGLE_USER ,
157
+
158
+ ) ;
138
159
user1 = cred . user ;
139
- cred = await driver . call ( RedirectFunction . CREATE_FAKE_GOOGLE_USER , '"[email protected] "' ) ;
160
+ cred = await driver . call (
161
+ RedirectFunction . CREATE_FAKE_GOOGLE_USER ,
162
+
163
+ ) ;
140
164
user2 = cred . user ;
141
165
await driver . call ( CoreFunction . SIGN_OUT ) ;
142
166
} ) ;
143
167
144
168
it ( 'a user can sign in again' , async ( ) => {
145
169
// Sign in using pre-poulated user
146
170
await driver . callNoWait ( RedirectFunction . IDP_REDIRECT ) ;
147
-
171
+
148
172
// This time, select an existing account
149
173
const widget = new IdPPage ( driver . webDriver ) ;
150
174
await widget . pageLoad ( ) ;
@@ -157,7 +181,7 @@ browserDescribe('WebDriver redirect IdP test', driver => {
157
181
expect ( user . email ) . to . eq ( user1 . email ) ;
158
182
} ) ;
159
183
160
- it ( 'reauthenticate works for the correct user' , async ( ) => {
184
+ it ( 'reauthenticate works for the correct user' , async ( ) => {
161
185
// Sign in using pre-poulated user
162
186
await driver . callNoWait ( RedirectFunction . IDP_REDIRECT ) ;
163
187
@@ -176,12 +200,12 @@ browserDescribe('WebDriver redirect IdP test', driver => {
176
200
await widget . pageLoad ( ) ;
177
201
await widget . selectExistingAccountByEmail ( user1 . email ! ) ;
178
202
179
- await driver . reinitOnRedirect ( ) ;
203
+ await driver . reinitOnRedirect ( ) ;
180
204
user = await driver . getUserSnapshot ( ) ;
181
205
expect ( user . uid ) . to . eq ( user1 . uid ) ;
182
206
expect ( user . email ) . to . eq ( user1 . email ) ;
183
- } )
184
-
207
+ } ) ;
208
+
185
209
it ( 'reauthenticate throws for wrong user' , async ( ) => {
186
210
// Sign in using pre-poulated user
187
211
await driver . callNoWait ( RedirectFunction . IDP_REDIRECT ) ;
@@ -195,15 +219,20 @@ browserDescribe('WebDriver redirect IdP test', driver => {
195
219
await driver . callNoWait ( RedirectFunction . IDP_REAUTH_REDIRECT ) ;
196
220
await widget . pageLoad ( ) ;
197
221
await widget . selectExistingAccountByEmail ( user2 . email ! ) ;
198
-
222
+
199
223
await driver . reinitOnRedirect ( ) ;
200
- await expect ( driver . call ( RedirectFunction . REDIRECT_RESULT ) ) . to . be . rejected . and . eventually . have . property ( 'code' , 'auth/user-mismatch' ) ;
224
+ await expect (
225
+ driver . call ( RedirectFunction . REDIRECT_RESULT )
226
+ ) . to . be . rejected . and . eventually . have . property (
227
+ 'code' ,
228
+ 'auth/user-mismatch'
229
+ ) ;
201
230
} ) ;
202
231
203
232
it ( 'handles aborted sign ins' , async ( ) => {
204
233
await driver . callNoWait ( RedirectFunction . IDP_REDIRECT ) ;
205
234
const widget = new IdPPage ( driver . webDriver ) ;
206
-
235
+
207
236
// Don't actually sign in; go back to the previous page
208
237
await widget . pageLoad ( ) ;
209
238
await driver . goToTestPage ( ) ;
0 commit comments