2013-02-25 19:05:37 -05:00
|
|
|
require 'helper'
|
2011-09-03 14:08:07 -04:00
|
|
|
|
|
|
|
describe OmniAuth do
|
2014-01-15 23:00:46 -05:00
|
|
|
describe '.strategies' do
|
|
|
|
it 'increases when a new strategy is made' do
|
|
|
|
expect do
|
2012-10-10 04:32:55 -04:00
|
|
|
class ExampleStrategy
|
|
|
|
include OmniAuth::Strategy
|
|
|
|
end
|
2014-01-15 23:00:46 -05:00
|
|
|
end.to change(OmniAuth.strategies, :size).by(1)
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(OmniAuth.strategies.last).to eq(ExampleStrategy)
|
2011-09-03 14:08:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
context 'configuration' do
|
|
|
|
describe '.defaults' do
|
|
|
|
it 'is a hash of default configuration' do
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(OmniAuth::Configuration.defaults).to be_kind_of(Hash)
|
2011-09-26 12:44:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'is callable from .configure' do
|
2011-09-03 14:08:07 -04:00
|
|
|
OmniAuth.configure do |c|
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(c).to be_kind_of(OmniAuth::Configuration)
|
2011-09-03 14:08:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2013-09-02 21:05:18 -04:00
|
|
|
@old_path_prefix = OmniAuth.config.path_prefix
|
|
|
|
@old_on_failure = OmniAuth.config.on_failure
|
|
|
|
@old_before_callback_phase = OmniAuth.config.before_callback_phase
|
|
|
|
@old_before_options_phase = OmniAuth.config.before_options_phase
|
|
|
|
@old_before_request_phase = OmniAuth.config.before_request_phase
|
2011-09-03 14:08:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
OmniAuth.configure do |config|
|
2013-09-02 21:05:18 -04:00
|
|
|
config.path_prefix = @old_path_prefix
|
|
|
|
config.on_failure = @old_on_failure
|
|
|
|
config.before_callback_phase = @old_before_callback_phase
|
|
|
|
config.before_options_phase = @old_before_options_phase
|
|
|
|
config.before_request_phase = @old_before_request_phase
|
2011-09-03 14:08:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'is able to set the path' do
|
2011-09-03 14:08:07 -04:00
|
|
|
OmniAuth.configure do |config|
|
|
|
|
config.path_prefix = '/awesome'
|
|
|
|
end
|
|
|
|
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(OmniAuth.config.path_prefix).to eq('/awesome')
|
2011-09-03 14:08:07 -04:00
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'is able to set the on_failure rack app' do
|
2011-09-03 14:08:07 -04:00
|
|
|
OmniAuth.configure do |config|
|
|
|
|
config.on_failure do
|
|
|
|
'yoyo'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(OmniAuth.config.on_failure.call).to eq('yoyo')
|
2011-09-03 14:08:07 -04:00
|
|
|
end
|
2013-02-25 18:52:36 -05:00
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'is able to set hook on option_call' do
|
2013-02-25 18:52:36 -05:00
|
|
|
OmniAuth.configure do |config|
|
2013-09-02 21:05:18 -04:00
|
|
|
config.before_options_phase do
|
2013-02-25 18:52:36 -05:00
|
|
|
'yoyo'
|
|
|
|
end
|
|
|
|
end
|
2013-09-02 21:05:18 -04:00
|
|
|
expect(OmniAuth.config.before_options_phase.call).to eq('yoyo')
|
2013-02-25 18:52:36 -05:00
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'is able to set hook on request_call' do
|
2013-02-25 18:52:36 -05:00
|
|
|
OmniAuth.configure do |config|
|
2013-09-02 21:05:18 -04:00
|
|
|
config.before_request_phase do
|
2013-02-25 18:52:36 -05:00
|
|
|
'heyhey'
|
|
|
|
end
|
|
|
|
end
|
2013-09-02 21:05:18 -04:00
|
|
|
expect(OmniAuth.config.before_request_phase.call).to eq('heyhey')
|
2013-02-25 18:52:36 -05:00
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'is able to set hook on callback_call' do
|
2013-02-25 18:52:36 -05:00
|
|
|
OmniAuth.configure do |config|
|
2013-09-02 21:05:18 -04:00
|
|
|
config.before_callback_phase do
|
2013-02-25 18:52:36 -05:00
|
|
|
'heyhey'
|
|
|
|
end
|
|
|
|
end
|
2013-09-02 21:05:18 -04:00
|
|
|
expect(OmniAuth.config.before_callback_phase.call).to eq('heyhey')
|
2013-02-25 18:52:36 -05:00
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
describe 'mock auth' do
|
2012-01-05 05:44:51 -05:00
|
|
|
before do
|
2015-11-10 23:14:34 -05:00
|
|
|
@auth_hash = {:uid => '12345', :info => {:name => 'Joe', :email => 'joe@example.com'}}
|
2017-01-17 11:50:31 -05:00
|
|
|
@original_auth_hash = @auth_hash.dup
|
2015-11-10 23:07:57 -05:00
|
|
|
|
|
|
|
OmniAuth.config.add_mock(:facebook, @auth_hash)
|
2012-01-05 05:44:51 -05:00
|
|
|
end
|
2014-01-16 00:04:44 -05:00
|
|
|
it 'default is AuthHash' do
|
2012-01-05 05:44:51 -05:00
|
|
|
OmniAuth.configure do |config|
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(config.mock_auth[:default]).to be_kind_of(OmniAuth::AuthHash)
|
2012-01-05 05:44:51 -05:00
|
|
|
end
|
|
|
|
end
|
2014-01-16 00:04:44 -05:00
|
|
|
it 'facebook is AuthHash' do
|
2012-01-05 05:44:51 -05:00
|
|
|
OmniAuth.configure do |config|
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(config.mock_auth[:facebook]).to be_kind_of(OmniAuth::AuthHash)
|
|
|
|
end
|
2012-01-05 05:44:51 -05:00
|
|
|
end
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'sets facebook attributes' do
|
2012-01-05 05:44:51 -05:00
|
|
|
OmniAuth.configure do |config|
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(config.mock_auth[:facebook].uid).to eq('12345')
|
|
|
|
expect(config.mock_auth[:facebook].info.name).to eq('Joe')
|
|
|
|
expect(config.mock_auth[:facebook].info.email).to eq('joe@example.com')
|
2012-01-05 05:44:51 -05:00
|
|
|
end
|
|
|
|
end
|
2015-11-10 23:07:57 -05:00
|
|
|
it 'does not mutate given auth hash' do
|
2015-11-10 23:14:34 -05:00
|
|
|
OmniAuth.configure do
|
2015-11-10 23:07:57 -05:00
|
|
|
expect(@auth_hash).to eq @original_auth_hash
|
|
|
|
end
|
|
|
|
end
|
2012-01-05 05:44:51 -05:00
|
|
|
end
|
2011-09-03 14:08:07 -04:00
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
describe '.logger' do
|
|
|
|
it 'calls through to the configured logger' do
|
|
|
|
allow(OmniAuth).to receive(:config).and_return(double(:logger => 'foo'))
|
|
|
|
expect(OmniAuth.logger).to eq('foo')
|
2012-04-12 16:50:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
describe '::Utils' do
|
|
|
|
describe '.deep_merge' do
|
|
|
|
it 'combines hashes' do
|
2014-12-25 16:29:22 -05:00
|
|
|
expect(OmniAuth::Utils.deep_merge({'abc' => {'def' => 123}}, 'abc' => {'foo' => 'bar'})).to eq('abc' => {'def' => 123, 'foo' => 'bar'})
|
2011-09-03 14:08:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
describe '.camelize' do
|
|
|
|
it 'works on normal cases' do
|
2011-09-03 14:08:07 -04:00
|
|
|
{
|
|
|
|
'some_word' => 'SomeWord',
|
|
|
|
'AnotherWord' => 'AnotherWord',
|
|
|
|
'one' => 'One',
|
2015-12-19 06:10:33 -05:00
|
|
|
'three_words_now' => 'ThreeWordsNow'
|
2014-01-15 23:00:46 -05:00
|
|
|
}.each_pair { |k, v| expect(OmniAuth::Utils.camelize(k)).to eq(v) }
|
2011-09-03 14:08:07 -04:00
|
|
|
end
|
|
|
|
|
2014-01-15 23:00:46 -05:00
|
|
|
it 'works in special cases that have been added' do
|
2011-09-22 19:49:22 -04:00
|
|
|
OmniAuth.config.add_camelization('oauth', 'OAuth')
|
2012-10-10 04:32:55 -04:00
|
|
|
expect(OmniAuth::Utils.camelize(:oauth)).to eq('OAuth')
|
2011-09-03 14:08:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|