From 4b4e854464324829d25c82ac9dadc7dc1ff95f34 Mon Sep 17 00:00:00 2001 From: Jillian Tullo Date: Mon, 10 Apr 2017 13:22:43 -0400 Subject: [PATCH] refresh authentications --- .../api/authentications_controller.rb | 8 +++ config/api.yml | 4 ++ spec/requests/api/authentications_spec.rb | 51 +++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/app/controllers/api/authentications_controller.rb b/app/controllers/api/authentications_controller.rb index 3bf7f487633..b3e5fca10f6 100644 --- a/app/controllers/api/authentications_controller.rb +++ b/app/controllers/api/authentications_controller.rb @@ -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 diff --git a/config/api.yml b/config/api.yml index adfcf9e2a40..a5e1328981d 100644 --- a/config/api.yml +++ b/config/api.yml @@ -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 @@ -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 diff --git a/spec/requests/api/authentications_spec.rb b/spec/requests/api/authentications_spec.rb index edb0f6cf7bf..2aeaa78905b 100644 --- a/spec/requests/api/authentications_spec.rb +++ b/spec/requests/api/authentications_spec.rb @@ -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 @@ -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