Skip to content

Commit e36dc32

Browse files
committed
changed spec to accommodate alma using ES256 instead of RS256 algorithm
1 parent cd3d043 commit e36dc32

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

spec/controllers/concerns/alma_jwt_validator_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88
let(:jwks_url) { "https://api-na.hosted.exlibrisgroup.com/auth/#{alma_institution_code}/jwks.json" }
99
let(:expected_iss) { 'Prima' }
1010

11-
# Generate an RSA key pair for testing
12-
let(:rsa_key) { OpenSSL::PKey::RSA.new(2048) }
11+
# Generate an EC key pair for testing
12+
let(:ec_key) { OpenSSL::PKey::EC.generate('prime256v1') }
1313
let(:kid) { 'test-key-id' }
1414
let(:test_payload) { { 'userName' => '10335026', 'iss' => expected_iss } }
1515

16-
# Helper to create JWK hash from RSA key using JWT::JWK
16+
# Helper to create JWK hash from EC key using JWT::JWK
1717
def create_jwk_hash(key, kid)
1818
jwk = JWT::JWK.new(key, kid: kid)
1919
jwk.export
2020
end
2121

2222
# Helper to generate a valid JWT
23-
def generate_jwt(payload, key, kid, algorithm = 'RS256')
23+
def generate_jwt(payload, key, kid, algorithm = 'ES256')
2424
header = { 'kid' => kid, 'alg' => algorithm }
2525
JWT.encode(payload, key, algorithm, header)
2626
end
2727

2828
before do
29-
jwk = create_jwk_hash(rsa_key, kid)
29+
jwk = create_jwk_hash(ec_key, kid)
3030

3131
stub_request(:get, jwks_url)
3232
.to_return(
@@ -39,7 +39,7 @@ def generate_jwt(payload, key, kid, algorithm = 'RS256')
3939
describe '.decode_and_verify_jwt' do
4040
context 'with a valid JWT' do
4141
it 'returns the decoded payload' do
42-
token = generate_jwt(test_payload, rsa_key, kid)
42+
token = generate_jwt(test_payload, ec_key, kid)
4343
result = AlmaJwtValidator.decode_and_verify_jwt(token)
4444

4545
expect(result).to be_an(Array)
@@ -51,7 +51,7 @@ def generate_jwt(payload, key, kid, algorithm = 'RS256')
5151
context 'with an invalid signature' do
5252
it 'raises JWT::DecodeError' do
5353
# Generate a token with a different key
54-
different_key = OpenSSL::PKey::RSA.new(2048)
54+
different_key = OpenSSL::PKey::EC.generate('prime256v1')
5555
token = generate_jwt(test_payload, different_key, kid)
5656

5757
expect do
@@ -62,7 +62,7 @@ def generate_jwt(payload, key, kid, algorithm = 'RS256')
6262

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

6767
expect do
6868
AlmaJwtValidator.decode_and_verify_jwt(token)
@@ -81,7 +81,7 @@ def generate_jwt(payload, key, kid, algorithm = 'RS256')
8181
context 'when JWKS endpoint is unreachable' do
8282
it 'raises an error' do
8383
stub_request(:get, jwks_url).to_return(status: 500)
84-
token = generate_jwt(test_payload, rsa_key, kid)
84+
token = generate_jwt(test_payload, ec_key, kid)
8585

8686
expect do
8787
AlmaJwtValidator.decode_and_verify_jwt(token)

0 commit comments

Comments
 (0)