Sha256: e3a5f2c097a82580747bce64d72d1de03face6c24bb893379109cbbd2453a3ec

Contents?: true

Size: 1.74 KB

Versions: 43

Compression:

Stored size: 1.74 KB

Contents

require 'spec_helper.rb'

describe Rack::OAuth2::Server::Resource::MAC::Unauthorized do
  let(:error) { Rack::OAuth2::Server::Resource::MAC::Unauthorized.new(:invalid_token) }

  it { should be_a Rack::OAuth2::Server::Resource::Unauthorized }

  describe '#scheme' do
    subject { error }
    its(:scheme) { should == :MAC }
  end

  describe '#finish' do
    it 'should use MAC scheme' do
      status, header, response = error.finish
      header['WWW-Authenticate'].should =~ /^MAC /
    end
  end
end

describe Rack::OAuth2::Server::Resource::MAC::ErrorMethods do
  let(:unauthorized)        { Rack::OAuth2::Server::Resource::MAC::Unauthorized }
  let(:redirect_uri)        { 'http://client.example.com/callback' }
  let(:default_description) { Rack::OAuth2::Server::Resource::ErrorMethods::DEFAULT_DESCRIPTION }
  let(:env)                 { Rack::MockRequest.env_for("/authorize?client_id=client_id") }
  let(:request)             { Rack::OAuth2::Server::Resource::MAC::Request.new env }

  describe 'unauthorized!' do
    it do
      expect { request.unauthorized! :invalid_client }.should raise_error unauthorized
    end
  end

  Rack::OAuth2::Server::Resource::Bearer::ErrorMethods::DEFAULT_DESCRIPTION.keys.each do |error_code|
    method = "#{error_code}!"
    case error_code
    when :invalid_request
      # ignore
    when :insufficient_scope
      # ignore
    else
      describe method do
        it "should raise Rack::OAuth2::Server::Resource::Bearer::Unauthorized with error = :#{error_code}" do
          expect { request.send method }.should raise_error(unauthorized) { |error|
            error.error.should       == error_code
            error.description.should == default_description[error_code]
          }
        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
rack-oauth2-0.14.6 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.14.5 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.14.4 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.14.3 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.14.2 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.14.1 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.14.0 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.13.0 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.12.2 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.12.1 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.12.0 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.11.0 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.10.1 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.10.0 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.10.0.alpha spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.9.5 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.9.4 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.9.3 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.9.2 spec/rack/oauth2/server/resource/mac/error_spec.rb
rack-oauth2-0.9.1 spec/rack/oauth2/server/resource/mac/error_spec.rb