redmine_oauth_controller_test.rb 1.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
require File.expand_path('../../test_helper', __FILE__)

class RedmineOauthControllerTest < ActionController::TestCase
  def setup
    User.current = nil
    Setting.openid = '1'
    OAuth2::AccessToken.any_instance.stubs(get: OAuth2::Response.new(nil))
    OAuth2::Client.any_instance.stubs(get_token: OAuth2::AccessToken.new('code', 'redirect_uri'))
  end
  def set_response_body_stub body
    OAuth2::Response.any_instance.stubs(body: body.to_json)
  end

14
  def new_user options = nil
15 16
    user_credentials = {:firstname => 'Cool',
                        :lastname => 'User',
17 18 19 20 21 22 23 24 25
                        :mail => 'user@somedomain.com'}.merge(options)
    user = User.new(user_credentials)
    user.login = options[:login] || 'cool_user'
    user
  end

  def test_login_with_omniauth_for_new_user
    Setting.self_registration = '3'
    user
26 27 28 29 30
    set_response_body_stub({verified_email: "true", name: [new_user.firstname, new_user.lastname]*" ", given_name: new_user.firstname, family_name: new_user.lastname, email: new_user.mail})
    get :oauth_google_callback, :email => new_user.mail
    assert_redirected_to controller: 'my', action: 'account'
  end

31 32 33 34 35
  def test_login_with_invalid_oauth_provider
    Setting.self_registration = '0'

  end

36 37
  #assert existing_user.save!
end