Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verify_claims test shouldnt be within the verify_sub test #431

Merged
merged 1 commit into from Jul 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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