Skip to content

Commit

Permalink
Updated tests when hd param is nil (gmail)
Browse files Browse the repository at this point in the history
  • Loading branch information
zquestz committed May 30, 2017
1 parent 9a9ef39 commit ca584d2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ use Rack::Session::Cookie, :secret => ENV['RACK_COOKIE_SECRET']
use OmniAuth::Builder do
# For additional provider examples please look at 'omni_auth.rb'
# The key provider_ignores_state is only for AJAX flows. It is not recommended for normal logins.
provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], {access_type: "offline", prompt: "consent", provider_ignores_state: true, scope: 'userinfo.email,calendar'}
provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'], {access_type: "offline", prompt: "consent", provider_ignores_state: true, scope: 'email,profile,calendar'}
end

run App.new
37 changes: 36 additions & 1 deletion spec/omniauth/strategies/google_oauth2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
@options = {:hd => 'example.com'}
expect(subject.authorize_params['hd']).to eq('example.com')
end

it 'should set the hd parameter and work with nil hd (gmail)' do
@options = {:hd => nil }
expect(subject.authorize_params['hd']).to eq(nil)
end
end

describe 'login_hint' do
Expand Down Expand Up @@ -625,6 +630,36 @@
end
let(:access_token) { OAuth2::AccessToken.from_hash(client, {}) }

context 'when domain is nil' do
let(:client) do
OAuth2::Client.new('abc', 'def') do |builder|
builder.request :url_encoded
builder.adapter :test do |stub|
stub.get('/plus/v1/people/me/openIdConnect') do |env|
[200, {'Content-Type' => 'application/json; charset=UTF-8'}, MultiJson.encode({})]
end
end
end
end

it 'should verify hd if options hd is set and correct' do
subject.options.hd = nil
expect(subject.send(:verify_hd, access_token)).to eq(true)
end

it 'should verify hd if options hd is set as an array and is correct' do
subject.options.hd = ['example.com', 'example.co', nil]
expect(subject.send(:verify_hd, access_token)).to eq(true)
end

it 'should raise an exception if nil is not included' do
subject.options.hd = ['example.com', 'example.co']
expect {
subject.send(:verify_hd, access_token)
}.to raise_error(OmniAuth::Strategies::OAuth2::CallbackError)
end
end

it 'should verify hd if options hd is not set' do
expect(subject.send(:verify_hd, access_token)).to eq(true)
end
Expand All @@ -635,7 +670,7 @@
end

it 'should verify hd if options hd is set as an array and is correct' do
subject.options.hd = ['example.com', 'example.co']
subject.options.hd = ['example.com', 'example.co', nil]
expect(subject.send(:verify_hd, access_token)).to eq(true)
end

Expand Down

0 comments on commit ca584d2

Please sign in to comment.