Skip to content
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
20 changes: 11 additions & 9 deletions spec/services/inherited_proofing/va/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,15 @@
end

RSpec.describe InheritedProofing::Va::Service do
include_context 'va_api_context'
include_context 'va_user_context'

subject(:service) { described_class.new auth_code }

before do
allow(service).to receive(:private_key).and_return(private_key)
end

let(:auth_code) {}
let(:private_key) { private_key_from_store_or(file_name: 'va_ip.key') }
let(:payload) { { inherited_proofing_auth: auth_code, exp: 1.day.from_now.to_i } }
let(:jwt_token) { JWT.encode(payload, private_key, 'RS256') }
let(:request_uri) {
"#{InheritedProofing::Va::Service::BASE_URI}/inherited_proofing/user_attributes"
}
let(:request_headers) { { Authorization: "Bearer #{jwt_token}" } }

it { respond_to :execute }

it do
Expand All @@ -41,6 +35,14 @@

expect(stub).to have_been_requested.once
end

it 'decrypts the response' do
stub_request(:get, request_uri).
with(headers: request_headers).
to_return(status: 200, body: encrypted_user_attributes, headers: {})

expect(service.execute).to eq user_attributes
end
end

context 'when the auth code is invalid' do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"data":"eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.IL_uTLpwR3ZoDQKuRY_clxK1AmrEnf3rCREIj8XGQ-iA7NxCiYfZ2CxuXFOTIzFbKXjcNYT1F56bCUuPwSmHNt88AGumB3RcskR6POfBu8EcjK2CI6myycGuQwm_1Dp9Vi55TQpSFRy5Bld7IR0gbk4ju0qTVSeH59-AyBGr0w07vojdHcPe-SDWEC1pG0_4iyVg0x2wOFAh6kIjMJ04sJYB4e7uW8hEI7lSwDLpiW-8KsjGhwCVIkUGPw7XKtLiWo1U_nXSragpG-E6XRx0Hn3YckSwEAMTATeZZPJr0TAAMO_jtukL0e7_ApwsCI-sEdI035_4befLlDnuz1QFJg.oLmsRlZKFlL_3Th4.YumiTPq6y8jyCpVwuSpqsd8iWQ_AqEN81v8pV9lB2dPb6po03aj05K361IWmWfB3gXir--L3nPpUdlFFkxF1X12QVkpfmH03kj01Zoaq9hZcQvY7d4QoOkMNkdONNFZ3_sp-4-11m5ki2TpD1AidkLe7AIaSvBvhYOq0TC-0veLwRvp5234-XyDq9o5hLogzUa3G1BxcZO_TxpS5IhV4CzJ2a-o_ymSgUULDjrAty23XMiqXxTMFbVCpMDrvgGTX2TYOYx0PngjySlir6Zf4WjKhvFBOd34hvx2MUYTEGPw.UcPA0owzraT7ckc1cRDzeg"}
15 changes: 15 additions & 0 deletions spec/support/shared_contexts/inherited_proofing/va_api_context.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
RSpec.shared_context 'va_api_context' do
# Sample mocked API call:
# stub_request(:get, request_uri).
# with(headers: request_headers).
# to_return(status: 200, body: '{}', headers: {})

let(:auth_code) { 'mocked-auth-code-for-testing' }
let(:private_key) { private_key_from_store_or(file_name: 'empty.key') }
let(:payload) { { inherited_proofing_auth: auth_code, exp: 1.day.from_now.to_i } }
let(:jwt_token) { JWT.encode(payload, private_key, 'RS256') }
let(:request_uri) {
"#{InheritedProofing::Va::Service::BASE_URI}/inherited_proofing/user_attributes"
}
let(:request_headers) { { Authorization: "Bearer #{jwt_token}" } }
end
18 changes: 18 additions & 0 deletions spec/support/shared_contexts/inherited_proofing/va_user_context.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
RSpec.shared_context 'va_user_context' do
# As given to us from VA
let(:user_attributes) {
{ first_name: 'Fakey',
last_name: 'Fakerson',
address: { street: '123 Fake St',
street2: 'Apt 235',
city: 'Faketown',
state: 'WA',
country: nil,
zip: '98037' },
phone: '2063119187',
birth_date: '2022-1-31',
ssn: '123456789' }
}
# Encrypted with AppArtifacts.store.oidc_private_key for testing
let(:encrypted_user_attributes) { File.read("#{__dir__}/encrypted_user_attributes.json") }
end