Sha256: aa85dd7f9ce93acb3a571c9285139d2e7d8e7952e2161ac8a4c4e24be2b4035c

Contents?: true

Size: 1.52 KB

Versions: 7

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'
require 'active_support/all'
require 'doorkeeper/errors'
require 'doorkeeper/server'

describe Doorkeeper::Server do
  let(:fake_class) { double :fake_class }

  subject do
    described_class.new
  end

  describe '.authorization_request' do
    it 'raises error when strategy does not exist' do
      expect do
        subject.authorization_request(:duh)
      end.to raise_error(Doorkeeper::Errors::InvalidAuthorizationStrategy)
    end

    it 'raises error when strategy does not match phase' do
      expect do
        subject.token_request(:code)
      end.to raise_error(Doorkeeper::Errors::InvalidTokenStrategy)
    end

    context 'when only Authorization Code strategy is enabled' do
      before do
        allow(Doorkeeper.configuration).
          to receive(:grant_flows).
          and_return(['authorization_code'])
      end

      it 'raises error when using the disabled Implicit strategy' do
        expect do
          subject.authorization_request(:token)
        end.to raise_error(Doorkeeper::Errors::InvalidAuthorizationStrategy)
      end

      it 'raises error when using the disabled Client Credentials strategy' do
        expect do
          subject.token_request(:client_credentials)
        end.to raise_error(Doorkeeper::Errors::InvalidTokenStrategy)
      end
    end

    it 'builds the request with selected strategy' do
      stub_const 'Doorkeeper::Request::Code', fake_class
      expect(fake_class).to receive(:build).with(subject)
      subject.authorization_request :code
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
doorkeeper-3.0.1 spec/lib/server_spec.rb
doorkeeper-2.2.2 spec/lib/server_spec.rb
doorkeeper-3.0.0 spec/lib/server_spec.rb
doorkeeper-3.0.0.rc2 spec/lib/server_spec.rb
doorkeeper-3.0.0.rc1 spec/lib/server_spec.rb
doorkeeper-2.2.1 spec/lib/server_spec.rb
doorkeeper-2.2.0 spec/lib/server_spec.rb