MINITEST的OAuth错误,回调链接给了一个错误

问题描述 投票:0回答:1

我试图写OmniAuth用户测试和建立我的test_helper后,我遇到了和坏的URI error.Sharing下面的详细信息:

test_helper.rb中

# OmniAuth auth mock for testing
  def setup_omniauth_mock (user)
    OmniAuth.config.test_mode = true
    OmniAuth::AuthHash.new ({
    'provider'            => 'google',
    'uid'                 => '123545',
    'user_id'             => '2',
    'first_name'          => 'X',
    'last_name'           => 'XYZ',
    'email'               => '[email protected]',
    'image'               => 'https://lh3.googleusercontent.com//photo.jpg',
    'oauth_token'         => 'abcdef12345',
    'oauth_expires_at'    => DateTime.now,
    })
    OmniAuth.config.add_mock(:google, OmniAuth::AuthHash.new)
    get '/auth/":google"/callback'
    Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[:google]
    get '/auth/:google/callback'
  end 

我得到的错误:

    test_validating_a_Google_OAuth_user#SessionsControllerTest (0.49s)
URI::InvalidURIError:         URI::InvalidURIError: bad
URI(is not URI?): http://www.example.com:80/auth/":google"/callback
test/test_helper.rb:42:in `setup_omniauth_mock'

现在,我跟着这里的文档[端Oauth集成测试] [1]

[1]:https://github.com/omniauth/omniauth/wiki/Integration-Testing但我认为有些事情我做错了。

是否有人可以帮助我通过这个指导。

谢谢! J.

ruby-on-rails oauth minitest
1个回答
0
投票

我实际上是由清洁事情有点解决它。

现在我test_helper.rb中:

 # OmniAuth auth mock setup for testing
  setup do
    OmniAuth.config.test_mode = true
    Rails.application.env_config["omniauth.auth"] =
    OmniAuth.config.mock_auth[:google]

  end

  #teardown OmniAuth mock setup
  teardown do
    OmniAuth.config.test_mode = false
  end

  #Google OAuth mock
  def google_oauth2_mock (user)
    OmniAuth.config.mock_auth[:google]
    OmniAuth::AuthHash.new ({
    'provider'            => 'google_oauth2',
    'uid'                 => '123545',
    'user_id'             => '2',
    'first_name'          => 'X',
    'last_name'           => 'XXYZ',
    'email'               => '[email protected]',
    'image'               => 'https://lh3.googleusercontent.com/photo.jpg',
    'oauth_token'         => 'abcdef12345',
    'refresh_token'       => '12345abcdef',
    'oauth_expires_at'    => DateTime.now,
    })
  end

我把路线的单项测试,这让我顺利运行测试套件。

希望我能为您节省时间和挫折。

© www.soinside.com 2019 - 2024. All rights reserved.