@@ -26,7 +26,12 @@ import { expect, use } from 'chai';
26
26
import { IdPPage } from './util/idp_page' ;
27
27
import * as chaiAsPromised from 'chai-as-promised' ;
28
28
import { browserDescribe } from './util/test_runner' ;
29
- import { AnonFunction , CoreFunction , PopupFunction } from './util/functions' ;
29
+ import {
30
+ AnonFunction ,
31
+ CoreFunction ,
32
+ EmailFunction ,
33
+ PopupFunction
34
+ } from './util/functions' ;
30
35
31
36
use ( chaiAsPromised ) ;
32
37
@@ -146,6 +151,89 @@ browserDescribe('Popup IdP tests', driver => {
146
151
] ) ;
147
152
} ) ;
148
153
154
+ it ( 'does not auto-upgrade anon accounts' , async ( ) => {
155
+ const { user : anonUser } : UserCredential = await driver . call (
156
+ AnonFunction . SIGN_IN_ANONYMOUSLY
157
+ ) ;
158
+ await driver . callNoWait ( PopupFunction . IDP_POPUP ) ;
159
+ await driver . selectPopupWindow ( ) ;
160
+ const widget = new IdPPage ( driver . webDriver ) ;
161
+ await widget . pageLoad ( ) ;
162
+ await widget . clickAddAccount ( ) ;
163
+ await widget . fillEmail ( '[email protected] ' ) ;
164
+ await widget . clickSignIn ( ) ;
165
+
166
+ // On redirect, check that the signed in user is different
167
+ await driver . selectMainWindow ( ) ;
168
+ const curUser = await driver . getUserSnapshot ( ) ;
169
+ expect ( curUser . uid ) . not . to . eq ( anonUser . uid ) ;
170
+ } ) ;
171
+
172
+ it ( 'linking with anonymous user upgrades account' , async ( ) => {
173
+ const { user : anonUser } : UserCredential = await driver . call (
174
+ AnonFunction . SIGN_IN_ANONYMOUSLY
175
+ ) ;
176
+ await driver . callNoWait ( PopupFunction . IDP_LINK_POPUP ) ;
177
+ await driver . selectPopupWindow ( ) ;
178
+ const widget = new IdPPage ( driver . webDriver ) ;
179
+ await widget . pageLoad ( ) ;
180
+ await widget . clickAddAccount ( ) ;
181
+ await widget . fillEmail ( '[email protected] ' ) ;
182
+ await widget . clickSignIn ( ) ;
183
+
184
+ // On redirect, check that the signed in user is upgraded
185
+ await driver . selectMainWindow ( ) ;
186
+ const curUser = await driver . getUserSnapshot ( ) ;
187
+ expect ( curUser . uid ) . to . eq ( anonUser . uid ) ;
188
+ expect ( curUser . isAnonymous ) . to . be . false ;
189
+ } ) ;
190
+
191
+ it ( 'is possible to link with different email' , async ( ) => {
192
+ const { user : emailUser } : UserCredential = await driver . call (
193
+ EmailFunction . CREATE_USER ,
194
+
195
+ ) ;
196
+
197
+ // Link using pre-poulated user
198
+ await driver . callNoWait ( PopupFunction . IDP_LINK_POPUP ) ;
199
+ await driver . selectPopupWindow ( ) ;
200
+ const widget = new IdPPage ( driver . webDriver ) ;
201
+ await widget . pageLoad ( ) ;
202
+ await widget . clickAddAccount ( ) ;
203
+ await widget . fillEmail ( '[email protected] ' ) ;
204
+ await widget . clickSignIn ( ) ;
205
+
206
+ // Check the linked account
207
+ await driver . selectMainWindow ( ) ;
208
+ const curUser = await driver . getUserSnapshot ( ) ;
209
+ expect ( curUser . uid ) . to . eq ( emailUser . uid ) ;
210
+ expect ( curUser . emailVerified ) . to . be . false ;
211
+ expect ( curUser . providerData . length ) . to . eq ( 2 ) ;
212
+ } ) ;
213
+
214
+ it ( 'is possible to link with the same email' , async ( ) => {
215
+ const { user : emailUser } : UserCredential = await driver . call (
216
+ EmailFunction . CREATE_USER ,
217
+
218
+ ) ;
219
+
220
+ // Link using pre-poulated user
221
+ await driver . callNoWait ( PopupFunction . IDP_LINK_POPUP ) ;
222
+ await driver . selectPopupWindow ( ) ;
223
+ const widget = new IdPPage ( driver . webDriver ) ;
224
+ await widget . pageLoad ( ) ;
225
+ await widget . clickAddAccount ( ) ;
226
+ await widget . fillEmail ( '[email protected] ' ) ;
227
+ await widget . clickSignIn ( ) ;
228
+
229
+ // Check the linked account
230
+ await driver . selectMainWindow ( ) ;
231
+ const curUser = await driver . getUserSnapshot ( ) ;
232
+ expect ( curUser . uid ) . to . eq ( emailUser . uid ) ;
233
+ expect ( curUser . emailVerified ) . to . be . true ;
234
+ expect ( curUser . providerData . length ) . to . eq ( 2 ) ;
235
+ } ) ;
236
+
149
237
context ( 'with existing user' , ( ) => {
150
238
let user1 : User ;
151
239
let user2 : User ;
0 commit comments