Sha256: fc24ee372e76e16a31eb2466f91a20abbe9f2d15b22717e92eb69cd8bb4d705e

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

require File.expand_path('../test_helper', __FILE__)
require 'oauth/signature/hmac/sha1'

class SignatureHMACSHA1Test < Test::Unit::TestCase
  def test_that_verify_returns_true_when_the_request_signature_is_right
    request = OAuth::RequestProxy::MockRequest.new(
      'method' => 'POST',
      'uri' => 'https://photos.example.net/initialize',
      'parameters' => {
        'oauth_consumer_key' => 'dpf43f3p2l4k3l03',
        'oauth_signature_method' => 'HMAC-SHA1',
        'oauth_timestamp' => '137131200',
        'oauth_nonce' => 'wIjqoS',
        'oauth_callback' => 'http://printer.example.com/ready',
        'oauth_version' => '1.0',
        'oauth_signature' => 'xcHYBV3AbyoDz7L4dV10P3oLCjY='
      }
    )
    assert OAuth::Signature::HMAC::SHA1.new(request, :consumer_secret => 'kd94hf93k423kf44').verify
  end

  def test_that_verify_returns_false_when_the_request_signature_is_wrong
    # Test a bug in the OAuth::Signature::Base#== method: when the Base64.decode64 method is
    # used on the "self" and "other" signature (as in version 0.4.7), the result may be incorrectly "true".
    request = OAuth::RequestProxy::MockRequest.new(
      'method' => 'POST',
      'uri' => 'https://photos.example.net/initialize',
      'parameters' => {
        'oauth_consumer_key' => 'dpf43f3p2l4k3l03',
        'oauth_signature_method' => 'HMAC-SHA1',
        'oauth_timestamp' => '137131200',
        'oauth_nonce' => 'wIjqoS',
        'oauth_callback' => 'http://printer.example.com/ready',
        'oauth_version' => '1.0',
        'oauth_signature' => 'xcHYBV3AbyoDz7L4dV10P3oLCjZ='
      }
    )
    assert !OAuth::Signature::HMAC::SHA1.new(request, :consumer_secret => 'kd94hf93k423kf44').verify
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
oauth-0.5.0 test/test_signature_hmac_sha1.rb