|
54 | 54 | end |
55 | 55 | end |
56 | 56 | 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 |
57 | 85 | end |
58 | 86 |
|
59 | 87 | describe '.payload_errors' do |
|
72 | 100 | end |
73 | 101 | end |
74 | 102 | 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 |
75 | 120 | end |
76 | 121 | end |
0 commit comments