Sha256: 455d47e236f6eab17ef367c896d08ffacf724701c7f93b1d21b5912217121b3e

Contents?: true

Size: 1.32 KB

Versions: 9

Compression:

Stored size: 1.32 KB

Contents

require 'spec_helper.rb'

describe Rack::OAuth2::Server::Token::AuthorizationCode do
  let(:request) { Rack::MockRequest.new app }
  let(:app) do
    Rack::OAuth2::Server::Token.new do |request, response|
      response.access_token = Rack::OAuth2::AccessToken::Bearer.new(access_token: 'access_token')
    end
  end
  let(:params) do
    {
      grant_type: 'authorization_code',
      client_id: 'client_id',
      code: 'authorization_code',
      redirect_uri: 'http://client.example.com/callback'
    }
  end
  let(:response) { request.post('/', params: params) }
  subject { response }

  its(:status)       { should == 200 }
  its(:content_type) { should == 'application/json' }
  its(:body)         { should include '"access_token":"access_token"' }
  its(:body)         { should include '"token_type":"bearer"' }

  it 'should prevent to be cached' do
    response.headers['Cache-Control'].should == 'no-store'
    response.headers['Pragma'].should == 'no-cache'
  end

  [:code].each do |required|
    context "when #{required} is missing" do
      before do
        params.delete_if do |key, value|
          key == required
        end
      end
      its(:status)       { should == 400 }
      its(:content_type) { should == 'application/json' }
      its(:body)         { should include '"error":"invalid_request"' }
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rack-oauth2-2.2.1 spec/rack/oauth2/server/token/authorization_code_spec.rb
rack-oauth2-2.2.0 spec/rack/oauth2/server/token/authorization_code_spec.rb
rack-oauth2-2.1.0 spec/rack/oauth2/server/token/authorization_code_spec.rb
rack-oauth2-2.0.1 spec/rack/oauth2/server/token/authorization_code_spec.rb
rack-oauth2-2.0.0 spec/rack/oauth2/server/token/authorization_code_spec.rb
rack-oauth2-2.0.0.rc3 spec/rack/oauth2/server/token/authorization_code_spec.rb
rack-oauth2-2.0.0.rc2 spec/rack/oauth2/server/token/authorization_code_spec.rb
rack-oauth2-2.0.0.rc1 spec/rack/oauth2/server/token/authorization_code_spec.rb
rack-oauth2-1.21.3 spec/rack/oauth2/server/token/authorization_code_spec.rb