@@ -2,7 +2,7 @@ import assert from 'assert';
22import feathers , { Application } from '@feathersjs/feathers' ;
33import jwt from 'jsonwebtoken' ;
44
5- import { AuthenticationBase } from '../src/core' ;
5+ import { AuthenticationBase , AuthenticationRequest } from '../src/core' ;
66import { Strategy1 , Strategy2 , MockRequest } from './fixtures' ;
77import { ServerResponse } from 'http' ;
88
@@ -23,6 +23,11 @@ describe('authentication/core', () => {
2323
2424 auth . register ( 'first' , new Strategy1 ( ) ) ;
2525 auth . register ( 'second' , new Strategy2 ( ) ) ;
26+ auth . register ( 'dummy' , {
27+ async authenticate ( data : AuthenticationRequest ) {
28+ return data ;
29+ }
30+ } ) ;
2631 } ) ;
2732
2833 describe ( 'configuration' , ( ) => {
@@ -80,7 +85,7 @@ describe('authentication/core', () => {
8085
8186 describe ( 'strategies' , ( ) => {
8287 it ( 'strategyNames' , ( ) => {
83- assert . deepStrictEqual ( auth . strategyNames , [ 'first' , 'second' ] ) ;
88+ assert . deepStrictEqual ( auth . strategyNames , [ 'first' , 'second' , 'dummy' ] ) ;
8489 } ) ;
8590
8691 it ( 'getStrategies' , ( ) => {
@@ -176,14 +181,6 @@ describe('authentication/core', () => {
176181 } , Strategy2 . result ) ) ;
177182 } ) ;
178183
179- it ( 'returns first success when both strategies succeed' , async ( ) => {
180- const result = await auth . authenticate ( {
181- both : true
182- } , { } , ...auth . strategyNames ) ;
183-
184- assert . deepStrictEqual ( result , Strategy1 . result ) ;
185- } ) ;
186-
187184 it ( 'throws error when allowed and passed strategy does not match' , async ( ) => {
188185 try {
189186 await auth . authenticate ( {
@@ -193,43 +190,18 @@ describe('authentication/core', () => {
193190 assert . fail ( 'Should never get here' ) ;
194191 } catch ( error ) {
195192 assert . strictEqual ( error . name , 'NotAuthenticated' ) ;
196- assert . strictEqual ( error . message , ` Invalid authentication strategy 'first'` ) ;
193+ assert . strictEqual ( error . message , ' Invalid authentication information' ) ;
197194 }
198195 } ) ;
199- } ) ;
200196
201- describe ( 'with a list of strategies and strategy not set in params' , ( ) => {
202- it ( 'returns first success in chain' , async ( ) => {
203- const authentication = {
204- v2 : true ,
205- password : 'supersecret'
206- } ;
207-
208- const result = await auth . authenticate ( authentication , { } , 'first' , 'second' ) ;
209-
210- assert . deepStrictEqual ( result , Object . assign ( {
211- authentication,
212- params : { authenticated : true }
213- } , Strategy2 . result ) ) ;
214- } ) ;
215-
216- it ( 'returns first error when all strategies fail' , async ( ) => {
217- try {
218- await auth . authenticate ( { } , { } , 'first' , 'second' ) ;
219- assert . fail ( 'Should never get here' ) ;
220- } catch ( error ) {
221- assert . strictEqual ( error . name , 'NotAuthenticated' ) ;
222- assert . strictEqual ( error . message , 'Invalid Dave' ) ;
223- }
224- } ) ;
225-
226- it ( 'errors when there is no valid strategy' , async ( ) => {
197+ it ( 'throws error when strategy is not set' , async ( ) => {
227198 try {
228- await auth . authenticate ( { } , { } , 'bla' ) ;
199+ await auth . authenticate ( {
200+ username : 'Dummy'
201+ } , { } , 'second' ) ;
229202 assert . fail ( 'Should never get here' ) ;
230203 } catch ( error ) {
231- assert . strictEqual ( error . name , 'NotAuthenticated' ) ;
232- assert . strictEqual ( error . message , 'No valid authentication strategy available' ) ;
204+ assert . strictEqual ( error . message , 'Invalid authentication information (no `strategy` set)' ) ;
233205 }
234206 } ) ;
235207 } ) ;
0 commit comments