diff --git a/lib/omniauth/strategies/sso.rb b/lib/omniauth/strategies/sso.rb index a5087fda86cf48db0a2dccbb763415a258ed79a8..6f819eb61fcff4326d67ee136a6549b7754e0252 100644 --- a/lib/omniauth/strategies/sso.rb +++ b/lib/omniauth/strategies/sso.rb @@ -21,7 +21,7 @@ module OmniAuth end info do - info_from_ticket.slice *options.fields + info_from_ticket.select{|key,_val| options.fields.include? key} end def authorize_url(_params_from_options) @@ -30,7 +30,7 @@ module OmniAuth end def name - 'ai_sso' + 'sso' end def info_from_ticket diff --git a/test/omniauth/strategies/sso_test.rb b/test/omniauth/strategies/sso_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..10fec00b2887ebd6cb422803f7cad4294e9c9862 --- /dev/null +++ b/test/omniauth/strategies/sso_test.rb @@ -0,0 +1,43 @@ +require 'test_helper' +require 'omniauth' +require 'rack/test' +require 'omniauth/strategies/sso' + +class OmniAuth::Strategies::SSOTest < Minitest::Test + include OmniAuth::Test::StrategyTestCase + include Rack::Test::Methods + + def strategy + [OmniAuth::Strategies::SSO, 'service_id', verify_key] + end + + def test_callback + post '/auth/sso/callback', t: ticket_string + assert auth_hash + assert_equal 'sso', auth_hash['provider'] + assert_equal 'ale@sso.net', auth_hash['uid'] + assert_equal 'ale@sso.net', auth_hash['info'].email + assert_equal 'ale', auth_hash['info'].name + end + + def test_invalid_callback + post '/auth/my_strategy/callback', t: invalid_ticket_string + assert_nil auth_hash + end + + def auth_hash + last_request.env['omniauth.auth'] + end + + def verify_key + 'c0dadbb483765b055d4f9ff5554d92b3ed7a433f15f4d8ebabbbd072510bfe23' + end + + def ticket_string + '4bHHseETK5U9YblImiqUpPHnEktAHIlICzb8w6jfrcrDyj/y7EtWoFVTvmTPcpJKHdh7TPPYgEVHVFH4DwKsCDN8YWxlfHNlcnZpY2UvfHNzby5uZXR8MTQxNTU3NDg0NHw=' + end + + def invalid_ticket_string + '4bHHseETK5U9YblImiqUpPHnEktAHIlICzb8w6jfrcrDyj/y7EtWoFVTvmTPcpJKHdh7TPPYgEVHVFH4DwKsCDN8YWxlfHNlcnZpY2UvfHNzby5invalidQxNTU3NDg1NHw=' + end +end