首页 文章

无法在测试模式下绕过Omniauth初始化程序

提问于
浏览
1

我试图测试我的graphql架构,而无需任何身份验证 .

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

在邮递员中,我在主体 {"query":"{\n user(id: 1) {\n id\n created_at\n updated_at\n jwt\n}\n}\n","variables":null,"operationName":null} 中有查询,在 Headers 中有Content-Type application / json,这样可以正常工作 .

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

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

虽然我不想,因为我不希望在此帖子请求中需要任何 Headers .

这是我的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'

1 回答

  • 0

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

    这是一个隐藏文件 .

相关问题