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 24, 2021
1 parent 5dacc20 commit 9fec3d3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
8 changes: 8 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,14 @@ def edit_resource(type, id, data)
end
end

def verify_credentials_resource(_type, _id = nil, data = {})
zone_name = data.delete('zone_name')
task_id = PxeServer.verify_depot_settings_queue(User.current_user.userid, zone_name, 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
25 changes: 25 additions & 0 deletions spec/requests/pxe_servers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,29 @@
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)
request = {
"action" => "verify_credentials",
"zone_name" => "zone",
"resource" => {:name => "test", :uri => "smb://tmp/foo", :username => "test", :password => "foo"}
}
post(api_pxe_servers_url, :params => request)
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 9fec3d3

Please sign in to comment.