test/test.rb in omniauth-facebook-2.0.0 vs test/test.rb in omniauth-facebook-2.0.1
- old
+ new
@@ -14,12 +14,14 @@
test 'has correct authorize url' do
assert_equal 'https://www.facebook.com/dialog/oauth', strategy.client.options[:authorize_url]
end
- test 'has correct token url' do
- assert_equal '/oauth/access_token', strategy.client.options[:token_url]
+ test 'has correct token url with versioning' do
+ @options = {:client_options => {:site => 'https://graph.facebook.net/v2.2'}}
+ assert_equal 'oauth/access_token', strategy.client.options[:token_url]
+ assert_equal 'https://graph.facebook.net/v2.2/oauth/access_token', strategy.client.token_url
end
end
class CallbackUrlTest < StrategyTestCase
test "returns the default callback url" do
@@ -102,17 +104,31 @@
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info)
assert_equal 'https://graph.facebook.com/321/picture', strategy.info['image']
end
+ test 'returns the image_url based of the client site' do
+ @options = { :secure_image_url => true, :client_options => {:site => "https://blah.facebook.com/v2.2"}}
+ raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
+ strategy.stubs(:raw_info).returns(raw_info)
+ assert_equal 'https://blah.facebook.com/v2.2/321/picture', strategy.info['image']
+ end
+
test 'returns the image with size specified in the `image_size` option' do
@options = { :image_size => 'normal' }
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info)
assert_equal 'http://graph.facebook.com/321/picture?type=normal', strategy.info['image']
end
+ test 'returns the image with size specified as a symbol in the `image_size` option' do
+ @options = { :image_size => :normal }
+ raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
+ strategy.stubs(:raw_info).returns(raw_info)
+ assert_equal 'http://graph.facebook.com/321/picture?type=normal', strategy.info['image']
+ end
+
test 'returns the image with width and height specified in the `image_size` option' do
@options = { :image_size => { :width => 123, :height => 987 } }
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
strategy.stubs(:raw_info).returns(raw_info)
assert_match 'width=123', strategy.info['image']
@@ -248,29 +264,29 @@
test 'performs a GET to https://graph.facebook.com/me' do
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
strategy.stubs(:access_token).returns(@access_token)
params = {:params => @options}
- @access_token.expects(:get).with('/me', params).returns(stub_everything('OAuth2::Response'))
+ @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
strategy.raw_info
end
test 'performs a GET to https://graph.facebook.com/me with locale' do
@options.merge!({ :locale => 'cs_CZ' })
strategy.stubs(:access_token).returns(@access_token)
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
params = {:params => @options}
- @access_token.expects(:get).with('/me', params).returns(stub_everything('OAuth2::Response'))
+ @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
strategy.raw_info
end
test 'performs a GET to https://graph.facebook.com/me with info_fields' do
@options.merge!({:info_fields => 'about'})
strategy.stubs(:access_token).returns(@access_token)
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
params = {:params => {:appsecret_proof => @appsecret_proof, :fields => 'about'}}
- @access_token.expects(:get).with('/me', params).returns(stub_everything('OAuth2::Response'))
+ @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
strategy.raw_info
end
test 'returns a Hash' do
strategy.stubs(:access_token).returns(@access_token)
@@ -279,21 +295,21 @@
raw_response.stubs(:body).returns('{ "ohai": "thar" }')
raw_response.stubs(:status).returns(200)
raw_response.stubs(:headers).returns({'Content-Type' => 'application/json' })
oauth2_response = OAuth2::Response.new(raw_response)
params = {:params => @options}
- @access_token.stubs(:get).with('/me', params).returns(oauth2_response)
+ @access_token.stubs(:get).with('me', params).returns(oauth2_response)
assert_kind_of Hash, strategy.raw_info
assert_equal 'thar', strategy.raw_info['ohai']
end
test 'returns an empty hash when the response is false' do
strategy.stubs(:access_token).returns(@access_token)
strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
oauth2_response = stub('OAuth2::Response', :parsed => false)
params = {:params => @options}
- @access_token.stubs(:get).with('/me', params).returns(oauth2_response)
+ @access_token.stubs(:get).with('me', params).returns(oauth2_response)
assert_kind_of Hash, strategy.raw_info
assert_equal({}, strategy.raw_info)
end
test 'should not include raw_info in extras hash when skip_info is specified' do
@@ -441,11 +457,11 @@
super
@request.stubs(:params).returns({})
end
test 'calls fail! when a code is not included in the params' do
- strategy.expects(:fail!).times(1).with(:no_authorization_code, kind_of(Exception))
+ strategy.expects(:fail!).times(1).with(:no_authorization_code, kind_of(OmniAuth::Strategies::Facebook::NoAuthorizationCodeError))
strategy.callback_phase
end
end
class MissingCodeInCookieRequestTest < TestCase
@@ -460,10 +476,29 @@
@request.stubs(:cookies).returns({"fbsr_#{@client_id}" => signed_request(@payload, @client_secret)})
end
test 'calls fail! when a code is not included in the cookie' do
- strategy.expects(:fail!).times(1).with(:no_authorization_code, kind_of(Exception))
+ strategy.expects(:fail!).times(1).with(:no_authorization_code, kind_of(OmniAuth::Strategies::Facebook::NoAuthorizationCodeError))
+ strategy.callback_phase
+ end
+ end
+
+ class UnknownAlgorithmInCookieRequestTest < TestCase
+ def setup
+ super()
+ @payload = {
+ 'algorithm' => 'UNKNOWN-ALGO',
+ 'code' => nil,
+ 'issued_at' => Time.now.to_i,
+ 'user_id' => '123456'
+ }
+
+ @request.stubs(:cookies).returns({"fbsr_#{@client_id}" => signed_request(@payload, @client_secret)})
+ end
+
+ test 'calls fail! when an algorithm is unknown' do
+ strategy.expects(:fail!).times(1).with(:unknown_signature_algorithm, kind_of(OmniAuth::Strategies::Facebook::UnknownSignatureAlgorithmError))
strategy.callback_phase
end
end
end