Sha256: 80f691d7a2d27930706d614207a525b6381496587e3cb5fe354dc68330f5ec2b

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require "spec_helper"

describe Doorkeeper::OAuth::CodeRequest do
  let(:pre_auth) do
    server = Doorkeeper.configuration
    allow(server)
      .to receive(:default_scopes).and_return(Doorkeeper::OAuth::Scopes.from_string("public"))
    allow(server)
      .to receive(:grant_flows).and_return(Doorkeeper::OAuth::Scopes.from_string("authorization_code"))

    application = FactoryBot.create(:application, scopes: "public")
    client = Doorkeeper::OAuth::Client.new(application)

    attributes = {
      client_id: client.uid,
      response_type: "code",
      redirect_uri: "https://app.com/callback",
    }

    pre_auth = Doorkeeper::OAuth::PreAuthorization.new(server, attributes)
    pre_auth.authorizable?
    pre_auth
  end

  let(:owner) { FactoryBot.create(:resource_owner) }

  subject do
    described_class.new(pre_auth, owner)
  end

  context "when pre_auth is authorized" do
    it "creates an access grant and returns a code response" do
      expect { subject.authorize }.to change { Doorkeeper::AccessGrant.count }.by(1)
      expect(subject.authorize).to be_a(Doorkeeper::OAuth::CodeResponse)
    end
  end

  context "when pre_auth is denied" do
    it "does not create access grant and returns a error response" do
      expect { subject.deny }.not_to(change { Doorkeeper::AccessGrant.count })
      expect(subject.deny).to be_a(Doorkeeper::OAuth::ErrorResponse)
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
doorkeeper-5.4.0.rc1 spec/lib/oauth/code_request_spec.rb
doorkeeper-mongodb-5.2.1 spec/lib/oauth/code_request_spec.rb
doorkeeper-mongodb-5.2.0 spec/lib/oauth/code_request_spec.rb