-
Notifications
You must be signed in to change notification settings - Fork 897
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 Read and Delete api #13780
Merged
abellotti
merged 2 commits into
ManageIQ:master
from
jntullo:enhancement/credentials_api
Feb 15, 2017
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 AuthenticationsController < 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,118 @@ | ||
RSpec.describe 'Authentications API' do | ||
describe 'GET/api/authentications' do | ||
it 'lists all the authentication configuration script bases with an appropriate role' do | ||
auth = FactoryGirl.create(:authentication) | ||
api_basic_authorize collection_action_identifier(:authentications, :read, :get) | ||
|
||
run_get(authentications_url) | ||
|
||
expected = { | ||
'count' => 1, | ||
'subcount' => 1, | ||
'name' => 'authentications', | ||
'resources' => [hash_including('href' => a_string_matching(authentications_url(auth.id)))] | ||
} | ||
expect(response.parsed_body).to include(expected) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'forbids access to authentication configuration script bases without an appropriate role' do | ||
api_basic_authorize | ||
|
||
run_get(authentications_url) | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe 'GET /api/authentications/:id' do | ||
it 'will show an authentication configuration script base' do | ||
auth = FactoryGirl.create(:authentication) | ||
api_basic_authorize action_identifier(:authentications, :read, :resource_actions, :get) | ||
|
||
run_get(authentications_url(auth.id)) | ||
|
||
expected = { | ||
'href' => a_string_matching(authentications_url(auth.id)) | ||
} | ||
expect(response.parsed_body).to include(expected) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'forbids access to an authentication configuration script base' do | ||
auth = FactoryGirl.create(:authentication) | ||
api_basic_authorize | ||
|
||
run_get(authentications_url(auth.id)) | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe 'POST /api/authentications' do | ||
it 'will delete an authentication' do | ||
auth = FactoryGirl.create(:authentication) | ||
api_basic_authorize collection_action_identifier(:authentications, :delete, :post) | ||
|
||
expected = { | ||
'results' => [a_hash_including('success' => true)] | ||
} | ||
expect do | ||
run_post(authentications_url, :action => 'delete', :resources => [{ 'id' => auth.id }]) | ||
end.to change(Authentication, :count).by(-1) | ||
expect(response.parsed_body).to include(expected) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'will forbid deletion to an authentication without appropriate role' do | ||
auth = FactoryGirl.create(:authentication) | ||
api_basic_authorize | ||
|
||
run_post(authentications_url, :action => 'delete', :resources => [{ 'id' => auth.id }]) | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe 'POST /api/authentications/:id' do | ||
it 'will delete an authentication' do | ||
auth = FactoryGirl.create(:authentication) | ||
api_basic_authorize action_identifier(:authentications, :delete, :resource_actions, :post) | ||
|
||
expect do | ||
run_post(authentications_url(auth.id), :action => 'delete') | ||
end.to change(Authentication, :count).by(-1) | ||
expect(response.parsed_body).to include('success' => true) | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'will not delete an authentication without an appropriate role' do | ||
auth = FactoryGirl.create(:authentication) | ||
api_basic_authorize | ||
|
||
run_post(authentications_url(auth.id), :action => 'delete') | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
describe 'DELETE /api/authentications/:id' do | ||
it 'will delete an authentication' do | ||
auth = FactoryGirl.create(:authentication) | ||
api_basic_authorize action_identifier(:authentications, :delete, :resource_actions, :delete) | ||
|
||
expect do | ||
run_delete(authentications_url(auth.id)) | ||
end.to change(Authentication, :count).by(-1) | ||
expect(response).to have_http_status(:no_content) | ||
end | ||
|
||
it 'will not delete an authentication without an appropriate role' do | ||
auth = FactoryGirl.create(:authentication) | ||
api_basic_authorize | ||
|
||
run_delete(authentications_url(auth.id)) | ||
|
||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abellotti how should we handle this identifier? We are using the
Authentication
model, but only have this identifier currently. Is it fine as is, and as needed we will add additional ones via #13827 ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thought behind #13827 is that higher level collections are authorizable if the user has at least one of the related/relevant roles, so if a user has embedded_automation_manager_credentials_view or later automation_manager_credentials_view, etc. he'd be able to access this collection.
Signature above is fine, once #13827 is merged, you'd also use the array equivalent: