Commit b8c82b9a authored by Markus Koller's avatar Markus Koller

Align naming for "secret" fields in integrations

We previously called these "password fields" because they use
`type: 'password'`, but this is really just for the frontend form,
and not all secret fields are passwords as such.

We also considered "sensitive" and "confidential", but these both are
a bit vague and longer to type.
parent aa51eadd
...@@ -89,7 +89,7 @@ module Integrations ...@@ -89,7 +89,7 @@ module Integrations
param_values = return_value[:integration] param_values = return_value[:integration]
if param_values.is_a?(ActionController::Parameters) if param_values.is_a?(ActionController::Parameters)
integration.password_fields.each do |param| integration.secret_fields.each do |param|
param_values.delete(param) if param_values[param].blank? param_values.delete(param) if param_values[param].blank?
end end
end end
......
...@@ -428,7 +428,9 @@ class Integration < ApplicationRecord ...@@ -428,7 +428,9 @@ class Integration < ApplicationRecord
[] []
end end
def password_fields # TODO: Once all integrations use `Integrations::Field` we can
# use `#secret?` here.
def secret_fields
fields.select { |f| f[:type] == 'password' }.pluck(:name) fields.select { |f| f[:type] == 'password' }.pluck(:name)
end end
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module Integrations module Integrations
class Field class Field
SENSITIVE_NAME = %r/token|key|password|passphrase|secret/.freeze SECRET_NAME = %r/token|key|password|passphrase|secret/.freeze
ATTRIBUTES = %i[ ATTRIBUTES = %i[
section type placeholder required choices value checkbox_label section type placeholder required choices value checkbox_label
...@@ -17,7 +17,7 @@ module Integrations ...@@ -17,7 +17,7 @@ module Integrations
def initialize(name:, type: 'text', api_only: false, **attributes) def initialize(name:, type: 'text', api_only: false, **attributes)
@name = name.to_s.freeze @name = name.to_s.freeze
attributes[:type] = SENSITIVE_NAME.match?(@name) ? 'password' : type attributes[:type] = SECRET_NAME.match?(@name) ? 'password' : type
attributes[:api_only] = api_only attributes[:api_only] = api_only
@attributes = attributes.freeze @attributes = attributes.freeze
end end
...@@ -31,7 +31,7 @@ module Integrations ...@@ -31,7 +31,7 @@ module Integrations
value value
end end
def sensitive? def secret?
@attributes[:type] == 'password' @attributes[:type] == 'password'
end end
......
...@@ -720,7 +720,7 @@ RSpec.describe Integration do ...@@ -720,7 +720,7 @@ RSpec.describe Integration do
describe '#api_field_names' do describe '#api_field_names' do
shared_examples 'api field names' do shared_examples 'api field names' do
it 'filters out sensitive fields' do it 'filters out secret fields' do
safe_fields = %w[some_safe_field safe_field url trojan_gift] safe_fields = %w[some_safe_field safe_field url trojan_gift]
expect(fake_integration.new).to have_attributes( expect(fake_integration.new).to have_attributes(
...@@ -857,7 +857,7 @@ RSpec.describe Integration do ...@@ -857,7 +857,7 @@ RSpec.describe Integration do
end end
end end
describe '#password_fields' do describe '#secret_fields' do
it 'returns all fields with type `password`' do it 'returns all fields with type `password`' do
allow(subject).to receive(:fields).and_return([ allow(subject).to receive(:fields).and_return([
{ name: 'password', type: 'password' }, { name: 'password', type: 'password' },
...@@ -865,11 +865,11 @@ RSpec.describe Integration do ...@@ -865,11 +865,11 @@ RSpec.describe Integration do
{ name: 'public', type: 'text' } { name: 'public', type: 'text' }
]) ])
expect(subject.password_fields).to match_array(%w[password secret]) expect(subject.secret_fields).to match_array(%w[password secret])
end end
it 'returns an empty array if no password fields exist' do it 'returns an empty array if no secret fields exist' do
expect(subject.password_fields).to eq([]) expect(subject.secret_fields).to eq([])
end end
end end
......
...@@ -84,17 +84,17 @@ RSpec.describe ::Integrations::Field do ...@@ -84,17 +84,17 @@ RSpec.describe ::Integrations::Field do
end end
end end
describe '#sensitive' do describe '#secret?' do
context 'when empty' do context 'when empty' do
it { is_expected.not_to be_sensitive } it { is_expected.not_to be_secret }
end end
context 'when a password field' do context 'when a secret field' do
before do before do
attrs[:type] = 'password' attrs[:type] = 'password'
end end
it { is_expected.to be_sensitive } it { is_expected.to be_secret }
end end
%w[token api_token api_key secret_key secret_sauce password passphrase].each do |name| %w[token api_token api_key secret_key secret_sauce password passphrase].each do |name|
...@@ -103,7 +103,7 @@ RSpec.describe ::Integrations::Field do ...@@ -103,7 +103,7 @@ RSpec.describe ::Integrations::Field do
attrs[:name] = name attrs[:name] = name
end end
it { is_expected.to be_sensitive } it { is_expected.to be_secret }
end end
end end
...@@ -112,7 +112,7 @@ RSpec.describe ::Integrations::Field do ...@@ -112,7 +112,7 @@ RSpec.describe ::Integrations::Field do
attrs[:name] = :url attrs[:name] = :url
end end
it { is_expected.not_to be_sensitive } it { is_expected.not_to be_secret }
end end
end end
end end
...@@ -378,15 +378,15 @@ RSpec.describe API::Integrations do ...@@ -378,15 +378,15 @@ RSpec.describe API::Integrations do
def assert_correct_response_fields(response_keys, integration) def assert_correct_response_fields(response_keys, integration)
assert_fields_match_integration(response_keys, integration) assert_fields_match_integration(response_keys, integration)
assert_password_fields_filtered(response_keys, integration) assert_secret_fields_filtered(response_keys, integration)
end end
def assert_fields_match_integration(response_keys, integration) def assert_fields_match_integration(response_keys, integration)
expect(response_keys).to match_array(integration.api_field_names) expect(response_keys).to match_array(integration.api_field_names)
end end
def assert_password_fields_filtered(response_keys, integration) def assert_secret_fields_filtered(response_keys, integration)
expect(response_keys).not_to include(*integration.password_fields) expect(response_keys).not_to include(*integration.secret_fields)
end end
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