Skip to content

Commit

Permalink
Merge pull request #14319 from jntullo/enhancement/update_authentication
Browse files Browse the repository at this point in the history
Edit Authentications API
  • Loading branch information
abellotti authored Mar 16, 2017
2 parents 2cbb57b + 7197086 commit 6cb8ae3
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 2 deletions.
9 changes: 9 additions & 0 deletions app/controllers/api/authentications_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
module Api
class AuthenticationsController < BaseController
def edit_resource(type, id, data)
auth = resource_search(id, type, collection_class(:authentications))
raise "Update not supported for #{authentication_ident(auth)}" unless auth.respond_to?(:update_in_provider_queue)
task_id = auth.update_in_provider_queue(data)
action_result(true, "Updating #{authentication_ident(auth)}", :task_id => task_id)
rescue => err
action_result(false, err.to_s)
end

def delete_resource(type, id, _data = {})
auth = resource_search(id, type, collection_class(:authentications))
raise "Delete not supported for #{authentication_ident(auth)}" unless auth.respond_to?(:delete_in_provider_queue)
Expand Down
4 changes: 4 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,17 @@
:post:
- :name: delete
:identifier: embedded_automation_manager_credentials_delete
- :name: edit
:identifier: embedded_automation_manager_credentials_edit
:resource_actions:
:get:
- :name: read
:identifier: embedded_automation_manager_credentials_view
:post:
- :name: delete
:identifier: embedded_automation_manager_credentials_delete
- :name: edit
:identifier: embedded_automation_manager_credentials_edit
:delete:
- :name: delete
:identifier: embedded_automation_manager_credentials_delete
Expand Down
103 changes: 101 additions & 2 deletions spec/requests/api/authentications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

describe 'GET /api/authentications/:id' do
it 'will show an authentication configuration script base' do
auth = FactoryGirl.create(:authentication)
api_basic_authorize action_identifier(:authentications, :read, :resource_actions, :get)

run_get(authentications_url(auth.id))
Expand All @@ -44,7 +43,6 @@
end

it 'forbids access to an authentication configuration script base' do
auth = FactoryGirl.create(:authentication)
api_basic_authorize

run_get(authentications_url(auth.id))
Expand All @@ -54,6 +52,14 @@
end

describe 'POST /api/authentications' do
let(:params) do
{
:id => auth.id,
:description => 'Description',
:name => 'Updated Credential'
}
end

it 'will delete an authentication' do
api_basic_authorize collection_action_identifier(:authentications, :delete, :post)

Expand Down Expand Up @@ -120,9 +126,66 @@
run_post(authentications_url, :action => 'delete', :resources => [{ 'id' => auth.id }])
expect(response).to have_http_status(:forbidden)
end

it 'can update an authentication with an appropriate role' do
api_basic_authorize collection_action_identifier(:authentications, :edit)

run_post(authentications_url, :action => 'edit', :resources => [params])

expected = {
'results' => [
a_hash_including(
'success' => true,
'message' => a_string_including('Updating Authentication'),
'task_id' => a_kind_of(Numeric)
)
]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'can update an authentication with an appropriate role' do
params2 = params.dup.merge(:id => auth_2.id)
api_basic_authorize collection_action_identifier(:authentications, :edit)

run_post(authentications_url, :action => 'edit', :resources => [params, params2])

expected = {
'results' => [
a_hash_including(
'success' => true,
'message' => a_string_including('Updating Authentication'),
'task_id' => a_kind_of(Numeric)
),
a_hash_including(
'success' => true,
'message' => a_string_including('Updating Authentication'),
'task_id' => a_kind_of(Numeric)
)
]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'will forbid update to an authentication without appropriate role' do
api_basic_authorize

run_post(authentications_url, :action => 'edit', :resources => [params])

expect(response).to have_http_status(:forbidden)
end
end

describe 'POST /api/authentications/:id' do
let(:params) do
{
:description => 'Description',
:name => 'Updated Credential'
}
end

it 'will delete an authentication' do
api_basic_authorize action_identifier(:authentications, :delete, :resource_actions, :post)

Expand All @@ -144,6 +207,42 @@

expect(response).to have_http_status(:forbidden)
end

it 'can update an authentication with an appropriate role' do
api_basic_authorize collection_action_identifier(:authentications, :edit)

run_post(authentications_url(auth.id), :action => 'edit', :resource => params)

expected = {
'success' => true,
'message' => a_string_including('Updating Authentication'),
'task_id' => a_kind_of(Numeric)
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'requires that the type support update_in_provider_queue' do
api_basic_authorize collection_action_identifier(:authentications, :edit)
auth = FactoryGirl.create(:authentication)

run_post(authentications_url(auth.id), :action => 'edit', :resource => params)

expected = {
'success' => false,
'message' => "Update not supported for Authentication id:#{auth.id} name: '#{auth.name}'"
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'will forbid update to an authentication without appropriate role' do
api_basic_authorize

run_post(authentications_url(auth.id), :action => 'edit', :resource => params)

expect(response).to have_http_status(:forbidden)
end
end

describe 'DELETE /api/authentications/:id' do
Expand Down

0 comments on commit 6cb8ae3

Please sign in to comment.