@@ -51,11 +51,19 @@ def create_nested(inner, algorithm:, key:)
5151 end
5252
5353 describe '#last' do
54- it 'returns the innermost token ' do
54+ it 'raises DecodeError before verification ' do
5555 nested_jwt = create_nested ( inner_jwt , algorithm : 'HS256' , key : outer_secret )
5656 nested = described_class . new ( nested_jwt )
5757
58- expect ( nested . last . unverified_payload ) . to eq ( inner_payload )
58+ expect { nested . last } . to raise_error ( JWT ::DecodeError , /Verify the token before/ )
59+ end
60+
61+ it 'returns the innermost token after verification' do
62+ nested_jwt = create_nested ( inner_jwt , algorithm : 'HS256' , key : outer_secret )
63+ nested = described_class . new ( nested_jwt )
64+ nested . verify! ( algorithm : 'HS256' , key : [ outer_secret , inner_secret ] )
65+
66+ expect ( nested . last . payload ) . to eq ( inner_payload )
5967 end
6068 end
6169
@@ -161,8 +169,9 @@ def create_nested(inner, algorithm:, key:)
161169 current = create_nested ( current , algorithm : 'HS256' , key : "key_#{ i } " )
162170 end
163171
172+ nested = described_class . new ( current )
164173 expect do
165- described_class . new ( current )
174+ nested . count
166175 end . to raise_error ( JWT ::DecodeError , /exceeds maximum depth/ )
167176 end
168177
@@ -171,11 +180,11 @@ def create_nested(inner, algorithm:, key:)
171180 level3 = create_nested ( level2 , algorithm : 'HS256' , key : 'key3' )
172181
173182 expect do
174- described_class . new ( level3 , max_depth : 2 )
183+ described_class . new ( level3 , max_depth : 2 ) . count
175184 end . to raise_error ( JWT ::DecodeError , 'Nested JWT exceeds maximum depth of 2' )
176185
177186 expect do
178- described_class . new ( level3 , max_depth : 5 )
187+ described_class . new ( level3 , max_depth : 5 ) . count
179188 end . not_to raise_error
180189 end
181190 end
0 commit comments