Skip to content

Commit

Permalink
Unescape the MIQ_GROUP header
Browse files Browse the repository at this point in the history
With the MIQ_GROUP header properly escaped, special characters in group descriptions will now be able to be specified.

unescape the group name
  • Loading branch information
Jillian Tullo committed Jan 17, 2018
1 parent 1182530 commit e9e734b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/controllers/api/base_controller/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def userid_to_userobj(userid)
def authorize_user_group(user_obj)
group_name = request.headers[HttpHeaders::MIQ_GROUP]
if group_name.present?
group_name = CGI.unescape(group_name)
group_obj = user_obj.miq_groups.find_by(:description => group_name)
raise AuthenticationError, "Invalid Authorization Group #{group_name} specified" if group_obj.nil?
user_obj.current_group_by_description = group_name
Expand Down
11 changes: 10 additions & 1 deletion spec/requests/authentication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@
context "Basic Authentication with Group Authorization" do
let(:group1) { FactoryGirl.create(:miq_group, :description => "Group1", :miq_user_role => @role) }
let(:group2) { FactoryGirl.create(:miq_group, :description => "Group2", :miq_user_role => @role) }
let(:special_char_group) { FactoryGirl.create(:miq_group, :description => "équipe", :miq_user_role => @role) }

before(:each) do
@user.miq_groups = [group1, group2, @user.current_group]
@user.miq_groups = [group1, group2, @user.current_group, special_char_group]
@user.current_group = group1
end

Expand All @@ -104,6 +105,14 @@

expect(response).to have_http_status(:ok)
end

it "permits group headers to be specified with properly escaped special characters" do
api_basic_authorize

get api_entrypoint_url, :headers => {Api::HttpHeaders::MIQ_GROUP => CGI.escape(special_char_group.description)}

expect(response).to have_http_status(:ok)
end
end

context "Authentication/Authorization Identity" do
Expand Down

0 comments on commit e9e734b

Please sign in to comment.