Module: OmniAuth::Strategy::TestMode

Included in:
OmniAuth::Strategy
Defined in:
lib/omniauth/strategy/test_mode.rb,
sig/omniauth.rbs

Overview

Runs the request and callback phases against OmniAuth.config.mock_auth instead of the provider when OmniAuth.config.test_mode is enabled.

Instance Method Summary collapse

Instance Method Details

#mock_call! ⇒ rack_response

This is called in lieu of the normal request process in the event that OmniAuth has been configured to be in test mode.

Parameters:

  • (Object)

Returns:

  • (rack_response)


9
10
11
12
13
14
15
16
17
18
19
# File 'lib/omniauth/strategy/test_mode.rb', line 9

def mock_call!(*)
  if request_call?
    mock_request_call
  elsif on_callback_path?
    mock_callback_call
  else
    call_app!
  end
rescue StandardError => e
  handle_phase_error(e)
end

#mock_callback_call ⇒ rack_response

Returns:

  • (rack_response)


38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/omniauth/strategy/test_mode.rb', line 38

def mock_callback_call
  setup_phase

  origin = session.delete('omniauth.origin')
  env['omniauth.origin'] ||= origin
  env['omniauth.origin'] = nil if env.fetch('omniauth.origin').eql?('')
  env['omniauth.params'] = session.delete('omniauth.params') || {}

  mocked_auth = OmniAuth.mock_auth_for(name)
  env['omniauth.auth'] = mocked_auth unless mocked_auth.instance_of?(Symbol)
  run_hook(:before_callback_phase)
  mocked_auth.instance_of?(Symbol) ? fail!(mocked_auth) : call_app!
end

#mock_request_call ⇒ rack_response

Returns:

  • (rack_response)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/omniauth/strategy/test_mode.rb', line 21

def mock_request_call
  setup_phase

  run_hook(:request_validation_phase)

  session['omniauth.params'] = omniauth_params

  run_hook(:before_request_phase)

  store_origin if options.origin_param

  result = redirect(callback_url)

  run_hook(:after_request_phase)
  result
end