@@ -57,7 +57,6 @@ vi.mock("@/features/debugger/services/debugger.store", () => ({
5757// Typed Mocks
5858const viExtractJwt = vi . mocked ( extractJwt ) ;
5959const viValidateSymmetricSecret = vi . mocked ( validateSymmetricSecret ) ;
60- const viValidateAsymmetricKey = vi . mocked ( validateAsymmetricKey ) ;
6160const viValidateJwtFormat = vi . mocked ( validateJwtFormat ) ;
6261const viIsHmacAlg = vi . mocked ( isHmacAlg ) ;
6362const viIsDigitalSignatureAlg = vi . mocked ( isDigitalSignatureAlg ) ;
@@ -71,7 +70,7 @@ const viParseStringIntoValidJsonObject = vi.mocked(
7170const viVerifyMACedJwt = vi . mocked ( verifyMACedJwt ) ;
7271const viDownloadPublicKeyIfPossible = vi . mocked ( downloadPublicKeyIfPossible ) ;
7372
74- describe ( "TokenDecoderService. handleJwtChange" , ( ) => {
73+ describe ( "handleJwtChange" , ( ) => {
7574 const mockJwt =
7675 "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" ;
7776 const mockParams = {
@@ -109,7 +108,6 @@ describe("TokenDecoderService.handleJwtChange", () => {
109108 ) ;
110109 viIsSupportedAlg . mockReturnValue ( true ) ;
111110 viValidateSymmetricSecret . mockResolvedValue ( ok ( new Uint8Array ( [ 1 , 2 , 3 ] ) ) ) ;
112- viValidateAsymmetricKey . mockResolvedValue ( ok ( { } as CryptoKey ) ) ;
113111 viGetStringifiedHeaderAndPayload . mockReturnValue (
114112 ok ( {
115113 header : mockStringifiedHeader ,
@@ -128,6 +126,31 @@ describe("TokenDecoderService.handleJwtChange", () => {
128126 ) ;
129127 } ) ;
130128
129+ it ( "should return a warning if the new token is empty" , async ( ) => {
130+ const error = {
131+ message : "JWT must not be empty." ,
132+ input : DebuggerInputValues . JWT ,
133+ task : DebuggerTaskValues . DECODE ,
134+ } ;
135+
136+ viExtractJwt . mockReturnValue ( "" ) ;
137+ viValidateJwtFormat . mockReturnValue ( err ( error ) ) ;
138+
139+ const result = await TokenDecoderService . handleJwtChange ( {
140+ ...mockParams ,
141+ newToken : " " ,
142+ } ) ;
143+
144+ expect ( viExtractJwt ) . toHaveBeenCalledWith ( " " ) ;
145+ expect ( result . jwt ) . toBe ( "" ) ;
146+ expect ( result . signatureStatus ) . toBe ( JwtSignatureStatusValues . WARNING ) ;
147+ expect ( result . signatureWarnings ) . toEqual ( [
148+ StringValues . editor . signatureWarning ,
149+ ] ) ;
150+ expect ( result . decodedHeader ) . toBe ( "" ) ;
151+ expect ( result . decodedPayload ) . toBe ( "" ) ;
152+ } ) ;
153+
131154 it ( "should return decoding errors if JWT format is invalid" , async ( ) => {
132155 const error = {
133156 message : "Invalid format" ,
0 commit comments