@@ -30,31 +30,31 @@ describe('PatRequestValidator', (): void => {
3030
3131 storage = {
3232 find : vi . fn ( ) . mockResolvedValue ( [ { expiration : Date . now ( ) + 5000 , registration : registrationId } ] ) ,
33+ findIds : vi . fn ( ) . mockResolvedValue ( [ registrationId ] ) ,
3334 get : vi . fn ( ) . mockResolvedValue ( { userId } ) ,
3435 } as any ;
3536
3637 validator = new PatRequestValidator ( storage as any ) ;
3738 } ) ;
3839
39- it ( 'returns the stored user as owner.' , async ( ) : Promise < void > => {
40- await expect ( validator . handle ( { request } ) ) . resolves . toEqual ( { owner : userId } ) ;
41- expect ( storage . find ) . toHaveBeenLastCalledWith ( PAT_STORAGE_TYPE , { pat } ) ;
42- expect ( storage . get ) . toHaveBeenLastCalledWith ( CLIENT_REGISTRATION_STORAGE_TYPE , registrationId ) ;
40+ it ( 'can only handle Bearer tokens.' , async ( ) : Promise < void > => {
41+ request . headers . authorization = 'Basic 1234' ;
42+ await expect ( validator . canHandle ( { request } ) ) . rejects . toThrow ( 'No Bearer Authorization header specified.' ) ;
4343 } ) ;
4444
45- it ( 'errors on non-Bearer tokens.' , async ( ) : Promise < void > => {
46- request . headers . authorization = 'Basic 1234' ;
47- await expect ( validator . handle ( { request } ) ) . rejects . toThrow ( 'No Bearer Authorization header specified .' ) ;
45+ it ( 'can only handle known tokens.' , async ( ) : Promise < void > => {
46+ storage . findIds . mockResolvedValueOnce ( [ ] ) ;
47+ await expect ( validator . canHandle ( { request } ) ) . rejects . toThrow ( 'Unknown PAT .' ) ;
4848 } ) ;
4949
50- it ( 'errors on non-Bearer tokens.' , async ( ) : Promise < void > => {
51- request . headers . authorization = 'Basic 1234' ;
52- await expect ( validator . handle ( { request } ) ) . rejects . toThrow ( 'No Bearer Authorization header specified.' ) ;
50+ it ( 'can handle known Bearer tokens.' , async ( ) : Promise < void > => {
51+ await expect ( validator . canHandle ( { request } ) ) . resolves . toBeUndefined ( ) ;
5352 } ) ;
5453
55- it ( 'errors if no matched token was found.' , async ( ) : Promise < void > => {
56- storage . find . mockResolvedValueOnce ( [ ] ) ;
57- await expect ( validator . handle ( { request } ) ) . rejects . toThrow ( 'Unknown PAT.' ) ;
54+ it ( 'returns the stored user as owner.' , async ( ) : Promise < void > => {
55+ await expect ( validator . handle ( { request } ) ) . resolves . toEqual ( { owner : userId } ) ;
56+ expect ( storage . find ) . toHaveBeenLastCalledWith ( PAT_STORAGE_TYPE , { pat } ) ;
57+ expect ( storage . get ) . toHaveBeenLastCalledWith ( CLIENT_REGISTRATION_STORAGE_TYPE , registrationId ) ;
5858 } ) ;
5959
6060 it ( 'errors if the PAT is expired.' , async ( ) : Promise < void > => {
0 commit comments