Sha256: d8d0b3f4bf72b066fa217d8bc5dfa69ea056b8f2fdda40ef8d0852e4399c45ca

Contents?: true

Size: 1.56 KB

Versions: 22

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper_integration'

describe Doorkeeper::TokenInfoController do
  describe 'when requesting tokeninfo with valid token' do
    let(:doorkeeper_token) { FactoryGirl.create(:access_token) }

    before(:each) do
      allow(controller).to receive(:doorkeeper_token) { doorkeeper_token }
    end

    def do_get
      get :show
    end

    describe 'successful request' do

      it 'responds with tokeninfo' do
        do_get
        expect(response.body).to eq(doorkeeper_token.to_json)
      end

      it 'responds with a 200 status' do
        do_get
        expect(response.status).to eq 200
      end
    end

    describe 'invalid token response' do
      before(:each) do
        allow(controller).to receive(:doorkeeper_token).and_return(nil)
      end
      it 'responds with 401 when doorkeeper_token is not valid' do
        do_get
        expect(response.status).to eq 401
        expect(response.headers['WWW-Authenticate']).to match(/^Bearer/)
      end

      it 'responds with 401 when doorkeeper_token is invalid, expired or revoked' do
        allow(controller).to receive(:doorkeeper_token).and_return(doorkeeper_token)
        allow(doorkeeper_token).to receive(:accessible?).and_return(false)
        do_get
        expect(response.status).to eq 401
        expect(response.headers['WWW-Authenticate']).to match(/^Bearer/)
      end

      it 'responds body message for error' do
        do_get
        expect(response.body).to eq(Doorkeeper::OAuth::ErrorResponse.new(name: :invalid_request, status: :unauthorized).body.to_json)
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
doorkeeper-sequel-1.3.1 spec/controllers/token_info_controller_spec.rb
doorkeeper-sequel-1.3.0 spec/controllers/token_info_controller_spec.rb
doorkeeper-sequel-1.2.3 spec/controllers/token_info_controller_spec.rb
doorkeeper-sequel-1.2.2 spec/controllers/token_info_controller_spec.rb
doorkeeper-4.2.6 spec/controllers/token_info_controller_spec.rb
doorkeeper-4.2.5 spec/controllers/token_info_controller_spec.rb
doorkeeper-sequel-1.2.1 spec/controllers/token_info_controller_spec.rb
doorkeeper-4.2.0 spec/controllers/token_info_controller_spec.rb
doorkeeper-4.1.0 spec/controllers/token_info_controller_spec.rb
doorkeeper-4.0.0 spec/controllers/token_info_controller_spec.rb
doorkeeper-4.0.0.rc4 spec/controllers/token_info_controller_spec.rb
doorkeeper-4.0.0.rc3 spec/controllers/token_info_controller_spec.rb
doorkeeper-4.0.0.rc2 spec/controllers/token_info_controller_spec.rb
doorkeeper-4.0.0.rc1 spec/controllers/token_info_controller_spec.rb
doorkeeper-3.1.0 spec/controllers/token_info_controller_spec.rb
doorkeeper-3.0.1 spec/controllers/token_info_controller_spec.rb
doorkeeper-2.2.2 spec/controllers/token_info_controller_spec.rb
doorkeeper-3.0.0 spec/controllers/token_info_controller_spec.rb
doorkeeper-3.0.0.rc2 spec/controllers/token_info_controller_spec.rb
doorkeeper-3.0.0.rc1 spec/controllers/token_info_controller_spec.rb