Codebase list ruby-omniauth-facebook / 83e7547
Tests for appsecret_proof. Josef Šimánek 10 years ago
3 changed file(s) with 26 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
66 - update Facebook authorize URL to fix broken authorization (#103, @dlackty)
77 - adds `info_fields` option (#109, @bloudermilk)
88 - adds `locale` parameter (#133, @donbobka, @simi)
9 - add automatically `appsecret_proof` (#140, @nlsrchtr, @simi)
910
1011 Changes:
1112
5757 end
5858
5959 def info_options
60 params = ({:appsecret_proof => OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), client.secret, access_token.token)})
60 params = ({:appsecret_proof => appsecret_proof})
6161 params.merge!({:fields => options[:info_fields]}) if options[:info_fields]
6262 params.merge!({:locale => options[:locale]}) if options[:locale]
6363
6464 { :params => params }
65 end
66
67 def appsecret_proof
68 @appsecret_proof ||= OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), client.secret, access_token.token)
6569 end
6670
6771 def build_access_token
245245 def setup
246246 super
247247 @access_token = stub('OAuth2::AccessToken')
248 @appsecret_proof = 'appsecret_proof'
249 @options = {:appsecret_proof => @appsecret_proof}
248250 end
249251
250252 test 'performs a GET to https://graph.facebook.com/me' do
253 strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
251254 strategy.stubs(:access_token).returns(@access_token)
252 @access_token.expects(:get).with('/me', {}).returns(stub_everything('OAuth2::Response'))
255 params = {:params => @options}
256 @access_token.expects(:get).with('/me', params).returns(stub_everything('OAuth2::Response'))
253257 strategy.raw_info
254258 end
255259
256260 test 'performs a GET to https://graph.facebook.com/me with locale' do
257 @options = { :locale => 'cs_CZ' }
261 @options.merge!({ :locale => 'cs_CZ' })
258262 strategy.stubs(:access_token).returns(@access_token)
259 @access_token.expects(:get).with('/me', {:params => {:locale => 'cs_CZ'}}).returns(stub_everything('OAuth2::Response'))
263 strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
264 params = {:params => @options}
265 @access_token.expects(:get).with('/me', params).returns(stub_everything('OAuth2::Response'))
260266 strategy.raw_info
261267 end
262268
263269 test 'performs a GET to https://graph.facebook.com/me with info_fields' do
264 @options = { :info_fields => 'about' }
270 @options.merge!({:info_fields => 'about'})
265271 strategy.stubs(:access_token).returns(@access_token)
266 @access_token.expects(:get).with('/me', {:params => {:fields => 'about'}}).returns(stub_everything('OAuth2::Response'))
272 strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
273 params = {:params => {:appsecret_proof => @appsecret_proof, :fields => 'about'}}
274 @access_token.expects(:get).with('/me', params).returns(stub_everything('OAuth2::Response'))
267275 strategy.raw_info
268276 end
269277
270278 test 'returns a Hash' do
271279 strategy.stubs(:access_token).returns(@access_token)
280 strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
272281 raw_response = stub('Faraday::Response')
273282 raw_response.stubs(:body).returns('{ "ohai": "thar" }')
274283 raw_response.stubs(:status).returns(200)
275284 raw_response.stubs(:headers).returns({'Content-Type' => 'application/json' })
276285 oauth2_response = OAuth2::Response.new(raw_response)
277 @access_token.stubs(:get).with('/me', {}).returns(oauth2_response)
286 params = {:params => @options}
287 @access_token.stubs(:get).with('/me', params).returns(oauth2_response)
278288 assert_kind_of Hash, strategy.raw_info
279289 assert_equal 'thar', strategy.raw_info['ohai']
280290 end
281291
282292 test 'returns an empty hash when the response is false' do
283293 strategy.stubs(:access_token).returns(@access_token)
294 strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
284295 oauth2_response = stub('OAuth2::Response', :parsed => false)
285 @access_token.stubs(:get).with('/me', {}).returns(oauth2_response)
296 params = {:params => @options}
297 @access_token.stubs(:get).with('/me', params).returns(oauth2_response)
286298 assert_kind_of Hash, strategy.raw_info
299 assert_equal({}, strategy.raw_info)
287300 end
288301
289302 test 'should not include raw_info in extras hash when skip_info is specified' do