Skip to content

Adds support for another way to show cas xml attributes. #39

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion lib/casclient/responses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ def parse(raw_text, options)
@extra_attributes = {}
@xml.elements.to_a('//cas:authenticationSuccess/cas:attributes/* | //cas:authenticationSuccess/*[local-name() != \'proxies\' and local-name() != \'proxyGrantingTicket\' and local-name() != \'user\' and local-name() != \'attributes\']').each do |el|
inner_text = el.cdatas.length > 0 ? el.cdatas.join('') : el.text
@extra_attributes.merge! el.name => inner_text
name = el.name
unless (attrs = el.attributes).empty?
name = attrs['name']
inner_text = attrs['value']
end
@extra_attributes.merge! name => inner_text
end

# unserialize extra attributes
Expand Down
21 changes: 21 additions & 0 deletions spec/casclient/validation_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,22 @@
RESPONSE_TEXT
end

let(:other_response_text) do
<<RESPONSE_TEXT
<?xml version="1.0" encoding="UTF-8"?>
<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
<cas:authenticationSuccess>
<cas:user>myuser</cas:user>
<cas:attribute name="username" value="myuser"/>
<cas:attribute name="name" value="My User"/>
<cas:attribute name="email" value="[email protected]"/>
</cas:authenticationSuccess>
</cas:serviceResponse>
RESPONSE_TEXT
end

let(:subject) { CASClient::ValidationResponse.new response_text, :encode_extra_attributes_as => :json }
let(:other_subject) { CASClient::ValidationResponse.new other_response_text }

it "sets the value of non-CDATA escaped empty attribute to nil" do
subject.extra_attributes["mobile_phone"].should be_nil
Expand Down Expand Up @@ -50,5 +65,11 @@
it "sets the value of attributes which are not valid JSON but are valid YAML to their literal value" do
subject.extra_attributes["allegedly_yaml"].should == '- 10'
end

it "sets attributes for other type of format" do
expected = {"username" => "myuser", "name" => 'My User', "email" => '[email protected]'}
other_subject.user.should == 'myuser'
other_subject.extra_attributes.should == expected
end
end
end