11import jwtVerify from "jose/jwt/verify" ;
2+ import { isValidAthClaim } from "../src/algorithm/isValidAthClaim" ;
23import { verify } from "../src/lib/DPoP" ;
3- import type { DPoPToken } from "../src/type" ;
4+ import type { DPoPToken , DPoPTokenPayload } from "../src/type" ;
45import { encodeToken } from "./fixture/EncodeToken" ;
56
67/* eslint-disable @typescript-eslint/no-explicit-any */
78jest . mock ( "jose/jwt/verify" ) ;
9+ jest . mock ( "../src/algorithm/isValidAthClaim" ) ;
810
911const dpop : DPoPToken = {
1012 header : {
@@ -27,6 +29,14 @@ const dpop: DPoPToken = {
2729 "lNhmpAX1WwmpBvwhok4E74kWCiGBNdavjLAeevGy32H3dbF0Jbri69Nm2ukkwb-uyUI4AUg1JSskfWIyo4UCbQ" ,
2830} ;
2931
32+ const dpopPayloadWithAth : DPoPTokenPayload = {
33+ jti : "e1j3V_bKic8-LAEB" ,
34+ htm : "GET" ,
35+ htu : "https://resource.example.org/protectedresource" ,
36+ iat : 1562262618 ,
37+ ath : "bla" ,
38+ } ;
39+
3040const dpopRSA : DPoPToken = {
3141 header : {
3242 typ : "dpop+jwt" ,
@@ -79,6 +89,54 @@ describe("DPoP proof", () => {
7989 ) . toStrictEqual ( dpop ) ;
8090 } ) ;
8191
92+ it ( "Checks conforming proof with EC Key and ath claim" , async ( ) => {
93+ ( jwtVerify as jest . Mock ) . mockResolvedValueOnce ( {
94+ payload : dpopPayloadWithAth ,
95+ protectedHeader : dpop . header ,
96+ } ) ;
97+ ( isValidAthClaim as jest . Mock ) . mockReturnValueOnce ( true ) ;
98+
99+ expect (
100+ await verify (
101+ encodeToken ( dpop ) ,
102+ {
103+ payload : {
104+ cnf : { jkt : "0ZcOCORZNYy-DWpqq30jZyJGHTN0d2HglBV3uiguA4I" } ,
105+ } ,
106+ } as any ,
107+ "GET" ,
108+ "https://resource.example.org/protectedresource" ,
109+ ( ) => false
110+ )
111+ ) . toStrictEqual ( {
112+ header : dpop . header ,
113+ payload : dpopPayloadWithAth ,
114+ signature : dpop . signature ,
115+ } ) ;
116+ } ) ;
117+
118+ it ( "Throws on invalid ath claim" , async ( ) => {
119+ ( jwtVerify as jest . Mock ) . mockResolvedValueOnce ( {
120+ payload : dpopPayloadWithAth ,
121+ protectedHeader : dpop . header ,
122+ } ) ;
123+ ( isValidAthClaim as jest . Mock ) . mockReturnValueOnce ( false ) ;
124+
125+ await expect (
126+ verify (
127+ encodeToken ( dpop ) ,
128+ {
129+ payload : {
130+ cnf : { jkt : "0ZcOCORZNYy-DWpqq30jZyJGHTN0d2HglBV3uiguA4I" } ,
131+ } ,
132+ } as any ,
133+ "GET" ,
134+ "https://resource.example.org/protectedresource" ,
135+ ( ) => false
136+ )
137+ ) . rejects . toThrow ( "Expected true, got:\nfalse" ) ;
138+ } ) ;
139+
82140 it ( "Checks conforming proof with RSA Key" , async ( ) => {
83141 ( jwtVerify as jest . Mock ) . mockResolvedValueOnce ( {
84142 payload : dpopRSA . payload ,
0 commit comments