M
M
Maxim Savichev2016-08-28 12:37:15
Ruby on Rails
Maxim Savichev, 2016-08-28 12:37:15

Why doesn't the oauth authorization test pass with the correct host?

The task is this: to test authorization through facebook.
Problem (message that pops up when testing after a click_on event):

Warning
Невозможно загрузить URL: Домен этого URL не включен в список доменов приложения. Чтобы загрузить этот URL, добавьте все домены и поддомены своего приложения в поле «Домены приложения» в настройках вашего приложения.

Test code:
require 'acceptance_helper'

feature 'User sign in with oauth' do
  scenario 'can sign in user with Facebook account', :js do
    visit new_user_session_path
    expect(page).to have_content('Sign in with Facebook')
    mock_auth_hash_facebook

    click_on 'Sign in with Facebook'

    expect(page).to have_content I18n.t('devise.sessions.signed_in')
    expect(current_path).to eq root_path
  end
end

Macro code:
module OmniauthMacros
  def mock_auth_hash_facebook
    OmniAuth.config.mock_auth[:facebook] = {
        provider: 'facebook',
        uid: '1234567',
        info: {
            email: '[email protected]',
        },
        credentials: {
            token: 'mock_token',
            secret: 'mock_secret'
        }
    }
  end
end

gemfile:
gem 'omniauth'
gem 'omniauth-facebook'

In the FB settings
site URL: localhost:3000
Tried to set port 31337 and declare the same port in the test, nothing helped
After reading the problem message, I added the host 'localhost' to 'Application Domains'.
When running the test, the problem still appears.
But if you set Capybara.server_host =31337 and set sleep, then 'manually' everything goes through and becomes authorized.
Maybe I missed something? What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Savichev, 2016-08-29
@MaksimSa

I found a solution to the problem, you just need to read the documentation better. In order for the mock to start working as a stub, you need to set it in the config before the test:
OmniAuth.config.test_mode = true
Information taken from: https://github.com/omniauth/omniauth/wiki/Integrat...
Use a real request to facebook during the execution of the tests is not necessary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question