@@ -19,18 +19,15 @@ const expect = chai.expect
1919const SolidAuthOIDC = require ( '../src/index' )
2020
2121describe ( 'SolidAuthOIDC' , ( ) => {
22+ var auth
23+ const providerUri = 'https://provider.example.com'
24+
2225 beforeEach ( ( ) => {
2326 localStorage . clear ( )
27+ auth = new SolidAuthOIDC ( { window : { location : { } } , store : localStorage } )
2428 } )
2529
2630 describe ( 'login()' , ( ) => {
27- let auth , providerUri
28-
29- beforeEach ( ( ) => {
30- auth = new SolidAuthOIDC ( { store : localStorage } )
31- providerUri = 'https://provider.example.com'
32- } )
33-
3431 it ( 'should invoke selectProvider() if provider uri is not given' , ( ) => {
3532 let selectProvider = sinon . stub ( auth , 'selectProvider' ) . resolves ( null )
3633
@@ -75,13 +72,6 @@ describe('SolidAuthOIDC', () => {
7572 } )
7673
7774 describe ( 'logout()' , ( ) => {
78- let auth
79-
80- beforeEach ( ( ) => {
81- localStorage . clear ( )
82- auth = new SolidAuthOIDC ( { store : localStorage } )
83- } )
84-
8575 it ( 'should clear the current user' , ( ) => {
8676 let clearCurrentUser = sinon . spy ( auth , 'clearCurrentUser' )
8777
@@ -131,12 +121,6 @@ describe('SolidAuthOIDC', () => {
131121 } )
132122
133123 describe ( 'providerFromCurrentUri()' , ( ) => {
134- var auth
135- beforeEach ( ( ) => {
136- localStorage . clear ( )
137- auth = new SolidAuthOIDC ( { window : { location : { } } , store : localStorage } )
138- } )
139-
140124 it ( 'should return null when no state param present' , ( ) => {
141125 auth . window . location . href = 'https://client-app.example.com'
142126 let providerUri = auth . providerFromCurrentUri ( )
@@ -166,9 +150,6 @@ describe('SolidAuthOIDC', () => {
166150
167151 describe ( 'provider persistence' , ( ) => {
168152 it ( 'should store and load provider uri, by state' , ( ) => {
169- localStorage . clear ( )
170- let auth = new SolidAuthOIDC ( { store : localStorage } )
171- let providerUri = 'https://provider.example.com'
172153 let state = 'abcd'
173154 // Check to see that provider doesn't exist initially
174155 expect ( auth . loadProvider ( state ) ) . to . not . exist ( )
@@ -182,12 +163,6 @@ describe('SolidAuthOIDC', () => {
182163 } )
183164
184165 describe ( 'extractState()' , ( ) => {
185- var auth
186-
187- beforeEach ( ( ) => {
188- auth = new SolidAuthOIDC ( )
189- } )
190-
191166 it ( 'should return null when no uri is provided' , ( ) => {
192167 let state = auth . extractState ( )
193168
@@ -227,15 +202,10 @@ describe('SolidAuthOIDC', () => {
227202
228203 describe ( 'selectProvider()' , ( ) => {
229204 it ( 'should pass through a given providerUri' , ( ) => {
230- let auth = new SolidAuthOIDC ( )
231- let providerUri = 'https://provider.example.com'
232-
233205 expect ( auth . selectProvider ( providerUri ) ) . to . eventually . equal ( providerUri )
234206 } )
235207
236208 it ( 'should derive a provider from the current uri' , ( ) => {
237- let auth = new SolidAuthOIDC ( )
238- let providerUri = 'https://provider.example.com'
239209 auth . providerFromCurrentUri = sinon . stub ( ) . returns ( providerUri )
240210
241211 return auth . selectProvider ( )
@@ -246,8 +216,6 @@ describe('SolidAuthOIDC', () => {
246216 } )
247217
248218 it ( 'should obtain provider from UI, if not present or cached' , ( ) => {
249- let auth = new SolidAuthOIDC ( )
250- let providerUri = 'https://provider.example.com'
251219 auth . providerFromCurrentUri = sinon . stub ( ) . returns ( null )
252220 auth . providerFromUI = sinon . stub ( ) . resolves ( providerUri )
253221
@@ -260,18 +228,11 @@ describe('SolidAuthOIDC', () => {
260228 } )
261229
262230 describe ( 'client persistence' , ( ) => {
263- let providerUri = 'https://provider.example.com'
264231 let clientConfig = { provider : { url : providerUri } }
265232 let mockClient = {
266233 provider : { url : providerUri } ,
267234 serialize : ( ) => { return clientConfig }
268235 }
269- var auth
270-
271- beforeEach ( ( ) => {
272- localStorage . clear ( )
273- auth = new SolidAuthOIDC ( { store : localStorage } )
274- } )
275236
276237 describe ( 'loadClient()' , ( ) => {
277238 it ( 'should throw an error if no providerUri given' , ( ) => {
@@ -320,13 +281,6 @@ describe('SolidAuthOIDC', () => {
320281 } )
321282
322283 describe ( 'validateOrSendAuthRequest()' , ( ) => {
323- var auth
324-
325- beforeEach ( ( ) => {
326- localStorage . clear ( )
327- auth = new SolidAuthOIDC ( { window : { location : { } } } )
328- } )
329-
330284 it ( 'should throw an error when no client is given' , ( ) => {
331285 expect ( auth . validateOrSendAuthRequest ( ) )
332286 . to . be . rejectedWith ( / C o u l d n o t l o a d o r r e g i s t e r a R e l y i n g P a r t y c l i e n t / )
@@ -360,13 +314,6 @@ describe('SolidAuthOIDC', () => {
360314 } )
361315
362316 describe ( 'initUserFromResponse()' , ( ) => {
363- var auth
364-
365- beforeEach ( ( ) => {
366- localStorage . clear ( )
367- auth = new SolidAuthOIDC ( { window : { location : { } } , store : localStorage } )
368- } )
369-
370317 it ( 'should validate the auth response' , ( ) => {
371318 let aliceWebId = 'https://alice.example.com/'
372319 let authResponse = {
@@ -392,13 +339,6 @@ describe('SolidAuthOIDC', () => {
392339 } )
393340
394341 describe ( 'sendAuthRequest()' , ( ) => {
395- var auth
396-
397- beforeEach ( ( ) => {
398- localStorage . clear ( )
399- auth = new SolidAuthOIDC ( { window : { location : { } } , store : localStorage } )
400- } )
401-
402342 it ( 'should compose an auth request uri, save provider, and redirect' , ( ) => {
403343 let state = 'abcd'
404344 let providerUri = 'https://provider.example.com'
@@ -420,13 +360,6 @@ describe('SolidAuthOIDC', () => {
420360 } )
421361
422362 describe ( 'currentUser()' , ( ) => {
423- var auth
424-
425- beforeEach ( ( ) => {
426- localStorage . clear ( )
427- auth = new SolidAuthOIDC ( { window : { location : { } } , store : localStorage } )
428- } )
429-
430363 it ( 'should return cached webId if present' , ( ) => {
431364 let aliceWebId = 'https://alice.example.com'
432365 auth . webId = aliceWebId
@@ -457,13 +390,6 @@ describe('SolidAuthOIDC', () => {
457390 } )
458391
459392 describe ( 'providerEndSessionEndpoint()' , ( ) => {
460- var auth
461-
462- beforeEach ( ( ) => {
463- localStorage . clear ( )
464- auth = new SolidAuthOIDC ( { window : { location : { } } , store : localStorage } )
465- } )
466-
467393 it ( 'should return null if no current client' , ( ) => {
468394 auth . currentClient = null
469395
@@ -496,7 +422,7 @@ describe('SolidAuthOIDC', () => {
496422 expect ( url ) . to . equal ( null )
497423 } )
498424
499- it ( 'should return null if current provider end session endpoint' , ( ) => {
425+ it ( 'should return the provider end session endpoint' , ( ) => {
500426 auth . currentClient = {
501427 provider : {
502428 configuration : {
@@ -513,8 +439,6 @@ describe('SolidAuthOIDC', () => {
513439
514440 describe ( 'clearAuthResponseFromUrl()' , ( ) => {
515441 it ( 'should replace the current url with a no-hash cleared one' , ( ) => {
516- let auth = new SolidAuthOIDC ( )
517-
518442 let clearedUrl = 'https://rp.com'
519443
520444 auth . currentLocationNoHash = sinon . stub ( ) . returns ( clearedUrl )
0 commit comments