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

96002 EPS Redis Client Implementation #19307

Merged
merged 16 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ development: &defaults
va_mobile_session_refresh_lock:
namespace: va-mobile-session-refresh-lock
each_ttl: 60
eps_access_token:
namespace: eps-access-token
each_ttl: 900 # 15 minutes
saml_request_tracker:
namespace: saml_request_tracker
each_ttl: 3600 # 1 hour
Expand Down
14 changes: 14 additions & 0 deletions modules/vaos/app/services/eps/access_token_store.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require 'common/models/redis_store'

module Eps
class AccessTokenStore < Common::RedisStore
redis_store REDIS_CONFIG[:eps_access_token][:namespace]
redis_ttl REDIS_CONFIG[:eps_access_token][:each_ttl]
redis_key :token_type

attribute :token_type
attribute :access_token
end
end
36 changes: 36 additions & 0 deletions modules/vaos/spec/services/eps/access_token_store_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require 'rails_helper'

describe Eps::AccessTokenStore do
subject { described_class }

let(:access_token) { 'test-access-token' }
let(:token_type) { 'jwt_bearer' }
let(:redis_key) { "eps-access-token:#{token_type}" }
let(:cache_data) { { token_type:, access_token: } }
let(:token_store_client) { subject.new(token_type:, access_token:) }

before do
token_store_client.save
end

describe '#save' do
it 'saves the value in cache' do
token = Oj.load($redis.get(redis_key))[:access_token]
expect(token).to eq(access_token)
end
end

describe '#ttl' do
it 'sets cache data expire to time from config file' do
expect($redis.ttl(redis_key)).to eq(900)
end
end

describe '#find' do
it 'gets data from cache' do
expect(Oj.load($redis.get(redis_key))).to eq(cache_data)
end
end
end
Loading