CognitoIdentityProvider

CognitoIdentityProvider

我在Rails控制器问题中有以下模块:

module AwsAuth
  extend ActiveSupport::Concern

  require 'aws-sdk'

  def get_cognito_user(token)
    cognitoidentityprovider = Aws::CognitoIdentityProvider::Client.new(region: ENV['AWS_REGION'])

    begin
      cognito_user = cognitoidentityprovider.get_user({ access_token: token })

      puts cognito_user

      return {"email" => cognito_user.username}

    rescue StandardError => msg
      puts "ERROR!"
      puts msg
      return {"error" => msg}
    end
  end
end

目前,puts cognito_用户返回:
#<Aws::CognitoIdentityProvider::Types::GetUserResponse:0x7fe51b0013a8
    mfa_options = nil,
    user_attributes = nil,
    username = nil
>

如何研究rspec中的响应,使用户名和用户属性不为零?

最佳答案

在考虑了伊扎尔文的建议之后…以下对我有用…

allow_any_instance_of( AwsAuth )
      .to receive(:get_cognito_user)
      .and_return( JSON[ {email: "[email protected]"}.to_json ] )

关于ruby-on-rails - 来自AWS CognitoIdentityProvider的WebMock stub 数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44450158/

10-13 07:59