Skip to content

Commit

Permalink
Merge pull request #1239 from agrare/allow_configuration_script_paylo…
Browse files Browse the repository at this point in the history
…ads_credentials_to_be_shown

Allow configuration_script_payloads#credentials to be shown

(cherry picked from commit 39e5ed9)
  • Loading branch information
kbrock authored and Fryguy committed Sep 27, 2023
1 parent 2b9b841 commit a430cff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/controllers/api/configuration_script_payloads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ module Api
class ConfigurationScriptPayloadsController < BaseController
include Subcollections::Authentications

def api_resource_action_options
# ConfigurationScriptPayloads do not have any passwords stored directly
# in the record, they reference the Authentication model via the
# credentials jsonb mapping. The names of these mappings are user defined
# and can include e.g. "api_password" => {"credential_ref" => ..} and this
# entire key would be removed from the payload.
#
# Since there aren't any encrypted attributes in this record it is safe
# to include encrypted attributes in the payload response.
%w[include_encrypted_attributes]
end

def edit_resource(type, id, data)
resource = resource_search(id, type)

Expand Down
17 changes: 16 additions & 1 deletion spec/requests/configuration_script_payloads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,22 @@
it "adds the authentication to the configuration_script_payload.authentications" do
api_basic_authorize collection_action_identifier(:configuration_script_payloads, :edit, :post)

post(api_configuration_script_payloads_url, :params => {:action => 'edit', :resources => [{:id => script_payload.id, :name => 'foo', :credentials => {"my-cred" => {"credential_ref" => "my-credential", "credential_field" => "userid"}}}]})
expected_credentials = {
"my-cred-user" => {"credential_ref" => "my-credential", "credential_field" => "userid"},
"my-cred-password" => {"credential_ref" => "my-credential", "credential_field" => "password"},
}

resource = {
:id => script_payload.id,
:name => 'foo',
:credentials => expected_credentials
}

post(api_configuration_script_payloads_url, :params => {:action => 'edit', :resources => [resource]})

expect(response.parsed_body["results"].first).to include(
"credentials" => expected_credentials
)
expect(script_payload.reload.authentications).to include(authentication)
end

Expand Down

0 comments on commit a430cff

Please sign in to comment.