【问题标题】:rails+capybara+selenium testing google oauth2 callbackrails+capybara+selenium 测试 google oauth2 回调
【发布时间】:2013-12-09 14:55:29
【问题描述】:

我正在使用 selenium 测试我的 google oauth2 登录:

#spec/featurers/google_spec.rb
require 'spec_helper'

describe "the signin process", type: :feature do
    before do
      Capybara.current_driver = :selenium
      visit  user_omniauth_authorize_path(:google_oauth2)
      fill_in "Email", :with => 'test@gmail.com'
      fill_in "Password", :with => 'test'
      click_button 'Accedi'
      #in this point it crash
      click_button 'Consenti'
    end
    it { page.should have_content('Google') }
end

它有效,但我在管理 google 回调时遇到问题:

Errore:redirect_uri_mismatch
The redirect URI in the request: http://127.0.0.1:58272/users/auth/google_oauth2/callback did not match a registered redirect URI

我该如何管理这个回调?如果进行真正的测试,而不是 127.0.01:58272 我有 localhost:3000 并且它可以工作。

解决方案

在 spec_helper.rb 中,或者更具体地说,在你的规范文件中的 before 块中。

describe "the signin process" do
  before do
    Capybara.run_server = true #Whether start server when testing
    Capybara.current_driver = :selenium
    Capybara.server_host= 'localhost' #this is the goal 
    Capybara.server_port = 3000
    visit user_omniauth_authorize_path(:google_oauth2)
  end
  it {#some}
end

【问题讨论】:

标签: ruby-on-rails selenium capybara


【解决方案1】:

redirect_uri 仅在您在控制台中的 https://code.google.com/apis/console/ 上生成客户端 ID 时才有效。

创建客户端 ID 时,您必须选择 Installed Application 以使其工作。有关生成客户端 ID 的更多信息:https://developers.google.com/console/help/#generatingoauth2

【讨论】:

  • 我刚刚发布了我的解决方案
  • 所以你已经在你的谷歌控制台中为 127.0.0.1:3000 创建了一个客户端 ID?请记住,通过将测试环境的端口设置为 3000,您必须确保没有处于开发模式的服务器在端口 3000 上运行。
猜你喜欢
  • 2018-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多