/
session.test.js
725 lines (577 loc) · 26.9 KB
/
session.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
import * as Factory from './lib/factory.js'
import WebDeviceInterface from './lib/web_device_interface.js'
chai.use(chaiAsPromised)
const expect = chai.expect
describe('server session', function () {
this.timeout(Factory.TenSecondTimeout)
let application
let email
let password
let newPassword
const syncOptions = {
checkIntegrity: true,
awaitAll: true,
}
beforeEach(async function () {
localStorage.clear()
application = await Factory.createInitAppWithFakeCrypto()
email = UuidGenerator.GenerateUuid()
password = UuidGenerator.GenerateUuid()
newPassword = Factory.randomString()
})
afterEach(async function () {
await Factory.safeDeinit(application)
application = null
localStorage.clear()
})
async function sleepUntilSessionExpires(application, basedOnAccessToken = true) {
const currentSession = application.legacyApi.session
const timestamp = basedOnAccessToken ? currentSession.accessToken.expiresAt : currentSession.refreshToken.expiresAt
const timeRemaining = (timestamp - Date.now()) / 1000 // in ms
/*
If the token has not expired yet, we will return the remaining time.
Else, there's no need to add a delay.
*/
const sleepTime = timeRemaining > 0 ? timeRemaining + 1 /** Safety margin */ : 0
await Factory.sleep(sleepTime)
}
async function getSessionFromStorage(application) {
return application.storage.getValue(StorageKey.Session)
}
it('should succeed when a sync request is perfomed with an expired access token', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
await sleepUntilSessionExpires(application)
const response = await application.legacyApi.sync([])
expect(response.status).to.equal(200)
}).timeout(Factory.TwentySecondTimeout)
it('should return the new session in the response when refreshed', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
const response = await application.legacyApi.deprecatedRefreshSessionOnlyUsedInE2eTests()
expect(response.status).to.equal(200)
expect(response.data.session.access_token).to.be.a('string')
expect(response.data.session.access_token).to.not.be.empty
expect(response.data.session.refresh_expiration).to.be.a('number')
expect(response.data.session.refresh_token).to.not.be.empty
})
it('should be refreshed on any api call if access token is expired', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
// Saving the current session information for later...
const sessionBeforeSync = application.legacyApi.getSession()
// Waiting enough time for the access token to expire, before performing a new sync request.
await sleepUntilSessionExpires(application)
// Performing a sync request with an expired access token.
await application.sync.sync(syncOptions)
// After the above sync request is completed, we obtain the session information.
const sessionAfterSync = application.legacyApi.getSession()
/**
* Access token and refresh token values in the new API version (20240226) represent the session uuid.
* So they should stay the same as they were since we are operating on the same session.
*
* The actual token values are stored in cookies indexed by the session uuid and are not accessible to the client.
*
* [E2E][Cookies] When e2e supports the expected behavior, we can uncomment the following lines.
*
*/
// expect(sessionBeforeSync.accessToken.value).to.equal(sessionAfterSync.accessToken.value)
// expect(sessionBeforeSync.refreshToken.value).to.equal(sessionAfterSync.refreshToken.value)
expect(sessionBeforeSync.accessToken.value).to.not.equal(sessionAfterSync.accessToken.value)
expect(sessionBeforeSync.refreshToken.value).to.not.equal(sessionAfterSync.refreshToken.value)
expect(sessionBeforeSync.accessToken.expiresAt).to.be.lessThan(sessionAfterSync.accessToken.expiresAt)
// New token should expire in the future.
expect(sessionAfterSync.accessToken.expiresAt).to.be.greaterThan(Date.now())
}).timeout(Factory.TwentySecondTimeout)
it('should not deadlock while renewing session', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
await sleepUntilSessionExpires(application)
// Apply a latency simulation so that ` inProgressRefreshSessionPromise = refreshSession()` does
// not have the chance to complete before it is assigned to the variable. This test came along with a fix
// where runHttp does not await a pending refreshSession promise if the request being made is itself a refreshSession request.
application.http.__latencySimulatorMs = 1000
await application.sync.sync(syncOptions)
const sessionAfterSync = application.legacyApi.getSession()
expect(sessionAfterSync.accessToken.expiresAt).to.be.greaterThan(Date.now())
}).timeout(Factory.TwentySecondTimeout)
it('should succeed when a sync request is perfomed after signing into an ephemeral session', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
application = await Factory.signOutApplicationAndReturnNew(application)
await application.signIn(email, password, false, true)
const response = await application.legacyApi.sync([])
expect(response.status).to.equal(200)
})
it('should succeed when a sync request is perfomed after registering into an ephemeral session', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
ephemeral: true,
})
const response = await application.legacyApi.sync([])
expect(response.status).to.equal(200)
})
it('should be consistent between storage and apiService', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
const sessionFromStorage = await getSessionFromStorage(application)
const sessionFromApiService = application.legacyApi.getSession()
expect(sessionFromStorage.accessToken).to.equal(sessionFromApiService.accessToken.value)
expect(sessionFromStorage.refreshToken).to.equal(sessionFromApiService.refreshToken.value)
expect(sessionFromStorage.accessExpiration).to.equal(sessionFromApiService.accessToken.expiresAt)
expect(sessionFromStorage.refreshExpiration).to.equal(sessionFromApiService.refreshToken.expiresAt)
expect(sessionFromStorage.readonlyAccess).to.equal(sessionFromApiService.isReadOnly())
await application.legacyApi.deprecatedRefreshSessionOnlyUsedInE2eTests()
const updatedSessionFromStorage = await getSessionFromStorage(application)
const updatedSessionFromApiService = application.legacyApi.getSession()
expect(updatedSessionFromStorage.accessToken).to.equal(updatedSessionFromApiService.accessToken.value)
expect(updatedSessionFromStorage.refreshToken).to.equal(updatedSessionFromApiService.refreshToken.value)
expect(updatedSessionFromStorage.accessExpiration).to.equal(updatedSessionFromApiService.accessToken.expiresAt)
expect(updatedSessionFromStorage.refreshExpiration).to.equal(updatedSessionFromApiService.refreshToken.expiresAt)
expect(updatedSessionFromStorage.readonlyAccess).to.equal(updatedSessionFromApiService.isReadOnly())
})
it('should be performed successfully and terminate session with a valid access token', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
const signOutResponse = await application.legacyApi.signOut()
expect(signOutResponse.status).to.equal(204)
Factory.ignoreChallenges(application)
const syncResponse = await application.legacyApi.sync([])
expect(syncResponse.status).to.equal(401)
expect(syncResponse.data.error.tag).to.equal('invalid-auth')
expect(syncResponse.data.error.message).to.equal('Invalid login credentials.')
})
it('sign out request should be performed successfully and terminate session with expired access token', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
// Waiting enough time for the access token to expire, before performing a sign out request.
await sleepUntilSessionExpires(application)
const signOutResponse = await application.legacyApi.signOut()
expect(signOutResponse.status).to.equal(204)
Factory.ignoreChallenges(application)
const syncResponse = await application.legacyApi.sync([])
expect(syncResponse.status).to.equal(401)
expect(syncResponse.data.error.tag).to.equal('invalid-auth')
expect(syncResponse.data.error.message).to.equal('Invalid login credentials.')
}).timeout(Factory.TwentySecondTimeout)
it('change email request should be successful with a valid access token', async function () {
let { application, password } = await Factory.createAndInitSimpleAppContext({
registerUser: true,
})
const newEmail = UuidGenerator.GenerateUuid()
const changeEmailResponse = await application.changeEmail(newEmail, password)
expect(changeEmailResponse.error).to.not.be.ok
application = await Factory.signOutApplicationAndReturnNew(application)
const loginResponse = await Factory.loginToApplication({
application: application,
email: newEmail,
password: password,
})
expect(loginResponse).to.be.ok
expect(loginResponse.status).to.equal(200)
await Factory.safeDeinit(application)
}).timeout(Factory.TwentySecondTimeout)
it('change email request should fail with an invalid access token', async function () {
let { application, password } = await Factory.createAndInitSimpleAppContext({
registerUser: true,
})
application.storage.setValue(StorageKey.Session, {
accessToken: 'this-is-a-fake-token-1234',
refreshToken: 'this-is-a-fake-token-1234',
accessExpiration: 999999999999999,
refreshExpiration: 99999999999999,
readonlyAccess: false,
})
application.sessions.initializeFromDisk()
Factory.ignoreChallenges(application)
const newEmail = UuidGenerator.GenerateUuid()
const changeEmailResponse = await application.changeEmail(newEmail, password)
expect(changeEmailResponse.error.message).to.equal('Invalid login credentials.')
await Factory.safeDeinit(application)
}).timeout(Factory.TwentySecondTimeout)
it('change email request should fail with an expired refresh token', async function () {
let { application, password } = await Factory.createAndInitSimpleAppContext({
registerUser: true,
})
application.sync.lockSyncing()
/** Waiting for the refresh token to expire. */
await sleepUntilSessionExpires(application, false)
Factory.ignoreChallenges(application)
const newEmail = UuidGenerator.GenerateUuid()
const changeEmailResponse = await application.changeEmail(newEmail, password)
expect(changeEmailResponse).to.be.ok
expect(changeEmailResponse.error.message).to.equal('Invalid login credentials.')
await Factory.safeDeinit(application)
}).timeout(Factory.ThirtySecondTimeout)
it('change password request should be successful with a valid access token', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
const changePasswordResponse = await application.changePassword(password, newPassword)
expect(changePasswordResponse.error).to.not.be.ok
application = await Factory.signOutApplicationAndReturnNew(application)
const loginResponse = await Factory.loginToApplication({
application: application,
email: email,
password: newPassword,
})
expect(loginResponse).to.be.ok
expect(loginResponse.status).to.be.equal(200)
}).timeout(Factory.TwentySecondTimeout)
it('change password request should be successful after the expired access token is refreshed', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
// Waiting enough time for the access token to expire.
await sleepUntilSessionExpires(application)
const changePasswordResponse = await application.changePassword(password, newPassword)
expect(changePasswordResponse.error).to.not.be.ok
application = await Factory.signOutApplicationAndReturnNew(application)
const loginResponse = await Factory.loginToApplication({
application: application,
email: email,
password: newPassword,
})
expect(loginResponse).to.be.ok
expect(loginResponse.status).to.be.equal(200)
}).timeout(Factory.TwentySecondTimeout)
it('change password request should fail with an invalid access token', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
application.storage.setValue(StorageKey.Session, {
accessToken: 'this-is-a-fake-token-1234',
refreshToken: 'this-is-a-fake-token-1234',
accessExpiration: 999999999999999,
refreshExpiration: 99999999999999,
readonlyAccess: false,
})
application.sessions.initializeFromDisk()
Factory.ignoreChallenges(application)
const changePasswordResponse = await application.changePassword(password, newPassword)
expect(changePasswordResponse.error.message).to.equal('Invalid login credentials.')
})
it('change password request should fail with an expired refresh token', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
application.sync.lockSyncing()
/** Waiting for the refresh token to expire. */
await sleepUntilSessionExpires(application, false)
Factory.ignoreChallenges(application)
const changePasswordResponse = await application.changePassword(password, newPassword)
expect(changePasswordResponse).to.be.ok
expect(changePasswordResponse.error.message).to.equal('Invalid login credentials.')
}).timeout(25000)
it('should sign in successfully after signing out', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
await application.legacyApi.signOut()
application.legacyApi.session = undefined
await application.sessions.signIn(email, password)
const currentSession = application.legacyApi.getSession()
expect(currentSession).to.be.ok
expect(currentSession.accessToken).to.be.ok
expect(currentSession.refreshToken).to.be.ok
expect(currentSession.accessToken.expiresAt).to.be.greaterThan(Date.now())
})
it('should fail when renewing a session with an expired refresh token', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
application.sync.lockSyncing()
await sleepUntilSessionExpires(application, false)
const refreshSessionResponse = await application.legacyApi.deprecatedRefreshSessionOnlyUsedInE2eTests()
expect(refreshSessionResponse.status).to.equal(400)
/**
* [E2E][Cookies] The following expectations are commented out because e2e does not support sending cookies with requests yet.
*/
// expect(refreshSessionResponse.data.error.tag).to.equal('invalid-parameters')
// expect(refreshSessionResponse.data.error.message).to.equal('The provided parameters are not valid.')
expect(refreshSessionResponse.data.error.tag).to.equal('expired-refresh-token')
expect(refreshSessionResponse.data.error.message).to.equal('The refresh token has expired.')
/*
The access token and refresh token should be expired up to this point.
Here we make sure that any subsequent requests will fail.
*/
Factory.ignoreChallenges(application)
const syncResponse = await application.legacyApi.sync([])
expect(syncResponse.status).to.equal(401)
expect(syncResponse.data.error.tag).to.equal('invalid-auth')
expect(syncResponse.data.error.message).to.equal('Invalid login credentials.')
}).timeout(Factory.TwentySecondTimeout)
/**
* This test is skipped due to the fact that tokens reside now in cookies and are not accessible to the client.
* Thus it is not possible to tamper with the refresh token.
*/
it.skip('should fail when renewing a session with an invalid refresh token', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
const originalSession = application.legacyApi.getSession()
application.storage.setValue(StorageKey.Session, {
accessToken: originalSession.accessToken.value,
refreshToken: 'this-is-a-fake-token-1234',
accessExpiration: originalSession.accessToken.expiresAt,
refreshExpiration: originalSession.refreshToken.expiresAt,
readonlyAccess: false,
})
application.sessions.initializeFromDisk()
const refreshSessionResponse = await application.legacyApi.deprecatedRefreshSessionOnlyUsedInE2eTests()
expect(refreshSessionResponse.status).to.equal(400)
expect(refreshSessionResponse.data.error.tag).to.equal('invalid-refresh-token')
expect(refreshSessionResponse.data.error.message).to.equal('The refresh token is not valid.')
// Access token should remain valid.
const syncResponse = await application.legacyApi.sync([])
expect(syncResponse.status).to.equal(200)
})
it('should fail if syncing while a session refresh is in progress', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
const refreshPromise = application.legacyApi.deprecatedRefreshSessionOnlyUsedInE2eTests()
const syncResponse = await application.legacyApi.sync([])
expect(syncResponse.data.error).to.be.ok
const errorMessage = 'Your account session is being renewed with the server. Please try your request again.'
expect(syncResponse.data.error.message).to.be.equal(errorMessage)
/** Wait for finish so that test cleans up properly */
await refreshPromise
})
it('should tell the client to refresh the token if one is used during the cooldown period after a refresh', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
const mimickApplyingSessionFromTheServerUnsuccessfully = () => {}
const originalSetSessionFn = application.http.setSession
const originalRefreshSessionCallbackFn = application.http.refreshSessionCallback
application.http.setSession = mimickApplyingSessionFromTheServerUnsuccessfully
application.http.refreshSessionCallback = mimickApplyingSessionFromTheServerUnsuccessfully
const refreshResultOrError = await application.http.refreshSession()
expect(refreshResultOrError.isFailed()).to.equal(false)
const refreshResult = refreshResultOrError.getValue()
expect(isErrorResponse(refreshResult)).to.equal(false)
const secondRefreshResultOrErrorWithNotAppliedSession = await application.http.refreshSession()
expect(secondRefreshResultOrErrorWithNotAppliedSession.isFailed()).to.equal(false)
const secondRefreshResultWithNotAppliedSession = secondRefreshResultOrErrorWithNotAppliedSession.getValue()
expect(isErrorResponse(secondRefreshResultWithNotAppliedSession)).to.equal(false)
application.http.setSession = originalSetSessionFn
application.http.refreshSessionCallback = originalRefreshSessionCallbackFn
})
it('if session renewal response is dropped, next sync with server should return a 498 and successfully renew the session', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
await sleepUntilSessionExpires(application)
const refreshSpy = sinon.spy(application.http, 'refreshSession')
/**
* With this sync, we expect refreshSession to be called twice, once where the response is dropped,
* and the other time where the request succeeds
*/
application.http.__simulateNextSessionRefreshResponseDrop = true
await application.sync.sync(syncOptions)
await application.sync.sync(syncOptions)
expect(refreshSpy.callCount).to.equal(2)
})
it('notes should be synced as expected after refreshing a session', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
const notesBeforeSync = await Factory.createManyMappedNotes(application, 5)
await sleepUntilSessionExpires(application)
await application.sync.sync(syncOptions)
expect(application.sync.isOutOfSync()).to.equal(false)
application = await Factory.signOutApplicationAndReturnNew(application)
await application.signIn(email, password, undefined, undefined, undefined, true)
const expectedNotesUuids = notesBeforeSync.map((n) => n.uuid)
const notesResults = await application.items.findItems(expectedNotesUuids)
expect(notesResults.length).to.equal(notesBeforeSync.length)
for (const aNoteBeforeSync of notesBeforeSync) {
const noteResult = await application.items.findItem(aNoteBeforeSync.uuid)
expect(aNoteBeforeSync.isItemContentEqualWith(noteResult)).to.equal(true)
}
}).timeout(Factory.TwentySecondTimeout)
it('should prompt user for account password and sign back in on invalid session', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
email = `${Math.random()}`
password = `${Math.random()}`
let didPromptForSignIn = false
const receiveChallenge = async (challenge) => {
didPromptForSignIn = true
appA.submitValuesForChallenge(challenge, [
CreateChallengeValue(challenge.prompts[0], email),
CreateChallengeValue(challenge.prompts[1], password),
])
}
const appA = await Factory.createApplicationWithFakeCrypto(Factory.randomString())
await appA.prepareForLaunch({ receiveChallenge })
await appA.launch(true)
await Factory.registerUserToApplication({
application: appA,
email: email,
password: password,
})
const oldRootKey = await appA.encryption.getRootKey()
/** Set the session as nonsense */
appA.storage.setValue(StorageKey.Session, {
accessToken: 'foo',
refreshToken: 'bar',
accessExpiration: 999999999999999,
refreshExpiration: 999999999999999,
readonlyAccess: false,
})
appA.sessions.initializeFromDisk()
/** Perform an authenticated network request */
await appA.sync.sync()
/** Allow session recovery to do its thing */
await Factory.sleep(5.0)
expect(didPromptForSignIn).to.equal(true)
expect(appA.legacyApi.session.accessToken.value).to.not.equal('foo')
expect(appA.legacyApi.session.refreshToken.value).to.not.equal('bar')
/** Expect that the session recovery replaces the global root key */
const newRootKey = await appA.encryption.getRootKey()
expect(oldRootKey).to.not.equal(newRootKey)
await Factory.safeDeinit(appA)
})
it('should return current session in list of sessions', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
const response = await application.legacyApi.getSessionsList()
expect(response.data[0].current).to.equal(true)
})
it('signing out should delete session from all list', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
/** Create new session aside from existing one */
const app2 = await Factory.createAndInitializeApplication('app2')
await app2.signIn(email, password)
const response = await application.legacyApi.getSessionsList()
expect(response.data.length).to.equal(2)
await app2.user.signOut()
const response2 = await application.legacyApi.getSessionsList()
expect(response2.data.length).to.equal(1)
})
it('revoking a session should destroy local data', async function () {
Factory.handlePasswordChallenges(application, password)
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
const app2identifier = 'app2'
const app2 = await Factory.createAndInitializeApplication(app2identifier)
await app2.signIn(email, password)
const app2Deinit = new Promise((resolve) => {
app2.setOnDeinit(() => {
resolve()
})
})
const { data: sessions } = await application.getSessions()
const app2session = sessions.find((session) => !session.current)
await application.revokeSession(app2session.uuid)
void app2.sync.sync()
await app2Deinit
const deviceInterface = new WebDeviceInterface()
const payloads = await deviceInterface.getAllDatabaseEntries(app2identifier)
expect(payloads).to.be.empty
}).timeout(Factory.TwentySecondTimeout)
it('revoking other sessions should destroy their local data', async function () {
Factory.handlePasswordChallenges(application, password)
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
const app2identifier = 'app2'
const app2 = await Factory.createAndInitializeApplication(app2identifier)
await app2.signIn(email, password)
const app2Deinit = new Promise((resolve) => {
app2.setOnDeinit(() => {
resolve()
})
})
await application.revokeAllOtherSessions()
void app2.sync.sync()
await app2Deinit
const deviceInterface = new WebDeviceInterface()
const payloads = await deviceInterface.getAllDatabaseEntries(app2identifier)
expect(payloads).to.be.empty
}).timeout(Factory.TwentySecondTimeout)
it('signing out with invalid session token should still delete local data', async function () {
await Factory.registerUserToApplication({
application: application,
email: email,
password: password,
})
application.storage.setValue(StorageKey.Session, {
accessToken: undefined,
refreshToken: undefined,
accessExpiration: 999999999999999,
refreshExpiration: 999999999999999,
readonlyAccess: false,
})
application.sessions.initializeFromDisk()
const storageKey = application.storage.getPersistenceKey()
expect(localStorage.getItem(storageKey)).to.be.ok
await application.user.signOut()
expect(localStorage.getItem(storageKey)).to.not.be.ok
})
})