|
44 | 44 |
|
45 | 45 | context 'alg: NONE' do
|
46 | 46 | let(:alg) { 'none' }
|
| 47 | + let(:sig) { 'kWOVtIOpWcG7JnyJG0qOkTDbOy636XrrQhMm_8JrRQ8' } |
47 | 48 |
|
48 | 49 | it 'should generate a valid token' do
|
49 | 50 | token = JWT.encode payload, nil, alg
|
50 | 51 |
|
51 | 52 | expect(token).to eq data['NONE']
|
52 | 53 | end
|
53 | 54 |
|
| 55 | + it 'with key should raise JWT::EncodeError' do |
| 56 | + expect do |
| 57 | + JWT.encode payload, data[:secret], alg |
| 58 | + end.to raise_error JWT::EncodeError, "Signing key not supported for Unsecured JWT" |
| 59 | + end |
| 60 | + |
54 | 61 | it 'should decode a valid token' do
|
55 | 62 | jwt_payload, header = JWT.decode data['NONE'], nil, false
|
56 | 63 |
|
57 | 64 | expect(header['alg']).to eq alg
|
58 | 65 | expect(jwt_payload).to eq payload
|
59 | 66 | end
|
| 67 | + |
| 68 | + it 'should decode and verify a valid token' do |
| 69 | + jwt_payload, header = JWT.decode data['NONE'], nil, true, algorithm: alg |
| 70 | + |
| 71 | + expect(header['alg']).to eq alg |
| 72 | + expect(jwt_payload).to eq payload |
| 73 | + end |
| 74 | + |
| 75 | + it 'with signature should raise JWT::VerificationError' do |
| 76 | + expect do |
| 77 | + JWT.decode data['NONE'] + sig, nil, true, algorithm: alg |
| 78 | + end.to raise_error JWT::VerificationError, "Signature should be empty for Unsecured JWT" |
| 79 | + end |
| 80 | + |
| 81 | + it 'with key should raise JWT::VerificationError' do |
| 82 | + expect do |
| 83 | + JWT.decode data['NONE'], data[:secret], true, algorithm: alg |
| 84 | + end.to raise_error JWT::VerificationError, "Signing key not supported for Unsecured JWT" |
| 85 | + end |
60 | 86 | end
|
61 | 87 |
|
62 | 88 | context 'payload validation' do
|
|
0 commit comments