Skip to content

Commit

Permalink
Don’t break if email is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
bjrne committed Aug 9, 2017
1 parent 400cd5a commit 3837a31
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
skip_before_action :verify_authenticity_token, only: :hpiopenid

def hpiopenid
if request.env["omniauth.auth"].info.email.empty?
if request.env["omniauth.auth"].info.email.to_s.empty?
return redirect_to user_session_path, :alert => I18n.t('users.openid.missing_email')
end
@user = User.from_omniauth(request.env["omniauth.auth"])
Expand Down
27 changes: 21 additions & 6 deletions spec/features/user_hpiopenid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,29 @@
expect(page).to have_css(".alert-success")
end

scenario 'Account creation fails due to empty email' do
OmniAuth.config.mock_auth[:hpiopenid] = OmniAuth::AuthHash.new({
:provider => @provider,
:uid => @uid,
:info => {
:email => ''
}
})
visit new_user_registration_path
click_link I18n.t('devise.shared.links.sign_in_with_provider', :provider => 'HPI OpenID')

expect(page).to have_css(".alert-danger")
expect(page).to have_text (I18n.t('users.openid.missing_email'))
end

scenario 'Account creation fails due to missing email' do
OmniAuth.config.mock_auth[:hpiopenid] = OmniAuth::AuthHash.new({
:provider => @provider,
:uid => @uid,
:info => {
:email => ''
}
})
:provider => @provider,
:uid => @uid,
:info => {
:email => nil
}
})
visit new_user_registration_path
click_link I18n.t('devise.shared.links.sign_in_with_provider', :provider => 'HPI OpenID')

Expand Down

0 comments on commit 3837a31

Please sign in to comment.