Sha256: 7ef12625dab964b71ab4827c8728d04909473209f8d261894536eb2f9e52d7fc

Contents?: true

Size: 1.96 KB

Versions: 9

Compression:

Stored size: 1.96 KB

Contents

require 'spec_helper'
require 'active_model'
require 'doorkeeper/oauth/error'
require 'doorkeeper/oauth/error_response'

module Doorkeeper::OAuth
  describe ErrorResponse do
    describe '#status' do
      it 'should have a status of unauthorized' do
        expect(subject.status).to eq(:unauthorized)
      end
    end

    describe :from_request do
      it 'has the error from request' do
        error = ErrorResponse.from_request double(error: :some_error)
        expect(error.name).to eq(:some_error)
      end

      it 'ignores state if request does not respond to state' do
        error = ErrorResponse.from_request double(error: :some_error)
        expect(error.state).to be_nil
      end

      it 'has state if request responds to state' do
        error = ErrorResponse.from_request double(error: :some_error, state: :hello)
        expect(error.state).to eq(:hello)
      end
    end

    it 'ignores empty error values' do
      subject = ErrorResponse.new(error: :some_error, state: nil)
      expect(subject.body).not_to have_key(:state)
    end

    describe '.body' do
      subject { ErrorResponse.new(name: :some_error, state: :some_state).body }

      describe '#body' do
        it { expect(subject).to have_key(:error) }
        it { expect(subject).to have_key(:error_description) }
        it { expect(subject).to have_key(:state) }
      end
    end

    describe '.authenticate_info' do
      let(:error_response) { ErrorResponse.new(name: :some_error, state: :some_state) }
      subject { error_response.authenticate_info }

      it { expect(subject).to include("realm=\"#{error_response.realm}\"") }
      it { expect(subject).to include("error=\"#{error_response.name}\"") }
      it { expect(subject).to include("error_description=\"#{error_response.description}\"") }
    end

    describe '.headers' do
      subject { ErrorResponse.new(name: :some_error, state: :some_state).headers }

      it { expect(subject).to include 'WWW-Authenticate' }
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
doorkeeper-sequel-1.2.1 spec/lib/oauth/error_response_spec.rb
doorkeeper-4.2.0 spec/lib/oauth/error_response_spec.rb
doorkeeper-4.1.0 spec/lib/oauth/error_response_spec.rb
doorkeeper-4.0.0 spec/lib/oauth/error_response_spec.rb
doorkeeper-4.0.0.rc4 spec/lib/oauth/error_response_spec.rb
doorkeeper-4.0.0.rc3 spec/lib/oauth/error_response_spec.rb
doorkeeper-4.0.0.rc2 spec/lib/oauth/error_response_spec.rb
doorkeeper-4.0.0.rc1 spec/lib/oauth/error_response_spec.rb
doorkeeper-3.1.0 spec/lib/oauth/error_response_spec.rb