Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentications refresh action #14717

Merged
merged 1 commit into from
Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -248,6 +248,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 @@ -257,6 +259,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