diff --git a/lib/casserver/authenticators/test.rb b/lib/casserver/authenticators/test.rb index 1780cc1..4d8740c 100644 --- a/lib/casserver/authenticators/test.rb +++ b/lib/casserver/authenticators/test.rb @@ -11,6 +11,7 @@ class CASServer::Authenticators::Test < CASServer::Authenticators::Base raise CASServer::AuthenticatorError, "Username is 'do_error'!" if @username == 'do_error' @extra_attributes[:test_string] = "testing!" + @extra_attributes[:test_utf_string] = "Ютф" @extra_attributes[:test_numeric] = 123.45 @extra_attributes[:test_serialized] = {:foo => 'bar', :alpha => [1,2,3]} diff --git a/lib/casserver/server.rb b/lib/casserver/server.rb index 4ca57d4..425e9df 100644 --- a/lib/casserver/server.rb +++ b/lib/casserver/server.rb @@ -651,13 +651,15 @@ module CASServer end end - def serialize_extra_attribute(builder, value) + def serialize_extra_attribute(builder, key, value) if value.kind_of?(String) - builder.text! value + builder.tag! key, value elsif value.kind_of?(Numeric) - builder.text! value.to_s + builder.tag! key, value.to_s else - builder.cdata! value.to_yaml + builder.tag! key do + builder.cdata! value.to_yaml + end end end end diff --git a/lib/casserver/views/proxy_validate.builder b/lib/casserver/views/proxy_validate.builder index 30e0d81..98cf9a4 100644 --- a/lib/casserver/views/proxy_validate.builder +++ b/lib/casserver/views/proxy_validate.builder @@ -3,9 +3,7 @@ if @success xml.tag!("cas:authenticationSuccess") do xml.tag!("cas:user", @username.to_s) @extra_attributes.each do |key, value| - xml.tag!(key) do - serialize_extra_attribute(xml, value) - end + serialize_extra_attribute(xml, key, value) end if @pgtiou xml.tag!("cas:proxyGrantingTicket", @pgtiou.to_s) diff --git a/lib/casserver/views/service_validate.builder b/lib/casserver/views/service_validate.builder index 5affc7f..cfe3001 100644 --- a/lib/casserver/views/service_validate.builder +++ b/lib/casserver/views/service_validate.builder @@ -3,9 +3,7 @@ if @success xml.tag!("cas:authenticationSuccess") do xml.tag!("cas:user", @username.to_s) @extra_attributes.each do |key, value| - xml.tag!(key) do - serialize_extra_attribute(xml, value) - end + serialize_extra_attribute(xml, key, value) end if @pgtiou xml.tag!("cas:proxyGrantingTicket", @pgtiou.to_s) diff --git a/spec/casserver_spec.rb b/spec/casserver_spec.rb index fbfc32e..b919caf 100644 --- a/spec/casserver_spec.rb +++ b/spec/casserver_spec.rb @@ -111,4 +111,30 @@ describe 'CASServer' do page.status_code.should_not == 404 end end + + describe "proxyValidate" do + before do + load_server(File.dirname(__FILE__) + "/default_config.yml") + reset_spec_database + + visit "/login?service="+CGI.escape(@target_service) + + fill_in 'username', :with => VALID_USERNAME + fill_in 'password', :with => VALID_PASSWORD + + click_button 'login-submit' + + page.current_url.should =~ /^#{Regexp.escape(@target_service)}\/?\?ticket=ST\-[1-9rA-Z]+/ + @ticket = page.current_url.match(/ticket=(.*)$/)[1] + end + + it "should have extra attributes in proper format" do + visit "/serviceValidate?service=#{CGI.escape(@target_service)}&ticket=#{@ticket}" + + puts page.body + page.body.should match("testing!") + page.body.should match("123.45") + page.body.should match("Ютф") + end + end end