|
| 1 | +require File.expand_path('../../test_helper', __FILE__) |
| 2 | + |
| 3 | +require 'oauth/signature/hmac/sha256' |
| 4 | + |
| 5 | +class SignatureHMACSHA256Test < Minitest::Test |
| 6 | + def test_that_verify_returns_true_when_the_request_signature_is_right |
| 7 | + request = OAuth::RequestProxy::MockRequest.new( |
| 8 | + 'method' => 'POST', |
| 9 | + 'uri' => 'https://photos.example.net/initialize', |
| 10 | + 'parameters' => { |
| 11 | + 'oauth_consumer_key' => 'dpf43f3p2l4k3l03', |
| 12 | + 'oauth_signature_method' => 'HMAC-SHA256', |
| 13 | + 'oauth_timestamp' => '137131200', |
| 14 | + 'oauth_nonce' => 'wIjqoS', |
| 15 | + 'oauth_callback' => 'http://printer.example.com/ready', |
| 16 | + 'oauth_version' => '1.0', |
| 17 | + 'oauth_signature' => 'tkpCGNHi3laWBHQ9+Ka5IOeixEuhxg12LTMlLJxQxKc=' |
| 18 | + } |
| 19 | + ) |
| 20 | + assert OAuth::Signature::HMAC::SHA256.new(request, :consumer_secret => 'kd94hf93k423kf44').verify |
| 21 | + end |
| 22 | + |
| 23 | + def test_that_verify_returns_false_when_the_request_signature_is_wrong |
| 24 | + # Test a bug in the OAuth::Signature::Base#== method: when the Base64.decode64 method is |
| 25 | + # used on the "self" and "other" signature (as in version 0.4.7), the result may be incorrectly "true". |
| 26 | + request = OAuth::RequestProxy::MockRequest.new( |
| 27 | + 'method' => 'POST', |
| 28 | + 'uri' => 'https://photos.example.net/initialize', |
| 29 | + 'parameters' => { |
| 30 | + 'oauth_consumer_key' => 'dpf43f3p2l4k3l03', |
| 31 | + 'oauth_signature_method' => 'HMAC-SHA256', |
| 32 | + 'oauth_timestamp' => '137131200', |
| 33 | + 'oauth_nonce' => 'wIjqoS', |
| 34 | + 'oauth_callback' => 'http://printer.example.com/ready', |
| 35 | + 'oauth_version' => '1.0', |
| 36 | + 'oauth_signature' => 'tkpCGNHi3laWBHQ9+Ka5IOeixEuhxg12LTMlLJxQxKZ=' |
| 37 | + } |
| 38 | + ) |
| 39 | + assert !OAuth::Signature::HMAC::SHA256.new(request, :consumer_secret => 'kd94hf93k423kf44').verify |
| 40 | + end |
| 41 | +end |
0 commit comments