@@ -34,7 +34,7 @@ tape.test('If invalid token then return 401', function(t) {
34
34
tape . test ( 'If valid token then return decoded token' , function ( t ) {
35
35
36
36
try {
37
- const decoded = auth . isValidToken ( 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0QHRlc3QuY29tIiwic2NvcGVzIjpbInRlc3RlciJdfQ.MjK579tyUaxtY9FXpTktC-vssI-rOS1RNsGl8KWX9mM ' ) ;
37
+ const decoded = auth . isValidToken ( 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0QHRlc3QuY29tIiwic2NvcGUiOlsidGVzdGVyIl19.ZzBZRdxQHFemCW2TwwFRn8Jk-uWt-OLtsi6O5pWpM34 ' ) ;
38
38
t . equal ( decoded . sub , '[email protected] ' ) ;
39
39
t . end ( ) ;
40
40
} catch ( err ) {
@@ -71,7 +71,7 @@ tape.test('If valid token with altered secret then return decoded token', functi
71
71
tape . test ( 'If valid token with Bearer keyword then return decoded token' , function ( t ) {
72
72
73
73
try {
74
- const decoded = auth . isValidToken ( 'Bearer ' + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0QHRlc3QuY29tIiwic2NvcGVzIjpbInRlc3RlciJdfQ.MjK579tyUaxtY9FXpTktC-vssI-rOS1RNsGl8KWX9mM ' ) ;
74
+ const decoded = auth . isValidToken ( 'Bearer ' + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0QHRlc3QuY29tIiwic2NvcGUiOlsidGVzdGVyIl19.ZzBZRdxQHFemCW2TwwFRn8Jk-uWt-OLtsi6O5pWpM34 ' ) ;
75
75
t . equal ( decoded . sub , '[email protected] ' ) ;
76
76
t . end ( ) ;
77
77
} catch ( err ) {
@@ -154,21 +154,33 @@ tape.test('if no unallowed roles present with None rule then return true', funct
154
154
t . end ( ) ;
155
155
} ) ;
156
156
157
- tape . test ( 'if valid token and valid scope then return true ' , function ( t ) {
157
+ tape . test ( 'if valid token and valid scope then resolve decoded token ' , function ( t ) {
158
158
159
- const authPromise = auth . authenticate ( 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0QHRlc3QuY29tIiwic2NvcGVzIjpbInRlc3RlciJdfQ.MjK579tyUaxtY9FXpTktC-vssI-rOS1RNsGl8KWX9mM' , {
159
+ const expectedDecodedToken = {
160
+
161
+ 'scope' : [
162
+ 'tester'
163
+ ]
164
+ } ;
165
+
166
+ const authPromise = auth . authenticate ( 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0QHRlc3QuY29tIiwic2NvcGUiOlsidGVzdGVyIl19.ZzBZRdxQHFemCW2TwwFRn8Jk-uWt-OLtsi6O5pWpM34' , {
160
167
scope : [ 'admin' ] ,
161
168
rule : auth . RULE . NONE
162
169
} ) ;
163
170
164
- t . ok ( authPromise , 'true expected' ) ;
165
- t . end ( ) ;
171
+ authPromise . then ( function ( decodedToken ) {
172
+ t . deepEqual ( expectedDecodedToken , decodedToken , 'decoded token doesn\'t match' ) ;
173
+ t . end ( ) ;
174
+ } ) . catch ( function ( err ) {
175
+ t . fail ( err . message ) ;
176
+ t . end ( ) ;
177
+ } ) ;
166
178
} ) ;
167
179
168
- tape . test ( 'if invalid token and valid scope then false ' , function ( t ) {
180
+ tape . test ( 'if invalid token and valid scope then reject ' , function ( t ) {
169
181
170
- const authPromise = auth . authenticate ( 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0QHRlc3QuY29tIiwic2NvcGVzIjpbInRlc3RlciJdfQ.MjK579tyUaxtY9FXpTktC-vssI-rOS1RNsGl8KWX9mM ' + 'foo' , {
171
- scope : [ 'admin ' ] ,
182
+ const authPromise = auth . authenticate ( 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0QHRlc3QuY29tIiwic2NvcGUiOlsidGVzdGVyIl19.ZzBZRdxQHFemCW2TwwFRn8Jk-uWt-OLtsi6O5pWpM34 ' + 'foo' , {
183
+ scope : [ 'tester ' ] ,
172
184
rule : auth . RULE . NONE
173
185
} ) ;
174
186
@@ -182,10 +194,10 @@ tape.test('if invalid token and valid scope then false', function(t) {
182
194
} ) ;
183
195
} ) ;
184
196
185
- tape . test ( 'if valid token and invalid scope then false ' , function ( t ) {
197
+ tape . test ( 'if valid token and invalid scope then reject ' , function ( t ) {
186
198
187
- const authPromise = auth . authenticate ( 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0QHRlc3QuY29tIiwic2NvcGVzIjpbInRlc3RlciJdfQ.MjK579tyUaxtY9FXpTktC-vssI-rOS1RNsGl8KWX9mM ' , {
188
- scope : [ 'tester ' ]
199
+ const authPromise = auth . authenticate ( 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0QHRlc3QuY29tIiwic2NvcGUiOlsidGVzdGVyIl19.ZzBZRdxQHFemCW2TwwFRn8Jk-uWt-OLtsi6O5pWpM34 ' , {
200
+ scope : [ 'admin ' ]
189
201
} ) ;
190
202
191
203
authPromise . then ( function ( ) {
0 commit comments