Skip to content

Commit

Permalink
Add PXE server credential validation endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
lfu committed Feb 23, 2021
1 parent 5dacc20 commit 9e1c49d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/api/pxe_servers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def edit_resource(type, id, data)
end
end

def verify_credentials_resource(_type, _id = nil, data = {})
task_id = PxeServer.verify_depot_settings_queue(User.current_user.userid, data)
action_result(true, "Credentials sent for verification", :task_id => task_id)
rescue => err
action_result(false, err.to_s)
end

private

def validate_data_for(klass, data)
Expand Down
2 changes: 2 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3030,6 +3030,8 @@
:identifier: pxe_server_edit
- :name: delete
:identifier: pxe_server_delete
- :name: verify_credentials
:identifier: pxe_server_new
:resource_actions:
:get:
- :name: read
Expand Down
20 changes: 20 additions & 0 deletions spec/requests/pxe_servers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,24 @@
expect(response).to have_http_status(:forbidden)
end
end

describe 'post /api/pxe_servers with verify_credentials action' do
it 'queues the request to verify the credentials' do
api_basic_authorize collection_action_identifier(:pxe_servers, :verify_credentials)
post(api_pxe_servers_url, :params => gen_request(:verify_credentials, :name => 'test', :uri => 'smb://tmp/foo', :username => 'test', :password => 'foo'))
expected = {
"results" => a_collection_containing_exactly(
a_hash_including(
"message" => a_string_matching(/Credentials sent for verification/),
"success" => true,
"task_href" => a_string_matching(api_tasks_url),
"task_id" => a_kind_of(String)
)
)
}

expect(response.parsed_body).to include(expected)
expect(response).to have_http_status(:ok)
end
end
end

0 comments on commit 9e1c49d

Please sign in to comment.