Skip to content

Commit

Permalink
Merge pull request #14717 from jntullo/enhancement/authentication_ref…
Browse files Browse the repository at this point in the history
…resh

Authentications refresh action
  • Loading branch information
abellotti authored Apr 18, 2017
2 parents 5164cd8 + 4b4e854 commit 23b5f69
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/controllers/api/authentications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ def delete_resource(type, id, _data = {})
action_result(false, err.to_s)
end

def refresh_resource(type, id, _data)
auth = resource_search(id, type, collection_class(type))
task_ids = EmsRefresh.queue_refresh_task(auth)
action_result(true, "Refreshing #{authentication_ident(auth)}", :task_ids => task_ids)
rescue => err
action_result(false, err.to_s)
end

def options
render_options(:authentications, build_additional_fields)
end
Expand Down
4 changes: 4 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@
:identifier: embedded_automation_manager_credentials_edit
- :name: create
:identifier: embedded_automation_manager_credentials_add
- :name: refresh
:identifier: embedded_automation_manager_credentials_refresh
:resource_actions:
:get:
- :name: read
Expand All @@ -167,6 +169,8 @@
:identifier: embedded_automation_manager_credentials_delete
- :name: edit
:identifier: embedded_automation_manager_credentials_edit
- :name: refresh
:identifier: embedded_automation_manager_credentials_refresh
:delete:
- :name: delete
:identifier: embedded_automation_manager_credentials_delete
Expand Down
51 changes: 51 additions & 0 deletions spec/requests/api/authentications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,33 @@

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

it 'can refresh multiple authentications with an appropriate role' do
api_basic_authorize collection_action_identifier(:authentications, :refresh, :post)

run_post(authentications_url, :action => :refresh, :resources => [{ :id => auth.id}, {:id => auth_2.id}])

expected = {
'results' => [
a_hash_including(
'success' => true,
'message' => a_string_including("Refreshing Authentication id:#{auth.id}"),
'task_id' => a_kind_of(Numeric),
'task_href' => /task/,
'tasks' => [a_hash_including('id' => a_kind_of(Numeric), 'href' => /task/)]
),
a_hash_including(
'success' => true,
'message' => a_string_including("Refreshing Authentication id:#{auth_2.id}"),
'task_id' => a_kind_of(Numeric),
'task_href' => /task/,
'tasks' => [a_hash_including('id' => a_kind_of(Numeric), 'href' => /task/)]
)
]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end

describe 'PUT /api/authentications/:id' do
Expand Down Expand Up @@ -395,6 +422,30 @@

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

it 'forbids refresh without an appropriate role' do
api_basic_authorize

run_post(authentications_url(auth.id), :action => :refresh)

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

it 'can refresh a authentications with an appropriate role' do
api_basic_authorize action_identifier(:authentications, :refresh)

run_post(authentications_url(auth.id), :action => :refresh)

expected = {
'success' => true,
'message' => /Refreshing Authentication/,
'task_id' => a_kind_of(Numeric),
'task_href' => /task/,
'tasks' => [a_hash_including('id' => a_kind_of(Numeric), 'href' => /tasks/)]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end

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

0 comments on commit 23b5f69

Please sign in to comment.