Commit 1b9c7769 authored by Alex Kalderimis's avatar Alex Kalderimis

Fix incorrect use of properties

This also uses a nicer implementation of `api_field_names`.

The test is changed to ensure that we are not just filtering for `safe`
or picking the last field.
parent 115beffe
...@@ -392,8 +392,7 @@ class Integration < ApplicationRecord ...@@ -392,8 +392,7 @@ class Integration < ApplicationRecord
end end
def api_field_names def api_field_names
fields.map { |field| field[:name] } fields.pluck(:name).grep_v(/password|token|key|title|description/)
.reject { |field_name| field_name =~ /(password|token|key|title|description)/ }
end end
def global_fields def global_fields
......
...@@ -710,30 +710,21 @@ RSpec.describe Integration do ...@@ -710,30 +710,21 @@ RSpec.describe Integration do
[ [
{ name: 'token' }, { name: 'token' },
{ name: 'api_token' }, { name: 'api_token' },
{ name: 'token_api' },
{ name: 'safe_token' },
{ name: 'key' }, { name: 'key' },
{ name: 'api_key' }, { name: 'api_key' },
{ name: 'password' }, { name: 'password' },
{ name: 'password_field' }, { name: 'password_field' },
{ name: 'some_safe_field' },
{ name: 'safe_field' } { name: 'safe_field' }
] ].shuffle
end end
end end
end end
let(:integration) do
fake_integration.new(properties: [
{ token: 'token-value' },
{ api_token: 'api_token-value' },
{ key: 'key-value' },
{ api_key: 'api_key-value' },
{ password: 'password-value' },
{ password_field: 'password_field-value' },
{ safe_field: 'safe_field-value' }
])
end
it 'filters out sensitive fields' do it 'filters out sensitive fields' do
expect(integration.api_field_names).to eq(['safe_field']) expect(fake_integration.new).to have_attributes(api_field_names: match_array(%w[some_safe_field safe_field]))
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment