Skip to content

Commit

Permalink
create tests for verify claims using options with values set to true …
Browse files Browse the repository at this point in the history
…and false
  • Loading branch information
yasonk authored and anakinj committed Feb 4, 2021
1 parent 10b7dd4 commit cba7d08
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions spec/jwt/verify_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,30 @@ module JWT # rubocop:disable Metrics/ModuleLength
Verify.verify_sub(base_payload.merge('sub' => sub), options.merge(sub: sub))
end
end

context '.verify_claims' do
let(:fail_verifications_options) { { iss: 'mismatched-issuer', aud: 'no-match', sub: 'some subject' } }
let(:fail_verifications_payload) { {
'exp' => (Time.now.to_i - 50),
'jti' => ' ',
'iss' => 'some-issuer',
'nbf' => (Time.now.to_i + 50),
'iat' => 'not a number',
'sub' => 'not-a-match' } }

%w[verify_aud verify_expiration verify_iat verify_iss verify_jti verify_not_before verify_sub].each do |method|
let(:payload) { base_payload.merge(fail_verifications_payload) }
it "must skip verification when #{method} option is set to false" do
Verify.verify_claims(payload, options.merge("#{method}" => false))
end

it "must raise error when #{method} option is set to true" do
expect do
Verify.verify_claims(payload, options.merge("#{method}" => true).merge(fail_verifications_options))
end.to raise_error
end
end

end
end
end

0 comments on commit cba7d08

Please sign in to comment.