oauth-instructure 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +47 -0
- data/HISTORY +174 -0
- data/LICENSE +20 -0
- data/README.rdoc +75 -0
- data/Rakefile +37 -0
- data/TODO +32 -0
- data/bin/oauth +5 -0
- data/examples/yql.rb +44 -0
- data/lib/digest/hmac.rb +104 -0
- data/lib/oauth.rb +13 -0
- data/lib/oauth/cli.rb +378 -0
- data/lib/oauth/client.rb +4 -0
- data/lib/oauth/client/action_pack.rb +9 -0
- data/lib/oauth/client/em_http.rb +120 -0
- data/lib/oauth/client/helper.rb +91 -0
- data/lib/oauth/client/net_http.rb +120 -0
- data/lib/oauth/consumer.rb +389 -0
- data/lib/oauth/core_ext.rb +31 -0
- data/lib/oauth/errors.rb +3 -0
- data/lib/oauth/errors/error.rb +4 -0
- data/lib/oauth/errors/problem.rb +14 -0
- data/lib/oauth/errors/unauthorized.rb +12 -0
- data/lib/oauth/helper.rb +109 -0
- data/lib/oauth/oauth.rb +13 -0
- data/lib/oauth/oauth_test_helper.rb +25 -0
- data/lib/oauth/request_proxy.rb +24 -0
- data/lib/oauth/request_proxy/action_controller_request.rb +116 -0
- data/lib/oauth/request_proxy/action_dispatch_request.rb +113 -0
- data/lib/oauth/request_proxy/base.rb +174 -0
- data/lib/oauth/request_proxy/curb_request.rb +55 -0
- data/lib/oauth/request_proxy/em_http_request.rb +66 -0
- data/lib/oauth/request_proxy/jabber_request.rb +41 -0
- data/lib/oauth/request_proxy/mock_request.rb +44 -0
- data/lib/oauth/request_proxy/net_http.rb +73 -0
- data/lib/oauth/request_proxy/rack_request.rb +44 -0
- data/lib/oauth/request_proxy/typhoeus_request.rb +53 -0
- data/lib/oauth/server.rb +66 -0
- data/lib/oauth/signature.rb +45 -0
- data/lib/oauth/signature/base.rb +110 -0
- data/lib/oauth/signature/hmac/base.rb +15 -0
- data/lib/oauth/signature/hmac/md5.rb +8 -0
- data/lib/oauth/signature/hmac/rmd160.rb +8 -0
- data/lib/oauth/signature/hmac/sha1.rb +9 -0
- data/lib/oauth/signature/hmac/sha2.rb +8 -0
- data/lib/oauth/signature/md5.rb +13 -0
- data/lib/oauth/signature/plaintext.rb +23 -0
- data/lib/oauth/signature/rsa/sha1.rb +46 -0
- data/lib/oauth/signature/sha1.rb +13 -0
- data/lib/oauth/token.rb +7 -0
- data/lib/oauth/tokens/access_token.rb +71 -0
- data/lib/oauth/tokens/consumer_token.rb +33 -0
- data/lib/oauth/tokens/request_token.rb +32 -0
- data/lib/oauth/tokens/server_token.rb +9 -0
- data/lib/oauth/tokens/token.rb +17 -0
- data/oauth.gemspec +148 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/cases/oauth_case.rb +19 -0
- data/test/cases/spec/1_0-final/test_construct_request_url.rb +62 -0
- data/test/cases/spec/1_0-final/test_normalize_request_parameters.rb +88 -0
- data/test/cases/spec/1_0-final/test_parameter_encodings.rb +86 -0
- data/test/cases/spec/1_0-final/test_signature_base_strings.rb +77 -0
- data/test/integration/consumer_test.rb +307 -0
- data/test/keys/rsa.cert +11 -0
- data/test/keys/rsa.pem +16 -0
- data/test/test_access_token.rb +26 -0
- data/test/test_action_controller_request_proxy.rb +133 -0
- data/test/test_consumer.rb +220 -0
- data/test/test_curb_request_proxy.rb +77 -0
- data/test/test_em_http_client.rb +80 -0
- data/test/test_em_http_request_proxy.rb +115 -0
- data/test/test_helper.rb +28 -0
- data/test/test_hmac_sha1.rb +20 -0
- data/test/test_net_http_client.rb +292 -0
- data/test/test_net_http_request_proxy.rb +72 -0
- data/test/test_oauth_helper.rb +94 -0
- data/test/test_rack_request_proxy.rb +40 -0
- data/test/test_request_token.rb +51 -0
- data/test/test_rsa_sha1.rb +59 -0
- data/test/test_server.rb +40 -0
- data/test/test_signature.rb +22 -0
- data/test/test_signature_base.rb +32 -0
- data/test/test_signature_plain_text.rb +31 -0
- data/test/test_token.rb +14 -0
- data/test/test_typhoeus_request_proxy.rb +80 -0
- metadata +274 -0
data/test/keys/rsa.cert
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIBpjCCAQ+gAwIBAgIBATANBgkqhkiG9w0BAQUFADAZMRcwFQYDVQQDDA5UZXN0
|
3
|
+
IFByaW5jaXBhbDAeFw03MDAxMDEwODAwMDBaFw0zODEyMzEwODAwMDBaMBkxFzAV
|
4
|
+
BgNVBAMMDlRlc3QgUHJpbmNpcGFsMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB
|
5
|
+
gQC0YjCwIfYoprq/FQO6lb3asXrxLlJFuCvtinTF5p0GxvQGu5O3gYytUvtC2JlY
|
6
|
+
zypSRjVxwxrsuRcP3e641SdASwfrmzyvIgP08N4S0IFzEURkV1wp/IpH7kH41Etb
|
7
|
+
mUmrXSwfNZsnQRE5SYSOhh+LcK2wyQkdgcMv11l4KoBkcwIDAQABMA0GCSqGSIb3
|
8
|
+
DQEBBQUAA4GBAGZLPEuJ5SiJ2ryq+CmEGOXfvlTtEL2nuGtr9PewxkgnOjZpUy+d
|
9
|
+
4TvuXJbNQc8f4AMWL/tO9w0Fk80rWKp9ea8/df4qMq5qlFWlx6yOLQxumNOmECKb
|
10
|
+
WpkUQDIDJEoFUzKMVuJf4KO/FJ345+BNLGgbJ6WujreoM1X/gYfdnJ/J
|
11
|
+
-----END CERTIFICATE-----
|
data/test/keys/rsa.pem
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
-----BEGIN PRIVATE KEY-----
|
2
|
+
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALRiMLAh9iimur8V
|
3
|
+
A7qVvdqxevEuUkW4K+2KdMXmnQbG9Aa7k7eBjK1S+0LYmVjPKlJGNXHDGuy5Fw/d
|
4
|
+
7rjVJ0BLB+ubPK8iA/Tw3hLQgXMRRGRXXCn8ikfuQfjUS1uZSatdLB81mydBETlJ
|
5
|
+
hI6GH4twrbDJCR2Bwy/XWXgqgGRzAgMBAAECgYBYWVtleUzavkbrPjy0T5FMou8H
|
6
|
+
X9u2AC2ry8vD/l7cqedtwMPp9k7TubgNFo+NGvKsl2ynyprOZR1xjQ7WgrgVB+mm
|
7
|
+
uScOM/5HVceFuGRDhYTCObE+y1kxRloNYXnx3ei1zbeYLPCHdhxRYW7T0qcynNmw
|
8
|
+
rn05/KO2RLjgQNalsQJBANeA3Q4Nugqy4QBUCEC09SqylT2K9FrrItqL2QKc9v0Z
|
9
|
+
zO2uwllCbg0dwpVuYPYXYvikNHHg+aCWF+VXsb9rpPsCQQDWR9TT4ORdzoj+Nccn
|
10
|
+
qkMsDmzt0EfNaAOwHOmVJ2RVBspPcxt5iN4HI7HNeG6U5YsFBb+/GZbgfBT3kpNG
|
11
|
+
WPTpAkBI+gFhjfJvRw38n3g/+UeAkwMI2TJQS4n8+hid0uus3/zOjDySH3XHCUno
|
12
|
+
cn1xOJAyZODBo47E+67R4jV1/gzbAkEAklJaspRPXP877NssM5nAZMU0/O/NGCZ+
|
13
|
+
3jPgDUno6WbJn5cqm8MqWhW1xGkImgRk+fkDBquiq4gPiT898jusgQJAd5Zrr6Q8
|
14
|
+
AO/0isr/3aa6O6NLQxISLKcPDk2NOccAfS/xOtfOz4sJYM3+Bs4Io9+dZGSDCA54
|
15
|
+
Lw03eHTNQghS0A==
|
16
|
+
-----END PRIVATE KEY-----
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class TestAccessToken < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@fake_response = {
|
6
|
+
:user_id => 5734758743895,
|
7
|
+
:oauth_token => "key",
|
8
|
+
:oauth_token_secret => "secret"
|
9
|
+
}
|
10
|
+
# setup a fake req. token. mocking Consumer would be more appropriate...
|
11
|
+
@access_token = OAuth::AccessToken.from_hash(
|
12
|
+
OAuth::Consumer.new("key", "secret", {}),
|
13
|
+
@fake_response
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_provides_response_parameters
|
18
|
+
assert @access_token
|
19
|
+
assert_respond_to @access_token, :params
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_access_token_makes_non_oauth_response_params_available
|
23
|
+
assert_not_nil @access_token.params[:user_id]
|
24
|
+
assert_equal 5734758743895, @access_token.params[:user_id]
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
gem 'actionpack', '~> 2.3.8'
|
2
|
+
require File.expand_path('../test_helper', __FILE__)
|
3
|
+
|
4
|
+
require 'oauth/request_proxy/action_controller_request'
|
5
|
+
require 'action_controller/test_process'
|
6
|
+
|
7
|
+
class ActionControllerRequestProxyTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def request_proxy(request_method = :get, uri_params = {}, body_params = {})
|
10
|
+
request = ActionController::TestRequest.new
|
11
|
+
request.set_REQUEST_URI('/')
|
12
|
+
|
13
|
+
case request_method
|
14
|
+
when :post
|
15
|
+
request.env['REQUEST_METHOD'] = 'POST'
|
16
|
+
when :put
|
17
|
+
request.env['REQUEST_METHOD'] = 'PUT'
|
18
|
+
end
|
19
|
+
|
20
|
+
request.env['REQUEST_URI'] = '/'
|
21
|
+
request.env['RAW_POST_DATA'] = body_params.to_query
|
22
|
+
request.env['QUERY_STRING'] = body_params.to_query
|
23
|
+
request.env['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
|
24
|
+
|
25
|
+
yield request if block_given?
|
26
|
+
OAuth::RequestProxy::ActionControllerRequest.new(request, :parameters => uri_params)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_that_proxy_simple_get_request_works_with_query_params
|
30
|
+
request_proxy = request_proxy(:get, {'key'=>'value'})
|
31
|
+
|
32
|
+
expected_parameters = [["key", "value"]]
|
33
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
34
|
+
assert_equal 'GET', request_proxy.method
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_that_proxy_simple_post_request_works_with_query_params
|
38
|
+
request_proxy = request_proxy(:post, {'key'=>'value'})
|
39
|
+
|
40
|
+
expected_parameters = [["key", "value"]]
|
41
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
42
|
+
assert_equal 'POST', request_proxy.method
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_that_proxy_simple_put_request_works_with_query_params
|
46
|
+
request_proxy = request_proxy(:put, {'key'=>'value'})
|
47
|
+
|
48
|
+
expected_parameters = [["key", "value"]]
|
49
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
50
|
+
assert_equal 'PUT', request_proxy.method
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_that_proxy_simple_get_request_works_with_post_params
|
54
|
+
request_proxy = request_proxy(:get, {}, {'key'=>'value'})
|
55
|
+
|
56
|
+
expected_parameters = []
|
57
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
58
|
+
assert_equal 'GET', request_proxy.method
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_that_proxy_simple_post_request_works_with_post_params
|
62
|
+
request_proxy = request_proxy(:post, {}, {'key'=>'value'})
|
63
|
+
|
64
|
+
expected_parameters = [["key", "value"]]
|
65
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
66
|
+
assert_equal 'POST', request_proxy.method
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_that_proxy_simple_put_request_works_with_post_params
|
70
|
+
request_proxy = request_proxy(:put, {}, {'key'=>'value'})
|
71
|
+
|
72
|
+
expected_parameters = []
|
73
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
74
|
+
assert_equal 'PUT', request_proxy.method
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_that_proxy_simple_get_request_works_with_mixed_params
|
78
|
+
request_proxy = request_proxy(:get, {'key'=>'value'}, {'key2'=>'value2'})
|
79
|
+
|
80
|
+
expected_parameters = [["key", "value"]]
|
81
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
82
|
+
assert_equal 'GET', request_proxy.method
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_that_proxy_simple_post_request_works_with_mixed_params
|
86
|
+
request_proxy = request_proxy(:post, {'key'=>'value'}, {'key2'=>'value2'})
|
87
|
+
|
88
|
+
expected_parameters = [["key", "value"],["key2", "value2"]]
|
89
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
90
|
+
assert_equal 'POST', request_proxy.method
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_that_proxy_simple_put_request_works_with_mixed_params
|
94
|
+
request_proxy = request_proxy(:put, {'key'=>'value'}, {'key2'=>'value2'})
|
95
|
+
|
96
|
+
expected_parameters = [["key", "value"]]
|
97
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
98
|
+
assert_equal 'PUT', request_proxy.method
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_parameter_keys_should_preserve_brackets_from_hash
|
102
|
+
assert_equal(
|
103
|
+
[["message[body]", "This is a test"]],
|
104
|
+
request_proxy(:post, { :message => { :body => 'This is a test' }}).parameters_for_signature
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_parameter_values_with_amps_should_not_break_parameter_parsing
|
109
|
+
assert_equal(
|
110
|
+
[['message[body]', 'http://foo.com/?a=b&c=d']],
|
111
|
+
request_proxy(:post, { :message => { :body => 'http://foo.com/?a=b&c=d'}}).parameters_for_signature
|
112
|
+
)
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_parameter_keys_should_preserve_brackets_from_array
|
116
|
+
assert_equal(
|
117
|
+
[["foo[]", "123"], ["foo[]", "456"]],
|
118
|
+
request_proxy(:post, { :foo => [123, 456] }).parameters_for_signature.sort
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
# TODO disabled; ActionController::TestRequest does not appear to parse
|
123
|
+
# QUERY_STRING
|
124
|
+
def x_test_query_string_parameter_values_should_be_cgi_unescaped
|
125
|
+
request = request_proxy do |r|
|
126
|
+
r.env['QUERY_STRING'] = 'url=http%3A%2F%2Ffoo.com%2F%3Fa%3Db%26c%3Dd'
|
127
|
+
end
|
128
|
+
assert_equal(
|
129
|
+
[['url', 'http://foo.com/?a=b&c=d']],
|
130
|
+
request.parameters_for_signature.sort
|
131
|
+
)
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,220 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
require 'mocha'
|
3
|
+
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
# This performs testing against Andy Smith's test server http://term.ie/oauth/example/
|
7
|
+
# Thanks Andy.
|
8
|
+
# This also means you have to be online to be able to run these.
|
9
|
+
class ConsumerTest < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@consumer=OAuth::Consumer.new(
|
12
|
+
'consumer_key_86cad9', '5888bf0345e5d237',
|
13
|
+
{
|
14
|
+
:site=>"http://blabla.bla",
|
15
|
+
:proxy=>"http://user:password@proxy.bla:8080",
|
16
|
+
:request_token_path=>"/oauth/example/request_token.php",
|
17
|
+
:access_token_path=>"/oauth/example/access_token.php",
|
18
|
+
:authorize_path=>"/oauth/example/authorize.php",
|
19
|
+
:scheme=>:header,
|
20
|
+
:http_method=>:get
|
21
|
+
})
|
22
|
+
@token = OAuth::ConsumerToken.new(@consumer,'token_411a7f', '3196ffd991c8ebdb')
|
23
|
+
@request_uri = URI.parse('http://example.com/test?key=value')
|
24
|
+
@request_parameters = { 'key' => 'value' }
|
25
|
+
@nonce = 225579211881198842005988698334675835446
|
26
|
+
@timestamp = "1199645624"
|
27
|
+
@consumer.http=Net::HTTP.new(@request_uri.host, @request_uri.port)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_initializer
|
31
|
+
assert_equal "consumer_key_86cad9",@consumer.key
|
32
|
+
assert_equal "5888bf0345e5d237",@consumer.secret
|
33
|
+
assert_equal "http://blabla.bla",@consumer.site
|
34
|
+
assert_equal "http://user:password@proxy.bla:8080",@consumer.proxy
|
35
|
+
assert_equal "/oauth/example/request_token.php",@consumer.request_token_path
|
36
|
+
assert_equal "/oauth/example/access_token.php",@consumer.access_token_path
|
37
|
+
assert_equal "http://blabla.bla/oauth/example/request_token.php",@consumer.request_token_url
|
38
|
+
assert_equal "http://blabla.bla/oauth/example/access_token.php",@consumer.access_token_url
|
39
|
+
assert_equal "http://blabla.bla/oauth/example/authorize.php",@consumer.authorize_url
|
40
|
+
assert_equal :header,@consumer.scheme
|
41
|
+
assert_equal :get,@consumer.http_method
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_defaults
|
45
|
+
@consumer=OAuth::Consumer.new(
|
46
|
+
"key",
|
47
|
+
"secret",
|
48
|
+
{
|
49
|
+
:site=>"http://twitter.com"
|
50
|
+
})
|
51
|
+
assert_equal "key",@consumer.key
|
52
|
+
assert_equal "secret",@consumer.secret
|
53
|
+
assert_equal "http://twitter.com",@consumer.site
|
54
|
+
assert_nil @consumer.proxy
|
55
|
+
assert_equal "/oauth/request_token",@consumer.request_token_path
|
56
|
+
assert_equal "/oauth/access_token",@consumer.access_token_path
|
57
|
+
assert_equal "http://twitter.com/oauth/request_token",@consumer.request_token_url
|
58
|
+
assert_equal "http://twitter.com/oauth/access_token",@consumer.access_token_url
|
59
|
+
assert_equal "http://twitter.com/oauth/authorize",@consumer.authorize_url
|
60
|
+
assert_equal :header,@consumer.scheme
|
61
|
+
assert_equal :post,@consumer.http_method
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_site_without_path
|
65
|
+
@consumer=OAuth::Consumer.new(
|
66
|
+
"key",
|
67
|
+
"secret",
|
68
|
+
{
|
69
|
+
:site=>"http://twitter.com"
|
70
|
+
})
|
71
|
+
request = stub(:oauth! => nil)
|
72
|
+
http = stub(:request => stub(:to_hash => {}))
|
73
|
+
Net::HTTP::Get.expects(:new).with('/people', {}).returns(request)
|
74
|
+
@consumer.expects(:create_http).returns(http)
|
75
|
+
@consumer.request(:get, '/people', nil, {})
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_site_with_path
|
79
|
+
@consumer=OAuth::Consumer.new(
|
80
|
+
"key",
|
81
|
+
"secret",
|
82
|
+
{
|
83
|
+
:site=>"http://identi.ca/api"
|
84
|
+
})
|
85
|
+
request = stub(:oauth! => nil)
|
86
|
+
http = stub(:request => stub(:to_hash => {}))
|
87
|
+
Net::HTTP::Get.expects(:new).with('/api/people', {}).returns(request)
|
88
|
+
@consumer.expects(:create_http).returns(http)
|
89
|
+
@consumer.request(:get, '/people', nil, {})
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_post_of_nested_params_maintains_nesting
|
93
|
+
@consumer=OAuth::Consumer.new(
|
94
|
+
"key",
|
95
|
+
"secret",
|
96
|
+
{
|
97
|
+
:site=>"http://twitter.com"
|
98
|
+
})
|
99
|
+
request = @consumer.create_signed_request(
|
100
|
+
:post,
|
101
|
+
'/people',
|
102
|
+
nil,
|
103
|
+
{},
|
104
|
+
{
|
105
|
+
:key => {
|
106
|
+
:subkey => 'value'
|
107
|
+
}
|
108
|
+
})
|
109
|
+
assert_equal 'key%5Bsubkey%5D=value', request.body
|
110
|
+
assert_equal request.content_type, 'application/x-www-form-urlencoded'
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_override_paths
|
114
|
+
@consumer=OAuth::Consumer.new(
|
115
|
+
"key",
|
116
|
+
"secret",
|
117
|
+
{
|
118
|
+
:site=>"http://twitter.com",
|
119
|
+
:request_token_url=>"http://oauth.twitter.com/request_token",
|
120
|
+
:access_token_url=>"http://oauth.twitter.com/access_token",
|
121
|
+
:authorize_url=>"http://site.twitter.com/authorize"
|
122
|
+
})
|
123
|
+
assert_equal "key",@consumer.key
|
124
|
+
assert_equal "secret",@consumer.secret
|
125
|
+
assert_equal "http://twitter.com",@consumer.site
|
126
|
+
assert_equal "/oauth/request_token",@consumer.request_token_path
|
127
|
+
assert_equal "/oauth/access_token",@consumer.access_token_path
|
128
|
+
assert_equal "http://oauth.twitter.com/request_token",@consumer.request_token_url
|
129
|
+
assert_equal "http://oauth.twitter.com/access_token",@consumer.access_token_url
|
130
|
+
assert_equal "http://site.twitter.com/authorize",@consumer.authorize_url
|
131
|
+
assert_equal :header,@consumer.scheme
|
132
|
+
assert_equal :post,@consumer.http_method
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_that_token_response_should_be_uri_parameter_format_as_default
|
136
|
+
@consumer.expects(:request).returns(create_stub_http_response("oauth_token=token&oauth_token_secret=secret"))
|
137
|
+
|
138
|
+
hash = @consumer.token_request(:get, "")
|
139
|
+
|
140
|
+
assert_equal "token", hash[:oauth_token]
|
141
|
+
assert_equal "secret", hash[:oauth_token_secret]
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_can_provided_a_block_to_interpret_token_response
|
145
|
+
@consumer.expects(:request).returns(create_stub_http_response)
|
146
|
+
|
147
|
+
hash = @consumer.token_request(:get, '') {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
|
148
|
+
|
149
|
+
assert_equal 'token', hash[:oauth_token]
|
150
|
+
assert_equal 'secret', hash[:oauth_token_secret]
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_token_request_follows_redirect
|
154
|
+
redirect_url = @request_uri.clone
|
155
|
+
redirect_url.path = "/oauth/example/request_token_redirect.php"
|
156
|
+
stub_request(:get, /.*#{@request_uri.path}/).to_return(:status => 301, :headers => {'Location' => redirect_url.to_s})
|
157
|
+
stub_request(:get, /.*#{redirect_url.path}/).to_return(:body => "oauth_token=token&oauth_token_secret=secret")
|
158
|
+
|
159
|
+
hash = @consumer.token_request(:get, @request_uri.path) {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
|
160
|
+
|
161
|
+
assert_equal 'token', hash[:oauth_token]
|
162
|
+
assert_equal 'secret', hash[:oauth_token_secret]
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_that_can_provide_a_block_to_interpret_a_request_token_response
|
166
|
+
@consumer.expects(:request).returns(create_stub_http_response)
|
167
|
+
|
168
|
+
token = @consumer.get_request_token {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
|
169
|
+
|
170
|
+
assert_equal 'token', token.token
|
171
|
+
assert_equal 'secret', token.secret
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_that_block_is_not_mandatory_for_getting_an_access_token
|
175
|
+
stub_token = mock
|
176
|
+
@consumer.expects(:request).returns(create_stub_http_response("oauth_token=token&oauth_token_secret=secret"))
|
177
|
+
|
178
|
+
token = @consumer.get_access_token(stub_token)
|
179
|
+
|
180
|
+
assert_equal 'token', token.token
|
181
|
+
assert_equal 'secret', token.secret
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_that_can_provide_a_block_to_interpret_an_access_token_response
|
185
|
+
stub_token = mock
|
186
|
+
@consumer.expects(:request).returns(create_stub_http_response)
|
187
|
+
|
188
|
+
token = @consumer.get_access_token(stub_token) {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
|
189
|
+
|
190
|
+
assert_equal 'token', token.token
|
191
|
+
assert_equal 'secret', token.secret
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_that_not_setting_ignore_callback_will_include_oauth_callback_in_request_options
|
195
|
+
request_options = {}
|
196
|
+
@consumer.stubs(:request).returns(create_stub_http_response)
|
197
|
+
|
198
|
+
@consumer.get_request_token(request_options) {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
|
199
|
+
|
200
|
+
assert_equal 'oob', request_options[:oauth_callback]
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_that_setting_ignore_callback_will_exclude_oauth_callback_in_request_options
|
204
|
+
request_options = { :exclude_callback=> true }
|
205
|
+
@consumer.stubs(:request).returns(create_stub_http_response)
|
206
|
+
|
207
|
+
@consumer.get_request_token(request_options) {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
|
208
|
+
|
209
|
+
assert_nil request_options[:oauth_callback]
|
210
|
+
end
|
211
|
+
|
212
|
+
private
|
213
|
+
|
214
|
+
def create_stub_http_response expected_body=nil
|
215
|
+
stub_http_response = stub
|
216
|
+
stub_http_response.stubs(:code).returns(200)
|
217
|
+
stub_http_response.stubs(:body).tap {|expectation| expectation.returns(expected_body) unless expected_body.nil? }
|
218
|
+
return stub_http_response
|
219
|
+
end
|
220
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
begin
|
4
|
+
|
5
|
+
require 'oauth/request_proxy/curb_request'
|
6
|
+
require 'curb'
|
7
|
+
|
8
|
+
|
9
|
+
class CurbRequestProxyTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_that_proxy_simple_get_request_works
|
12
|
+
request = Curl::Easy.new('/test?key=value')
|
13
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value'})
|
14
|
+
|
15
|
+
expected_parameters = {'key' => ['value']}
|
16
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
17
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_that_proxy_simple_post_request_works_with_arguments
|
21
|
+
request = Curl::Easy.new('/test')
|
22
|
+
params = {'key' => 'value'}
|
23
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params})
|
24
|
+
|
25
|
+
expected_parameters = {'key' => 'value'}
|
26
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
27
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_that_proxy_simple_post_request_works_with_form_data
|
31
|
+
request = Curl::Easy.new('/test')
|
32
|
+
request.post_body = 'key=value'
|
33
|
+
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
34
|
+
|
35
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'})
|
36
|
+
|
37
|
+
expected_parameters = {'key' => 'value'}
|
38
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
39
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_that_proxy_simple_put_request_works_with_arguments
|
43
|
+
request = Curl::Easy.new('/test')
|
44
|
+
params = {'key' => 'value'}
|
45
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params})
|
46
|
+
|
47
|
+
expected_parameters = {'key' => 'value'}
|
48
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
49
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_that_proxy_simple_put_request_works_with_form_data
|
53
|
+
request = Curl::Easy.new('/test')
|
54
|
+
request.post_body = 'key=value'
|
55
|
+
|
56
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'})
|
57
|
+
|
58
|
+
expected_parameters = {}
|
59
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
60
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_that_proxy_post_request_works_with_mixed_parameter_sources
|
64
|
+
request = Curl::Easy.new('/test?key=value')
|
65
|
+
request.post_body = 'key2=value2'
|
66
|
+
request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
67
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value', :parameters => {'key3' => 'value3'}})
|
68
|
+
|
69
|
+
expected_parameters = {'key' => ['value'], 'key2' => 'value2', 'key3' => 'value3'}
|
70
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
71
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
rescue LoadError => e
|
76
|
+
warn "! problems loading curb, skipping these tests: #{e}"
|
77
|
+
end
|