Sha256: 8062c357fc36256518cabb7bc7ac3257c671b21021d4ce63f2394c61f089befa

Contents?: true

Size: 1.86 KB

Versions: 34

Compression:

Stored size: 1.86 KB

Contents

require 'spec_helper'

describe Github::Request::OAuth2 do
  include Github::Utils::Url

  def auth_header(env)
    env[:request_headers]['Authorization']
  end

  def middleware
    described_class.new(lambda { |env| env }, options)
  end

  def process(params={}, headers={})
    env = {
      :url => URI('http://example.com/?' + build_query(params)),
      :request_headers => headers
    }
    middleware.call(env)
  end

  context 'no token configured' do
    let(:options) { nil }

    it "doesn't add params" do
      result = process(:q => 'query')
      result[:url].query.should eql 'q=query'
    end

    it "doesn't add headers" do
      auth_header(process).should be_nil
    end

    it "allows for ad hoc access token" do
      result = process(:q => 'query', :access_token => 'abc123')
      result[:url].query.should eql 'access_token=abc123&q=query'
    end

    it "creates header for ad hoc access token" do
      result = process(:q => 'query', :access_token => 'abc123')
      auth_header(result).should eql 'Token token="abc123"'
    end
  end

  context 'default token configured' do
    let(:options) { 'ABC' }

    it "adds access token to params" do
      result = process(:q => 'query')
      result[:url].query.should eql 'access_token=ABC&q=query'
    end

    it "creates header for access token" do
      auth_header(process).should eql 'Token token="ABC"'
    end

    it "overrides default with explicit token" do
      result = process(:q => 'query', :access_token => 'abc123')
      result[:url].query.should eql 'access_token=abc123&q=query'
      auth_header(result).should eql 'Token token="abc123"'
    end

    it "clears default token with explicit one" do
      result = process(:q => 'query', :access_token => nil)
      result[:url].query.should eql 'q=query&access_token'
      auth_header(result).should be_nil
    end
  end

end # Github::Request::OAuth2

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
github_api-0.10.1 spec/github/request/oauth2_spec.rb
github_api-0.10.0 spec/github/request/oauth2_spec.rb
github_api-0.9.7 spec/github/request/oauth2_spec.rb
github_api-0.9.6 spec/github/request/oauth2_spec.rb
github_api-0.9.5 spec/github/request/oauth2_spec.rb
github_api-0.9.4 spec/github/request/oauth2_spec.rb
github_api-0.9.3 spec/github/request/oauth2_spec.rb
github_api-0.9.2 spec/github/request/oauth2_spec.rb
github_api-0.9.1 spec/github/request/oauth2_spec.rb
github_api-0.9.0 spec/github/request/oauth2_spec.rb
github_api-0.8.11 spec/github/request/oauth2_spec.rb
github_api-0.8.10 spec/github/request/oauth2_spec.rb
github_api-0.8.9 spec/github/request/oauth2_spec.rb
github_api-0.8.8 spec/github/request/oauth2_spec.rb
github_api-0.8.7 spec/github/request/oauth2_spec.rb
github_api-0.8.6 spec/github/request/oauth2_spec.rb
github_api-0.8.5 spec/github/request/oauth2_spec.rb
github_api-0.8.4 spec/github/request/oauth2_spec.rb
github_api-0.8.3 spec/github/request/oauth2_spec.rb
github_api-0.8.2 spec/github/request/oauth2_spec.rb