Sha256: 88215673155b013f5fad58ec29b6bba1eeaf8f089076a0aa2338c3bae1789fe4

Contents?: true

Size: 1.68 KB

Versions: 5

Compression:

Stored size: 1.68 KB

Contents

require 'rest-core/test'

describe RC::ClientOauth1 do
  after do
    WebMock.reset!
    RR.verify
  end

  client = RC::Builder.client do
    use RC::Oauth1Header
  end

  client.send(:include, RC::ClientOauth1)

  should 'restore data with correct sig' do
    data = {'a' => 'b', 'c' => 'd'}
    sig = Digest::MD5.hexdigest('e&a=b&c=d')
    data_sig = data.merge('sig' => sig)
    data_json = RC::Json.encode(data_sig)
    @client = client.new(:data => data, :consumer_secret => 'e')

    @client.send(:calculate_sig).should.eq sig
    @client.data_json.should.eq data_json

    @client.data_json = data_json
    @client.data.should.eq data_sig

    @client.data_json = RC::Json.encode(data_sig.merge('sig' => 'wrong'))
    @client.data.should.eq({})

    @client.data_json = data_json
    @client.data.should.eq data_sig

    @client.data_json = 'bad json'
    @client.data.should.eq({})
  end

  should 'have correct default data' do
    @client = client.new
    @client.data.should.eq({})
    @client.data = nil
    @client.data['a'] = 'b'
    @client.data['a'].should.eq 'b'
  end

  should 'authorize' do
    stub_request(:post, 'http://localhost').
      to_return(:body => 'oauth_token=abc')

    stub_request(:post, 'http://nocalhost').
      to_return(:body => 'user_id=123&haha=point')

    @client = client.new(:request_token_path => 'http://localhost',
                         :authorize_path     => 'http://mocalhost',
                         :access_token_path  => 'http://nocalhost')

    @client.authorize_url!.should.eq 'http://mocalhost?oauth_token=abc'
    @client.authorize!.should.eq('user_id' => '123', 'haha' => 'point',
                                 'authorized' => 'true')
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rest-core-2.0.4 test/test_client_oauth1.rb
rest-core-2.0.3 test/test_client_oauth1.rb
rest-core-2.0.2 test/test_client_oauth1.rb
rest-core-2.0.1 test/test_client_oauth1.rb
rest-core-2.0.0 test/test_client_oauth1.rb