11'use strict'
22
3- require ( 'localstorage-polyfill' ) // exports 'localStorage' global
43global . URL = require ( 'url' ) . URL
54global . URLSearchParams = require ( 'url' ) . URLSearchParams
65
6+ const localStorage = require ( 'localstorage-memory' )
7+
78const chai = require ( 'chai' )
89const sinon = require ( 'sinon' )
910const sinonChai = require ( 'sinon-chai' )
@@ -26,7 +27,7 @@ describe('SolidAuthOIDC', () => {
2627 let auth , providerUri
2728
2829 beforeEach ( ( ) => {
29- auth = new SolidAuthOIDC ( )
30+ auth = new SolidAuthOIDC ( { store : localStorage } )
3031 providerUri = 'https://provider.example.com'
3132 } )
3233
@@ -77,7 +78,8 @@ describe('SolidAuthOIDC', () => {
7778 let auth
7879
7980 beforeEach ( ( ) => {
80- auth = new SolidAuthOIDC ( )
81+ localStorage . clear ( )
82+ auth = new SolidAuthOIDC ( { store : localStorage } )
8183 } )
8284
8385 it ( 'should clear the current user' , ( ) => {
@@ -131,7 +133,8 @@ describe('SolidAuthOIDC', () => {
131133 describe ( 'providerFromCurrentUri()' , ( ) => {
132134 var auth
133135 beforeEach ( ( ) => {
134- auth = new SolidAuthOIDC ( { window : { location : { } } } )
136+ localStorage . clear ( )
137+ auth = new SolidAuthOIDC ( { window : { location : { } } , store : localStorage } )
135138 } )
136139
137140 it ( 'should return null when no state param present' , ( ) => {
@@ -163,7 +166,8 @@ describe('SolidAuthOIDC', () => {
163166
164167 describe ( 'provider persistence' , ( ) => {
165168 it ( 'should store and load provider uri, by state' , ( ) => {
166- let auth = new SolidAuthOIDC ( )
169+ localStorage . clear ( )
170+ let auth = new SolidAuthOIDC ( { store : localStorage } )
167171 let providerUri = 'https://provider.example.com'
168172 let state = 'abcd'
169173 // Check to see that provider doesn't exist initially
@@ -265,7 +269,8 @@ describe('SolidAuthOIDC', () => {
265269 var auth
266270
267271 beforeEach ( ( ) => {
268- auth = new SolidAuthOIDC ( )
272+ localStorage . clear ( )
273+ auth = new SolidAuthOIDC ( { store : localStorage } )
269274 } )
270275
271276 describe ( 'loadClient()' , ( ) => {
@@ -290,8 +295,6 @@ describe('SolidAuthOIDC', () => {
290295 } )
291296
292297 it ( 'should store and load serialized clients' , ( ) => {
293- let auth = new SolidAuthOIDC ( )
294-
295298 auth . storeClient ( mockClient , providerUri )
296299 // Storing a client should cache it in the auth client
297300 expect ( auth . currentClient ) . to . equal ( mockClient )
@@ -305,8 +308,12 @@ describe('SolidAuthOIDC', () => {
305308
306309 describe ( 'currentLocation()' , ( ) => {
307310 it ( 'should return the current window uri' , ( ) => {
311+ localStorage . clear ( )
312+
308313 let currentUri = 'https://client-app.example.com'
309- let auth = new SolidAuthOIDC ( { window : { location : { href : currentUri } } } )
314+ let auth = new SolidAuthOIDC ( {
315+ window : { location : { href : currentUri } } , store : localStorage
316+ } )
310317
311318 expect ( auth . currentLocation ( ) ) . to . equal ( currentUri )
312319 } )
@@ -357,7 +364,7 @@ describe('SolidAuthOIDC', () => {
357364
358365 beforeEach ( ( ) => {
359366 localStorage . clear ( )
360- auth = new SolidAuthOIDC ( { window : { location : { } } } )
367+ auth = new SolidAuthOIDC ( { window : { location : { } } , store : localStorage } )
361368 } )
362369
363370 it ( 'should validate the auth response' , ( ) => {
@@ -385,8 +392,14 @@ describe('SolidAuthOIDC', () => {
385392 } )
386393
387394 describe ( 'sendAuthRequest()' , ( ) => {
395+ var auth
396+
397+ beforeEach ( ( ) => {
398+ localStorage . clear ( )
399+ auth = new SolidAuthOIDC ( { window : { location : { } } , store : localStorage } )
400+ } )
401+
388402 it ( 'should compose an auth request uri, save provider, and redirect' , ( ) => {
389- let auth = new SolidAuthOIDC ( { window : { location : { } } } )
390403 let state = 'abcd'
391404 let providerUri = 'https://provider.example.com'
392405 let authUri = `https://provider.example.com/authorize?state=${ state } `
@@ -407,24 +420,27 @@ describe('SolidAuthOIDC', () => {
407420 } )
408421
409422 describe ( 'currentUser()' , ( ) => {
423+ var auth
424+
425+ beforeEach ( ( ) => {
426+ localStorage . clear ( )
427+ auth = new SolidAuthOIDC ( { window : { location : { } } , store : localStorage } )
428+ } )
429+
410430 it ( 'should return cached webId if present' , ( ) => {
411431 let aliceWebId = 'https://alice.example.com'
412- let auth = new SolidAuthOIDC ( )
413432 auth . webId = aliceWebId
414433
415434 expect ( auth . currentUser ( ) ) . to . eventually . equal ( aliceWebId )
416435 } )
417436
418437 it ( 'should return null if no cached webId and no current state param' , ( ) => {
419- let auth = new SolidAuthOIDC ( { window : { location : { } } } )
420-
421438 expect ( auth . currentUser ( ) ) . to . eventually . not . exist ( )
422439 } )
423440
424441 it ( 'should automatically login if current uri has state param' , ( ) => {
425442 let state = 'abcd'
426443 let providerUri = 'https://provider.example.com'
427- let auth = new SolidAuthOIDC ( { window : { location : { } } } )
428444 auth . saveProviderByState ( state , providerUri )
429445
430446 auth . window . location . href = `https://client-app.example.com#state=${ state } `
@@ -441,10 +457,11 @@ describe('SolidAuthOIDC', () => {
441457 } )
442458
443459 describe ( 'providerEndSessionEndpoint()' , ( ) => {
444- let auth
460+ var auth
445461
446462 beforeEach ( ( ) => {
447- auth = new SolidAuthOIDC ( )
463+ localStorage . clear ( )
464+ auth = new SolidAuthOIDC ( { window : { location : { } } , store : localStorage } )
448465 } )
449466
450467 it ( 'should return null if no current client' , ( ) => {
0 commit comments