Skip to content

Commit 3792e52

Browse files
committed
For JWT signature authorization. changed EXPECTED_ISS and removed rescue block
1 parent a626e32 commit 3792e52

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

app/controllers/concerns/alma_jwt_validator.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
module AlmaJwtValidator
66
JWKS_URL = 'https://api-na.hosted.exlibrisgroup.com/auth/01UCS_BER/jwks.json'.freeze
7-
EXPECTED_ISS = 'https://api-na.hosted.exlibrisgroup.com/auth/01UCS_BER'.freeze
7+
EXPECTED_ISS = 'Prima'.freeze
88

99
module_function
1010

@@ -16,7 +16,6 @@ def jwk_set
1616
end
1717
end
1818

19-
# rubocop:disable Metrics/MethodLength
2019
def decode_and_verify_jwt(token)
2120
options = {
2221
algorithm: 'RS256',
@@ -28,8 +27,5 @@ def decode_and_verify_jwt(token)
2827
}
2928

3029
JWT.decode(token, nil, true, options)
31-
rescue JWT::DecodeError => e
32-
raise JWT::VerificationError, e.message
3330
end
34-
# rubocop:enable Metrics/MethodLength
3531
end

spec/controllers/concerns/alma_jwt_validator_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
describe AlmaJwtValidator do
77
let(:alma_institution_code) { '01UCS_BER' }
88
let(:jwks_url) { "https://api-na.hosted.exlibrisgroup.com/auth/#{alma_institution_code}/jwks.json" }
9-
let(:expected_iss) { "https://api-na.hosted.exlibrisgroup.com/auth/#{alma_institution_code}" }
9+
let(:expected_iss) { 'Prima' }
1010

1111
# Generate an RSA key pair for testing
1212
let(:rsa_key) { OpenSSL::PKey::RSA.new(2048) }
@@ -49,32 +49,32 @@ def generate_jwt(payload, key, kid, algorithm = 'RS256')
4949
end
5050

5151
context 'with an invalid signature' do
52-
it 'raises JWT::VerificationError' do
52+
it 'raises JWT::DecodeError' do
5353
# Generate a token with a different key
5454
different_key = OpenSSL::PKey::RSA.new(2048)
5555
token = generate_jwt(test_payload, different_key, kid)
5656

5757
expect do
5858
AlmaJwtValidator.decode_and_verify_jwt(token)
59-
end.to raise_error(JWT::VerificationError)
59+
end.to raise_error(JWT::DecodeError)
6060
end
6161
end
6262

6363
context 'with an unknown key id' do
64-
it 'raises JWT::VerificationError' do
64+
it 'raises JWT::DecodeError' do
6565
token = generate_jwt(test_payload, rsa_key, 'unknown-kid')
6666

6767
expect do
6868
AlmaJwtValidator.decode_and_verify_jwt(token)
69-
end.to raise_error(JWT::VerificationError)
69+
end.to raise_error(JWT::DecodeError)
7070
end
7171
end
7272

7373
context 'with a malformed JWT' do
74-
it 'raises JWT::VerificationError' do
74+
it 'raises JWT::DecodeError' do
7575
expect do
7676
AlmaJwtValidator.decode_and_verify_jwt('not.a.jwt')
77-
end.to raise_error(JWT::VerificationError)
77+
end.to raise_error(JWT::DecodeError)
7878
end
7979
end
8080

0 commit comments

Comments
 (0)