Sha256: 2b8abf6a7e4f2ed1ea814d87b0ed8e5d7425cec8e18e4709750458c0feab11b2

Contents?: true

Size: 1.4 KB

Versions: 8

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module AuthorizationRequestHelper
  def resource_owner_is_authenticated(resource_owner = nil)
    resource_owner ||= User.create!(name: "Joe", password: "sekret")
    Doorkeeper.config.instance_variable_set(:@authenticate_resource_owner, proc { resource_owner })
  end

  def resource_owner_is_not_authenticated
    Doorkeeper.config.instance_variable_set(:@authenticate_resource_owner, proc { redirect_to("/sign_in") })
  end

  def default_scopes_exist(*scopes)
    Doorkeeper.config.instance_variable_set(:@default_scopes, Doorkeeper::OAuth::Scopes.from_array(scopes))
  end

  def optional_scopes_exist(*scopes)
    Doorkeeper.config.instance_variable_set(:@optional_scopes, Doorkeeper::OAuth::Scopes.from_array(scopes))
  end

  def client_should_be_authorized(client)
    expect(client.access_grants.size).to eq(1)
  end

  def client_should_not_be_authorized(client)
    expect(client.size).to eq(0)
  end

  def i_should_be_on_client_callback(client)
    expect(client.redirect_uri).to eq("#{current_uri.scheme}://#{current_uri.host}#{current_uri.path}")
  end

  def allowing_forgery_protection(&_block)
    original_value = ActionController::Base.allow_forgery_protection
    ActionController::Base.allow_forgery_protection = true

    yield
  ensure
    ActionController::Base.allow_forgery_protection = original_value
  end
end

RSpec.configuration.send :include, AuthorizationRequestHelper

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
doorkeeper-mongodb-5.3.0 spec/support/helpers/authorization_request_helper.rb
doorkeeper-mongodb-5.2.3 spec/support/helpers/authorization_request_helper.rb
doorkeeper-sequel-2.4.0 spec/support/helpers/authorization_request_helper.rb
doorkeeper-mongodb-5.2.2 spec/support/helpers/authorization_request_helper.rb
doorkeeper-sequel-2.3.0 spec/support/helpers/authorization_request_helper.rb
doorkeeper-5.4.0.rc1 spec/support/helpers/authorization_request_helper.rb
doorkeeper-mongodb-5.2.1 spec/support/helpers/authorization_request_helper.rb
doorkeeper-mongodb-5.2.0 spec/support/helpers/authorization_request_helper.rb