-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce the auth_key_pairs endpoint with set_ownership feature
- Loading branch information
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Api | ||
class AuthKeyPairsController < BaseController | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
RSpec.describe "Auth Key Pairs API" do | ||
let(:akp) { FactoryBot.create(:auth_key_pair_cloud) } | ||
|
||
describe 'GET /api/auth_key_pairs' do | ||
before { akp } | ||
|
||
context 'without an appropriate role' do | ||
it 'does not list auth key pairs' do | ||
api_basic_authorize | ||
get(api_auth_key_pairs_url) | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
context 'with an appropriate role' do | ||
before { api_basic_authorize collection_action_identifier(:auth_key_pairs, :read, :get) } | ||
|
||
it 'lists all auth key pairs' do | ||
get(api_auth_key_pairs_url) | ||
|
||
expected = { | ||
'count' => 1, | ||
'subcount' => 1, | ||
'name' => 'auth_key_pairs', | ||
'resources' => [ | ||
hash_including('href' => api_auth_key_pair_url(nil, akp)) | ||
] | ||
} | ||
|
||
expect(response).to have_http_status(:ok) | ||
expect(response.parsed_body).to include(expected) | ||
end | ||
end | ||
end | ||
|
||
describe 'GET /api/auth_key_pairs/:id' do | ||
context 'without an appropriate role' do | ||
it 'does not let you query a custom button' do | ||
api_basic_authorize | ||
get(api_auth_key_pair_url(nil, akp)) | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
context 'with an appropriate role' do | ||
before { api_basic_authorize action_identifier(:auth_key_pairs, :read, :resource_actions, :get) } | ||
|
||
it 'can query an auth key pair by its id' do | ||
get(api_auth_key_pair_url(nil, akp)) | ||
|
||
expected = { | ||
'id' => akp.id.to_s, | ||
'type' => "ManageIQ::Providers::CloudManager::AuthKeyPair" | ||
} | ||
expect(response).to have_http_status(:ok) | ||
expect(response.parsed_body).to include(expected) | ||
end | ||
end | ||
end | ||
|
||
describe 'POST /api/auth_key_pairs' do | ||
it 'can create auth_key_pairs' do | ||
api_basic_authorize collection_action_identifier(:auth_key_pairs, :create) | ||
|
||
post(api_auth_key_pairs_url, :params => {'name' => 'foo'}) | ||
|
||
expect(response).to have_http_status(:ok) | ||
|
||
auth_key_pair = ManageIQ::Providers::CloudManager::AuthKeyPair.find(response.parsed_body['results'].first["id"]) | ||
expect(auth_key_pair.name).to eq('foo') | ||
end | ||
end | ||
|
||
describe 'PUT /api/auth_key_pairs/:id' do | ||
it 'can edit an auth key pair by id' do | ||
api_basic_authorize action_identifier(:auth_key_pairs, :edit) | ||
|
||
expect(akp.name).not_to eq('foo') | ||
put(api_auth_key_pair_url(nil, akp), :params => {'name' => 'foo'}) | ||
expect(response).to have_http_status(:ok) | ||
expect(akp.reload.name).to eq('foo') | ||
end | ||
end | ||
|
||
describe 'DELETE /api/auth_key_pairs/:id' do | ||
it 'can delete an auth key pair by id' do | ||
api_basic_authorize action_identifier(:auth_key_pairs, :delete, :resource_actions, :delete) | ||
|
||
delete(api_auth_key_pair_url(nil, akp)) | ||
|
||
expect(response).to have_http_status(:no_content) | ||
end | ||
end | ||
end |