Sha256: f508d818839cd122b38f82a87997512ae0ce3a0bdca280cfd7f609cda5bad50f

Contents?: true

Size: 1.91 KB

Versions: 23

Compression:

Stored size: 1.91 KB

Contents

require 'spec_helper.rb'

describe Rack::OAuth2::Server::Authorize::Code do
  let(:request)            { Rack::MockRequest.new app }
  let(:redirect_uri)       { 'http://client.example.com/callback' }
  let(:authorization_code) { 'authorization_code' }
  let(:response)           { request.get "/?response_type=code&client_id=client&redirect_uri=#{redirect_uri}&state=state" }

  context 'when approved' do
    subject { response }
    let :app do
      Rack::OAuth2::Server::Authorize.new do |request, response|
        response.redirect_uri = redirect_uri
        response.code = authorization_code
        response.approve!
      end
    end
    its(:status)   { should == 302 }
    its(:location) { should == "#{redirect_uri}?code=#{authorization_code}&state=state" }

    context 'when redirect_uri already includes query' do
      let(:redirect_uri) { 'http://client.example.com/callback?k=v' }
      its(:location)     { should == "#{redirect_uri}&code=#{authorization_code}&state=state" }
    end

    context 'when redirect_uri is missing' do
      let(:redirect_uri) { nil }
      it do
        expect { response }.to raise_error AttrRequired::AttrMissing
      end
    end

    context 'when code is missing' do
      let(:authorization_code) { nil }
      it do
        expect { response }.to raise_error AttrRequired::AttrMissing
      end
    end
  end

  context 'when denied' do
    let :app do
      Rack::OAuth2::Server::Authorize.new do |request, response|
        request.verify_redirect_uri! redirect_uri
        request.access_denied!
      end
    end
    it 'should redirect with error in query' do
      response.status.should == 302
      error_message = {
        error: :access_denied,
        error_description: Rack::OAuth2::Server::Authorize::ErrorMethods::DEFAULT_DESCRIPTION[:access_denied]
      }
      response.location.should == "#{redirect_uri}?#{error_message.to_query.gsub('+', '%20')}&state=state"
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
rack-oauth2-2.2.1 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-2.2.0 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-2.1.0 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-2.0.1 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-2.0.0 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-2.0.0.rc3 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-2.0.0.rc2 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-2.0.0.rc1 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-1.21.3 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-1.21.2 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-1.21.1 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-1.21.0 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-1.20.0 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-1.19.0 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-1.18.0 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-1.17.0 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-1.16.0 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-1.15.0 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-1.14.0 spec/rack/oauth2/server/authorize/code_spec.rb
rack-oauth2-1.13.0 spec/rack/oauth2/server/authorize/code_spec.rb