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

71999 scour payload #16308

Merged
merged 9 commits into from
Apr 16, 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
27 changes: 25 additions & 2 deletions modules/check_in/app/services/check_in/map/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,40 @@ def initialize
@settings = Settings.check_in.map_api
end

def deep_analyze_and_modify(obj)
case obj
when Hash
obj.each do |key, value|
if key == :system && value.is_a?(String)
obj[key] = value.gsub('https://va.gov', '')
else
deep_analyze_and_modify(value)
end
end
when Array
obj.each do |value|
deep_analyze_and_modify(value)
end
end
end

##
# HTTP GET call to get the appointment data from MAP
#
# @return [Faraday::Response]
#
def appointments(token:, patient_icn:, query_params:)
connection.post("/vaos/v1/patients/#{patient_icn}/appointments?#{query_params}") do |req|
response = connection.post("/vaos/v1/patients/#{patient_icn}/appointments?#{query_params}") do |req|
req.headers = default_headers.merge('X-VAMF-JWT' => token)
end
deep_analyze_and_modify(response)
response
rescue => e
Faraday::Response.new(body: e.original_body, status: e.original_status)
if e.respond_to?(:original_body) && e.respond_to?(:original_status)
Faraday::Response.new(body: e.original_body, status: e.original_status)
else
raise e
end
end

private
Expand Down
47 changes: 46 additions & 1 deletion modules/check_in/spec/services/check_in/map/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
id: '180765',
identifier: [
{
system: 'Appointment/',
system: 'https://va.gov/Appointment/',
value: '413938333130383735'
}
],
Expand Down Expand Up @@ -68,6 +68,51 @@
end
end

context 'when appointments service returns success response takes out https://va.gov' do
let(:appointments_response) do
{
data: [
{
id: '180765',
identifier: [
{
system: 'https://va.gov/Appointment/',
value: '413938333130383735'
}
],
kind: 'clinic',
status: 'booked',
serviceType: 'amputation',
patientIcn: :icn,
locationId: '983GC',
clinic: '1081',
start: '2023-11-02T17:12:30.174Z',
end: '2023-12-12T17:12:30.174Z',
minutesDuration: 30,
extension: {
preCheckinAllowed: true,
eCheckinAllowed: true
}
}
]
}
end

before do
allow_any_instance_of(Faraday::Connection).to receive(:post).with(anything).and_return(appointments_response)
end

it 'strips https://va.gov from any system property in the response' do
response = subject.appointments(token: jwt_token, patient_icn: icn, query_params:)
response[:data].each do |appointment|
appointment[:identifier].each do |identifier|
puts identifier[:system]
expect(identifier[:system]).not_to start_with('https://va.gov')
end
end
end
end

context 'when appointments service returns a 500 error response' do
let(:error_msg) do
{
Expand Down
Loading