Sha256: b7e686762e1a5c56c77e71ef68a3b4e6605a896ae8934e1ecddfdaeffc99b4d9

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe 'bearer authentication' do
  context 'bearer' do
    before(:each) do
      class MyResource < ActiveResource::Base
        self.auth_type = :bearer

        self.site = 'http://spec.invalid/'
      end
    end

    it 'sets bearer token' do
      MyResource.token = 'spoken'

      MyResource.connection.send(:authorization_header, :get, '/my_uri').should == { 'Authorization' => 'Bearer spoken' }
      MyResource.token.should == 'spoken'
    end

    it 'sets bearer token lazily' do
      MyResource.token do
        "JRR_Token"
      end

      MyResource.connection.send(:authorization_header, :get, '/my_uri').should == { 'Authorization' => 'Bearer JRR_Token' }
      MyResource.token.should == 'JRR_Token'
    end
  end

  context 'passthrough' do
    before(:each) do
      class MyPassthroughResource < ActiveResource::Base
        self.auth_type = :basic

        self.site = 'http://user:pass@spec.invalid'
      end
    end

    it 'still accepts other auths' do
      MyPassthroughResource.connection.should_receive(:authorization_header_without_bearer).with(:get, '/my_uri')

      MyPassthroughResource.connection.send(:authorization_header, :get, '/my_uri')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activeresource_bearer_authentication-0.0.3 spec/bearer_authentication_spec.rb
activeresource_bearer_authentication-0.0.2 spec/bearer_authentication_spec.rb
activeresource_bearer_authentication-0.0.1 spec/bearer_authentication_spec.rb