@@ -21,13 +21,13 @@ const authCredential = async (
21
21
return await authenticator . authCredential ( ctx ) ;
22
22
} ;
23
23
24
- const authIdentity = async (
24
+ const getTokenInfo = async (
25
25
ctx : KoaContext ,
26
26
options : any
27
27
) : Promise < Record < string , any > > => {
28
28
const authenticator = new BasicAuthenticator ( { options } , '' ) ;
29
29
await authenticator . activate ( ) ;
30
- return await authenticator . authIdentity ( ctx ) ;
30
+ return await authenticator . getTokenInfo ( ctx ) ;
31
31
} ;
32
32
33
33
describe ( 'Test http basic authenticator' , ( ) => {
@@ -310,35 +310,13 @@ describe('Test http basic authenticator', () => {
310
310
} ;
311
311
const expected = Buffer . from ( 'user1:test1' ) . toString ( 'base64' ) ;
312
312
// Act
313
- const result = await authIdentity ( ctx , {
313
+ const result = await getTokenInfo ( ctx , {
314
314
basic : { 'users-list' : userLists } ,
315
315
} ) ;
316
316
// Assert
317
317
expect ( result [ 'token' ] ) . toEqual ( expected ) ;
318
318
} ) ;
319
319
320
- it ( 'Should auth identity failed when request not matched in empty "users-list" options' , async ( ) => {
321
- // Arrange
322
- const expected = new Error ( 'authenticate user identity failed.' ) ;
323
- const ctx = {
324
- ...sinon . stubInterface < KoaContext > ( ) ,
325
- request : {
326
- ...sinon . stubInterface < Request > ( ) ,
327
- query : {
328
- ...sinon . stubInterface < ParsedUrlQuery > ( ) ,
329
- username : 'user1' ,
330
- password : 'test1' ,
331
- } ,
332
- } ,
333
- } ;
334
- // Act
335
- const action = authIdentity ( ctx , {
336
- basic : { 'users-list' : [ ] } ,
337
- } ) ;
338
- // Assert
339
- expect ( action ) . rejects . toThrow ( expected ) ;
340
- } ) ;
341
-
342
320
it ( 'Should auth identity successfully when request match in "htpasswd-file" path of options' , async ( ) => {
343
321
// Arrange
344
322
const expected = Buffer . from ( 'user3:test3' ) . toString ( 'base64' ) ;
@@ -357,7 +335,7 @@ describe('Test http basic authenticator', () => {
357
335
} ;
358
336
359
337
// Act
360
- const result = await authIdentity ( ctx , {
338
+ const result = await getTokenInfo ( ctx , {
361
339
basic : {
362
340
'htpasswd-file' : {
363
341
path : path . resolve ( __dirname , './test-files/basic.htpasswd' ) ,
@@ -369,32 +347,6 @@ describe('Test http basic authenticator', () => {
369
347
expect ( result [ 'token' ] ) . toEqual ( expected ) ;
370
348
} ) ;
371
349
372
- it ( 'Should auth identity failed when request not match in "htpasswd-file" path of options' , async ( ) => {
373
- // Arrange
374
- const expected = new Error ( 'authenticate user identity failed.' ) ;
375
- const ctx = {
376
- ...sinon . stubInterface < KoaContext > ( ) ,
377
- request : {
378
- ...sinon . stubInterface < Request > ( ) ,
379
- query : {
380
- ...sinon . stubInterface < ParsedUrlQuery > ( ) ,
381
- username : 'user1' ,
382
- password : 'test1' ,
383
- } ,
384
- } ,
385
- } ;
386
- // Act
387
- const action = authIdentity ( ctx , {
388
- basic : {
389
- 'htpasswd-file' : {
390
- path : path . resolve ( __dirname , './test-files/basic.htpasswd' ) ,
391
- } ,
392
- } ,
393
- } ) ;
394
- // Assert
395
- expect ( action ) . rejects . toThrow ( expected ) ;
396
- } ) ;
397
-
398
350
it . each ( [
399
351
[ 'username' , { 'users-list' : userLists } ] ,
400
352
[ 'password' , { 'users-list' : userLists } ] ,
@@ -430,7 +382,7 @@ describe('Test http basic authenticator', () => {
430
382
} ,
431
383
} ;
432
384
// Act
433
- const action = authIdentity ( ctx , {
385
+ const action = getTokenInfo ( ctx , {
434
386
basic : options ,
435
387
} ) ;
436
388
// Assert
0 commit comments