Sha256: ded4c727c06161c9b35163e25edb7989ac63476c2f85c0224874c1910bbee322

Contents?: true

Size: 1.44 KB

Versions: 7

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper_integration'

describe Doorkeeper::TokensController do
  describe 'when authorization has succeeded' do
    let :token do
      double(:token, authorize: true)
    end

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

    it 'returns the authorization' do
      skip 'verify need of these specs'

      expect(token).to receive(:authorization)

      post :create
    end
  end

  describe 'when authorization has failed' do
    it 'returns the error response' do
      token = double(:token, authorize: false)
      allow(controller).to receive(:token) { token }

      post :create

      expect(response.status).to eq 401
      expect(response.headers['WWW-Authenticate']).to match(/Bearer/)
    end
  end

  describe 'when revoke authorization has failed' do
    # http://tools.ietf.org/html/rfc7009#section-2.2
    it 'returns no error response' do
      token = double(:token, authorize: false)
      allow(controller).to receive(:token) { token }

      post :revoke

      expect(response.status).to eq 200
    end
  end

  describe 'authorize response memoization' do
    it "memoizes the result of the authorization" do
      strategy = double(:strategy, authorize: true)
      expect(strategy).to receive(:authorize).once
      allow(controller).to receive(:strategy) { strategy }
      allow(controller).to receive(:create) do
        controller.send :authorize_response
      end

      post :create
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
doorkeeper-3.0.1 spec/controllers/tokens_controller_spec.rb
doorkeeper-2.2.2 spec/controllers/tokens_controller_spec.rb
doorkeeper-3.0.0 spec/controllers/tokens_controller_spec.rb
doorkeeper-3.0.0.rc2 spec/controllers/tokens_controller_spec.rb
doorkeeper-3.0.0.rc1 spec/controllers/tokens_controller_spec.rb
doorkeeper-2.2.1 spec/controllers/tokens_controller_spec.rb
doorkeeper-2.2.0 spec/controllers/tokens_controller_spec.rb