【问题标题】:Cannot bypass Omniauth initializer in test mode在测试模式下无法绕过 Omniauth 初始化程序
【发布时间】:2018-10-19 14:09:56
【问题描述】:

我正在尝试测试我的 graphql 架构而不需要任何身份验证。

我已将skip_before_action :verify_authenticity_token 添加到GraphqlController,并且在使用邮递员时(由来自graphiql 的curl 请求复制),并且在开发模式下看到了成功的查询。

在邮递员中,我在正文 {"query":"{\n user(id: 1) {\n id\n created_at\n updated_at\n jwt\n}\n}\n","variables":null,"operationName":null} 中有查询,在标题中有 Content-Type application/json,这工作正常。

现在处于测试模式,我正在使用 Omniauth 的身份验证初始化程序:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider(
    :auth0,
    Auth0::Config["app_client_id"],
    Auth0::Config["app_client_secret"],
    Auth0::Config["domain"],
    callback_path: "/auth/auth0/callback"
  )
end

虽然我不想这样做,因为我不希望此帖子请求中需要任何标头。

这是我的 rspec 请求:

require 'graphlient'

RSpec.shared_context "GraphQL Client", shared_context: :metadata do
  let(:client) do
    Graphlient::Client.new('https://api.example.org/graphql') do |client|
      client.http do |h|
        h.connection do |c|
          c.use Faraday::Adapter::Rack, app
        end
      end
    end
  end
end

这是实际测试

it 'retrieves schema' do
  expect(client.schema).to be_a GraphQL::Schema
end

出现错误:

 Failure/Error:
   expect { client.schema.status }
     .to raise_error(Graphlient::Errors::ServerError)

   expected Graphlient::Errors::ServerError, got #<ArgumentError: Received wrong number of arguments. [nil, nil, nil, {:callback_path=>"/auth/auth0/callback"}]> with backtrace:
     # /usr/local/bundle/gems/omniauth-auth0-1.4.2/lib/omniauth/strategies/auth0.rb:41:in `initialize'

【问题讨论】:

    标签: ruby-on-rails rspec graphql omniauth


    【解决方案1】:

    我想我明白了!我忘记在 config/auth0.yml 中添加用于测试的密钥。

    这是一个隐藏文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-19
      • 1970-01-01
      • 2011-05-21
      • 2014-02-12
      • 1970-01-01
      • 1970-01-01
      • 2022-08-03
      相关资源
      最近更新 更多