File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 1
1
require 'omniauth/strategies/oauth2'
2
+ require 'uri'
3
+ require 'rack/utils'
2
4
3
5
module OmniAuth
4
6
module Strategies
@@ -55,7 +57,11 @@ def raw_info
55
57
end
56
58
57
59
def user_info
58
- @user_info ||= access_token . get ( "/api/users.info?user=#{ raw_info [ 'user_id' ] } " ) . parsed
60
+ url = URI . parse ( "/api/users.info" )
61
+ url . query = Rack ::Utils . build_query ( user : raw_info [ 'user_id' ] )
62
+ url = url . to_s
63
+
64
+ @user_info ||= access_token . get ( url ) . parsed
59
65
end
60
66
61
67
def team_info
Original file line number Diff line number Diff line change @@ -98,3 +98,25 @@ def setup
98
98
refute_has_key "refresh_token" , strategy . credentials
99
99
end
100
100
end
101
+
102
+ class UserInfoTest < StrategyTestCase
103
+ def setup
104
+ super
105
+ @access_token = stub ( "OAuth2::AccessToken" )
106
+ strategy . stubs ( :access_token ) . returns ( @access_token )
107
+ end
108
+
109
+ test "performs a GET to https://slack.com/api/users.info" do
110
+ strategy . stubs ( :raw_info ) . returns ( "user_id" => "U123" )
111
+ @access_token . expects ( :get ) . with ( "/api/users.info?user=U123" )
112
+ . returns ( stub_everything ( "OAuth2::Response" ) )
113
+ strategy . user_info
114
+ end
115
+
116
+ test "URI escapes user ID" do
117
+ strategy . stubs ( :raw_info ) . returns ( "user_id" => "../haxx?U123#abc" )
118
+ @access_token . expects ( :get ) . with ( "/api/users.info?user=..%2Fhaxx%3FU123%23abc" )
119
+ . returns ( stub_everything ( "OAuth2::Response" ) )
120
+ strategy . user_info
121
+ end
122
+ end
You can’t perform that action at this time.
0 commit comments