forked from mojodna/oauth
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow access to token parameters and raw Response.
Additionally adds the ability to include arbitrary parameters to generated authorization urls. Includes new tests for RequestToken and AccessToken.
- Loading branch information
Showing
3 changed files
with
108 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require File.dirname(__FILE__) + '/test_helper.rb' | ||
require 'oauth/token' | ||
require 'oauth/consumer' | ||
|
||
class TestAccessToken < Test::Unit::TestCase | ||
def setup | ||
@fake_response = { | ||
:user_id => 5734758743895, | ||
:oauth_token => "key", | ||
:oauth_token_secret => "secret" | ||
} | ||
# setup a fake req. token. mocking Consumer would be more appropriate... | ||
@access_token = OAuth::AccessToken.from_hash( | ||
OAuth::Consumer.new("key", "secret", {}), | ||
@fake_response | ||
) | ||
end | ||
|
||
def test_provides_response_parameters | ||
assert @access_token | ||
assert_respond_to @access_token, :params | ||
end | ||
|
||
def test_access_token_makes_non_oauth_response_params_available | ||
assert_not_nil @access_token.params[:user_id] | ||
assert_equal 5734758743895, @access_token.params[:user_id] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require File.dirname(__FILE__) + '/test_helper.rb' | ||
require 'oauth/token' | ||
require 'oauth/consumer' | ||
|
||
class StubbedToken < OAuth::RequestToken | ||
define_method :build_authorize_url_promoted do |root_domain, params| | ||
build_authorize_url root_domain, params | ||
end | ||
end | ||
|
||
class TestRequestToken < Test::Unit::TestCase | ||
def setup | ||
# setup a fake req. token. mocking Consumer would be more appropriate... | ||
@request_token = OAuth::RequestToken.new( | ||
OAuth::Consumer.new("key", "secret", {}), | ||
"key", | ||
"secret" | ||
) | ||
end | ||
|
||
def test_request_token_builds_authorize_url_connectly_with_additional_params | ||
auth_url = @request_token.authorize_url({:oauth_callback => "github.com"}) | ||
assert_not_nil auth_url | ||
assert_match(/oauth_token/, auth_url) | ||
assert_match(/oauth_callback/, auth_url) | ||
end | ||
|
||
def test_request_token_builds_authorize_url_connectly_with_no_or_nil_params | ||
# we should only have 1 key in the url returned if we didn't pass anything. | ||
# this is the only required param to authenticate the client. | ||
auth_url = @request_token.authorize_url(nil) | ||
assert_not_nil auth_url | ||
assert_match(/\?oauth_token=/, auth_url) | ||
|
||
auth_url = @request_token.authorize_url | ||
assert_not_nil auth_url | ||
assert_match(/\?oauth_token=/, auth_url) | ||
end | ||
|
||
#TODO: mock out the Consumer to test the Consumer/AccessToken interaction. | ||
def test_get_access_token | ||
end | ||
|
||
def test_build_authorize_url | ||
@stubbed_token = StubbedToken.new(nil, nil, nil) | ||
assert_respond_to @stubbed_token, :build_authorize_url_promoted | ||
url = @stubbed_token.build_authorize_url_promoted( | ||
"http://github.com/oauth/authorize", | ||
{:foo => "bar bar"}) | ||
assert url | ||
assert_equal "http://github.com/oauth/authorize?foo=bar+bar", url | ||
end | ||
end |