Skip to content
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

Add support for multivalued attributes #59

Merged
merged 3 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/omniauth/strategies/cas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class InvalidCASTicket < StandardError; end
option :port, nil
option :path, nil
option :ssl, true
option :merge_multivalued_attributes, false
option :service_validate_url, '/serviceValidate'
option :login_url, '/login'
option :logout_url, '/logout'
Expand Down
6 changes: 5 additions & 1 deletion lib/omniauth/strategies/cas/service_ticket_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ def parse_user_info(node)
unless e.kind_of?(Nokogiri::XML::Text) || node_name == 'proxies'
# There are no child elements
if e.element_children.count == 0
hash[node_name] = e.content
hash[node_name] = if hash[node_name] && @options.merge_multivalued_attributes
Array(hash[node_name]).push(e.content)
else
e.content
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better stubbed out in a separate method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vjt Thanks for the feedback, see the updated changes. And glad to see this project is still active. 🎉

elsif e.element_children.count
# JASIG style extra attributes
if node_name == 'attributes'
Expand Down
23 changes: 21 additions & 2 deletions spec/omniauth/strategies/cas/service_ticket_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
let(:provider_options) do
double('provider_options',
disable_ssl_verification?: false,
merge_multivalued_attributes: false,
ca_path: '/etc/ssl/certsZOMG'
)
end
Expand Down Expand Up @@ -48,8 +49,26 @@

subject { validator.user_info }

it 'parses user info from the response' do
expect(subject).to include 'user' => 'psegel'
context 'with default settings' do
it 'parses user info from the response' do
expect(subject).to include 'user' => 'psegel'
expect(subject).to include 'roles' => 'financier'
end
end

context 'when merging multivalued attributes' do
let(:provider_options) do
double('provider_options',
disable_ssl_verification?: false,
merge_multivalued_attributes: true,
ca_path: '/etc/ssl/certsZOMG'
)
end

it 'parses multivalued user info from the response' do
expect(subject).to include 'user' => 'psegel'
expect(subject).to include 'roles' => %w[senator lobbyist financier]
end
end
end
end