Skip to content

Commit

Permalink
verify_claims test shouldnt be within the verify_sub test
Browse files Browse the repository at this point in the history
  • Loading branch information
andyjdavis authored and anakinj committed Jul 9, 2021
1 parent c444ac9 commit dbf9bfd
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions spec/jwt/verify_spec.rb
Expand Up @@ -220,31 +220,31 @@
it 'must allow a matching sub' do
described_class.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'
}
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
described_class.verify_claims(payload, options.merge(method => false))
end

%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
described_class.verify_claims(payload, options.merge(method => false))
end

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

0 comments on commit dbf9bfd

Please sign in to comment.