11import { describe , expect , test } from 'vitest'
22import { Oauth2ServerErrorResponseError } from '../../error/Oauth2ServerErrorResponseError.js'
3- import { authorizationCodeGrantIdentifier , preAuthorizedCodeGrantIdentifier } from '../../z-grant-type.js'
3+ import {
4+ authorizationCodeGrantIdentifier ,
5+ preAuthorizedCodeGrantIdentifier ,
6+ refreshTokenGrantIdentifier ,
7+ } from '../../z-grant-type.js'
48import { parseAccessTokenRequest } from '../parse-access-token-request.js'
59
610describe ( 'Parse Access Token Request' , ( ) => {
@@ -47,7 +51,7 @@ describe('Parse Access Token Request', () => {
4751 ) . toThrow ( `The grant type 'something' is not supported` )
4852 } )
4953
50- test ( 'handles mising pre-authorized_code for pre-auth grant_type' , ( ) => {
54+ test ( 'handles missing pre-authorized_code for pre-auth grant_type' , ( ) => {
5155 expect ( ( ) =>
5256 parseAccessTokenRequest ( {
5357 accessTokenRequest : {
@@ -62,7 +66,7 @@ describe('Parse Access Token Request', () => {
6266 ) . toThrow ( `Missing required 'pre-authorized_code' for grant type '${ preAuthorizedCodeGrantIdentifier } '` )
6367 } )
6468
65- test ( 'handles mising code for authorization_code grant_type' , ( ) => {
69+ test ( 'handles missing code for authorization_code grant_type' , ( ) => {
6670 expect ( ( ) =>
6771 parseAccessTokenRequest ( {
6872 accessTokenRequest : {
@@ -168,7 +172,34 @@ describe('Parse Access Token Request', () => {
168172 } )
169173 } )
170174
171- test ( 'handles invalid dpop jwt' , ( ) => {
175+ test ( 'handles refresh token grant' , ( ) => {
176+ expect (
177+ parseAccessTokenRequest ( {
178+ accessTokenRequest : {
179+ grant_type : refreshTokenGrantIdentifier ,
180+ refresh_token : 'mamma-mia' ,
181+ } ,
182+ request : {
183+ headers : new Headers ( { } ) ,
184+ method : 'POST' ,
185+ url : 'https://request.com/token' ,
186+ } ,
187+ } )
188+ ) . toEqual ( {
189+ accessTokenRequest : {
190+ grant_type : refreshTokenGrantIdentifier ,
191+ refresh_token : 'mamma-mia' ,
192+ } ,
193+ grant : {
194+ grantType : refreshTokenGrantIdentifier ,
195+ refreshToken : 'mamma-mia' ,
196+ } ,
197+ dpopJwt : undefined ,
198+ pkceCodeVerifier : undefined ,
199+ } )
200+ } )
201+
202+ test ( 'handles invalid dpop jwt' , ( ) =>
172203 expect ( ( ) =>
173204 parseAccessTokenRequest ( {
174205 accessTokenRequest : {
@@ -193,10 +224,9 @@ describe('Parse Access Token Request', () => {
193224 error : 'invalid_dpop_proof' ,
194225 error_description : `Request contains a 'DPoP' header, but the value is not a valid DPoP jwt` ,
195226 } )
196- )
197- } )
227+ ) )
198228
199- test ( 'handles invalid client attestation jwt' , ( ) => {
229+ test ( 'handles invalid client attestation jwt' , ( ) =>
200230 expect ( ( ) =>
201231 parseAccessTokenRequest ( {
202232 accessTokenRequest : {
@@ -220,6 +250,5 @@ describe('Parse Access Token Request', () => {
220250 error_description :
221251 'Request contains client attestation header, but the values are not valid client attestation and client attestation PoP header.' ,
222252 } )
223- )
224- } )
253+ ) )
225254} )
0 commit comments