Skip to content

Commit 5144e6a

Browse files
committed
More advanced test
1 parent 2ac5e61 commit 5144e6a

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

spec/jwt/claims_spec.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,34 @@
5454
end
5555
end
5656
end
57+
58+
context 'various types of params' do
59+
context 'when payload is missing most of the claims' do
60+
it 'raises an error' do
61+
expect do
62+
described_class.verify_payload!(payload,
63+
:nbf,
64+
iss: ['www.host.com', 'https://other.host.com'].freeze,
65+
aud: 'aud',
66+
exp: { leeway: 10 })
67+
end.to raise_error(JWT::InvalidIssuerError)
68+
end
69+
end
70+
71+
context 'when payload has everything that is expected of it' do
72+
let(:payload) { { 'iss' => 'www.host.com', 'aud' => 'audience', 'exp' => Time.now.to_i - 10, 'pay' => 'load' } }
73+
74+
it 'does not raise' do
75+
expect do
76+
described_class.verify_payload!(payload,
77+
:nbf,
78+
iss: ['www.host.com', 'https://other.host.com'].freeze,
79+
aud: 'audience',
80+
exp: { leeway: 11 })
81+
end.not_to raise_error
82+
end
83+
end
84+
end
5785
end
5886

5987
describe '.payload_errors' do
@@ -72,5 +100,22 @@
72100
end
73101
end
74102
end
103+
104+
context 'various types of params' do
105+
let(:payload) { { 'exp' => Time.now.to_i - 10, 'pay' => 'load' } }
106+
107+
context 'when payload is most of the claims' do
108+
it 'raises an error' do
109+
messages = described_class.payload_errors(payload,
110+
:nbf,
111+
iss: ['www.host.com', 'https://other.host.com'].freeze,
112+
aud: 'aud',
113+
exp: { leeway: 10 }).map(&:message)
114+
expect(messages).to eq(['Invalid issuer. Expected ["www.host.com", "https://other.host.com"], received <none>',
115+
'Invalid audience. Expected aud, received <none>',
116+
'Signature has expired'])
117+
end
118+
end
119+
end
75120
end
76121
end

0 commit comments

Comments
 (0)