oauth 0.5.0 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.rdoc +22 -9
- data/bin/oauth +8 -2
- data/lib/oauth.rb +2 -2
- data/lib/oauth/cli.rb +37 -359
- data/lib/oauth/cli/authorize_command.rb +71 -0
- data/lib/oauth/cli/base_command.rb +208 -0
- data/lib/oauth/cli/help_command.rb +22 -0
- data/lib/oauth/cli/query_command.rb +25 -0
- data/lib/oauth/cli/sign_command.rb +81 -0
- data/lib/oauth/cli/version_command.rb +7 -0
- data/lib/oauth/client/action_controller_request.rb +1 -1
- data/lib/oauth/client/em_http.rb +0 -1
- data/lib/oauth/client/helper.rb +8 -2
- data/lib/oauth/client/net_http.rb +0 -1
- data/lib/oauth/consumer.rb +69 -13
- data/lib/oauth/helper.rb +10 -6
- data/lib/oauth/request_proxy/action_controller_request.rb +2 -2
- data/lib/oauth/request_proxy/action_dispatch_request.rb +7 -0
- data/lib/oauth/request_proxy/base.rb +6 -2
- data/lib/oauth/tokens/request_token.rb +14 -7
- data/lib/oauth/version.rb +1 -1
- metadata +93 -96
- data/lib/oauth/core_ext.rb +0 -31
- data/test/cases/oauth_case.rb +0 -19
- data/test/cases/spec/1_0-final/test_construct_request_url.rb +0 -62
- data/test/cases/spec/1_0-final/test_normalize_request_parameters.rb +0 -88
- data/test/cases/spec/1_0-final/test_parameter_encodings.rb +0 -86
- data/test/cases/spec/1_0-final/test_signature_base_strings.rb +0 -77
- data/test/integration/consumer_test.rb +0 -307
- data/test/test_access_token.rb +0 -26
- data/test/test_action_controller_request_proxy.rb +0 -157
- data/test/test_consumer.rb +0 -226
- data/test/test_curb_request_proxy.rb +0 -77
- data/test/test_em_http_client.rb +0 -80
- data/test/test_em_http_request_proxy.rb +0 -115
- data/test/test_helper.rb +0 -33
- data/test/test_hmac_sha1.rb +0 -20
- data/test/test_net_http_client.rb +0 -298
- data/test/test_net_http_request_proxy.rb +0 -72
- data/test/test_oauth_helper.rb +0 -94
- data/test/test_rack_request_proxy.rb +0 -40
- data/test/test_request_token.rb +0 -56
- data/test/test_rest_client_request_proxy.rb +0 -81
- data/test/test_rsa_sha1.rb +0 -59
- data/test/test_server.rb +0 -41
- data/test/test_signature.rb +0 -15
- data/test/test_signature_base.rb +0 -32
- data/test/test_signature_hmac_sha1.rb +0 -40
- data/test/test_signature_plain_text.rb +0 -31
- data/test/test_token.rb +0 -14
- data/test/test_typhoeus_request_proxy.rb +0 -101
data/test/test_access_token.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
class TestAccessToken < Minitest::Test
|
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 @access_token.params[:user_id]
|
24
|
-
assert_equal 5734758743895, @access_token.params[:user_id]
|
25
|
-
end
|
26
|
-
end
|
@@ -1,157 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
require 'oauth/request_proxy/action_controller_request'
|
4
|
-
|
5
|
-
class ActionControllerRequestProxyTest < Minitest::Test
|
6
|
-
|
7
|
-
def request_proxy(request_method = :get, uri_params = {}, body_params = {})
|
8
|
-
request = ActionDispatch::TestRequest.new
|
9
|
-
request.request_uri = '/'
|
10
|
-
|
11
|
-
case request_method
|
12
|
-
when :post
|
13
|
-
request.env['REQUEST_METHOD'] = 'POST'
|
14
|
-
when :put
|
15
|
-
request.env['REQUEST_METHOD'] = 'PUT'
|
16
|
-
when :patch
|
17
|
-
request.env['REQUEST_METHOD'] = 'PATCH'
|
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_patch_request_works_with_query_params
|
54
|
-
request_proxy = request_proxy(:patch, {'key'=>'value'})
|
55
|
-
|
56
|
-
expected_parameters = [["key", "value"]]
|
57
|
-
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
58
|
-
assert_equal 'PATCH', request_proxy.method
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_that_proxy_simple_get_request_works_with_post_params
|
62
|
-
request_proxy = request_proxy(:get, {}, {'key'=>'value'})
|
63
|
-
|
64
|
-
expected_parameters = []
|
65
|
-
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
66
|
-
assert_equal 'GET', request_proxy.method
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_that_proxy_simple_post_request_works_with_post_params
|
70
|
-
request_proxy = request_proxy(:post, {}, {'key'=>'value'})
|
71
|
-
|
72
|
-
expected_parameters = [["key", "value"]]
|
73
|
-
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
74
|
-
assert_equal 'POST', request_proxy.method
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_that_proxy_simple_put_request_works_with_post_params
|
78
|
-
request_proxy = request_proxy(:put, {}, {'key'=>'value'})
|
79
|
-
|
80
|
-
expected_parameters = []
|
81
|
-
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
82
|
-
assert_equal 'PUT', request_proxy.method
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_that_proxy_simple_patch_request_works_with_post_params
|
86
|
-
request_proxy = request_proxy(:patch, {}, {'key'=>'value'})
|
87
|
-
|
88
|
-
expected_parameters = []
|
89
|
-
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
90
|
-
assert_equal 'PATCH', request_proxy.method
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_that_proxy_simple_get_request_works_with_mixed_params
|
94
|
-
request_proxy = request_proxy(:get, {'key'=>'value'}, {'key2'=>'value2'})
|
95
|
-
|
96
|
-
expected_parameters = [["key", "value"]]
|
97
|
-
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
98
|
-
assert_equal 'GET', request_proxy.method
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_that_proxy_simple_post_request_works_with_mixed_params
|
102
|
-
request_proxy = request_proxy(:post, {'key'=>'value'}, {'key2'=>'value2'})
|
103
|
-
|
104
|
-
expected_parameters = [["key", "value"],["key2", "value2"]]
|
105
|
-
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
106
|
-
assert_equal 'POST', request_proxy.method
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_that_proxy_simple_put_request_works_with_mixed_params
|
110
|
-
request_proxy = request_proxy(:put, {'key'=>'value'}, {'key2'=>'value2'})
|
111
|
-
|
112
|
-
expected_parameters = [["key", "value"]]
|
113
|
-
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
114
|
-
assert_equal 'PUT', request_proxy.method
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_that_proxy_simple_patch_request_works_with_mixed_params
|
118
|
-
request_proxy = request_proxy(:patch, {'key'=>'value'}, {'key2'=>'value2'})
|
119
|
-
|
120
|
-
expected_parameters = [["key", "value"]]
|
121
|
-
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
122
|
-
assert_equal 'PATCH', request_proxy.method
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_parameter_keys_should_preserve_brackets_from_hash
|
126
|
-
assert_equal(
|
127
|
-
[["message[body]", "This is a test"]],
|
128
|
-
request_proxy(:post, { :message => { :body => 'This is a test' }}).parameters_for_signature
|
129
|
-
)
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_parameter_values_with_amps_should_not_break_parameter_parsing
|
133
|
-
assert_equal(
|
134
|
-
[['message[body]', 'http://foo.com/?a=b&c=d']],
|
135
|
-
request_proxy(:post, { :message => { :body => 'http://foo.com/?a=b&c=d'}}).parameters_for_signature
|
136
|
-
)
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_parameter_keys_should_preserve_brackets_from_array
|
140
|
-
assert_equal(
|
141
|
-
[["foo[]", "123"], ["foo[]", "456"]],
|
142
|
-
request_proxy(:post, { :foo => [123, 456] }).parameters_for_signature.sort
|
143
|
-
)
|
144
|
-
end
|
145
|
-
|
146
|
-
# TODO disabled; ActionController::TestRequest does not appear to parse
|
147
|
-
# QUERY_STRING
|
148
|
-
def x_test_query_string_parameter_values_should_be_cgi_unescaped
|
149
|
-
request = request_proxy do |r|
|
150
|
-
r.env['QUERY_STRING'] = 'url=http%3A%2F%2Ffoo.com%2F%3Fa%3Db%26c%3Dd'
|
151
|
-
end
|
152
|
-
assert_equal(
|
153
|
-
[['url', 'http://foo.com/?a=b&c=d']],
|
154
|
-
request.parameters_for_signature.sort
|
155
|
-
)
|
156
|
-
end
|
157
|
-
end
|
data/test/test_consumer.rb
DELETED
@@ -1,226 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', __FILE__)
|
2
|
-
|
3
|
-
require 'stringio'
|
4
|
-
|
5
|
-
# This performs testing against Andy Smith's test server http://term.ie/oauth/example/
|
6
|
-
# Thanks Andy.
|
7
|
-
# This also means you have to be online to be able to run these.
|
8
|
-
class ConsumerTest < Minitest::Test
|
9
|
-
def setup
|
10
|
-
@consumer=OAuth::Consumer.new(
|
11
|
-
'consumer_key_86cad9', '5888bf0345e5d237',
|
12
|
-
{
|
13
|
-
:site=>"http://blabla.bla",
|
14
|
-
:proxy=>"http://user:password@proxy.bla:8080",
|
15
|
-
:request_token_path=>"/oauth/example/request_token.php",
|
16
|
-
:access_token_path=>"/oauth/example/access_token.php",
|
17
|
-
:authorize_path=>"/oauth/example/authorize.php",
|
18
|
-
:scheme=>:header,
|
19
|
-
:http_method=>:get
|
20
|
-
})
|
21
|
-
@token = OAuth::ConsumerToken.new(@consumer,'token_411a7f', '3196ffd991c8ebdb')
|
22
|
-
@request_uri = URI.parse('http://example.com/test?key=value')
|
23
|
-
@request_parameters = { 'key' => 'value' }
|
24
|
-
@nonce = 225579211881198842005988698334675835446
|
25
|
-
@timestamp = "1199645624"
|
26
|
-
@consumer.http=Net::HTTP.new(@request_uri.host, @request_uri.port)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_initializer
|
30
|
-
assert_equal "consumer_key_86cad9",@consumer.key
|
31
|
-
assert_equal "5888bf0345e5d237",@consumer.secret
|
32
|
-
assert_equal "http://blabla.bla",@consumer.site
|
33
|
-
assert_equal "http://user:password@proxy.bla:8080",@consumer.proxy
|
34
|
-
assert_equal "/oauth/example/request_token.php",@consumer.request_token_path
|
35
|
-
assert_equal "/oauth/example/access_token.php",@consumer.access_token_path
|
36
|
-
assert_equal "http://blabla.bla/oauth/example/request_token.php",@consumer.request_token_url
|
37
|
-
assert_equal "http://blabla.bla/oauth/example/access_token.php",@consumer.access_token_url
|
38
|
-
assert_equal "http://blabla.bla/oauth/example/authorize.php",@consumer.authorize_url
|
39
|
-
assert_equal :header,@consumer.scheme
|
40
|
-
assert_equal :get,@consumer.http_method
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_defaults
|
44
|
-
@consumer=OAuth::Consumer.new(
|
45
|
-
"key",
|
46
|
-
"secret",
|
47
|
-
{
|
48
|
-
:site=>"http://twitter.com"
|
49
|
-
})
|
50
|
-
assert_equal "key",@consumer.key
|
51
|
-
assert_equal "secret",@consumer.secret
|
52
|
-
assert_equal "http://twitter.com",@consumer.site
|
53
|
-
assert_nil @consumer.proxy
|
54
|
-
assert_equal "/oauth/request_token",@consumer.request_token_path
|
55
|
-
assert_equal "/oauth/access_token",@consumer.access_token_path
|
56
|
-
assert_equal "http://twitter.com/oauth/request_token",@consumer.request_token_url
|
57
|
-
assert_equal "http://twitter.com/oauth/access_token",@consumer.access_token_url
|
58
|
-
assert_equal "http://twitter.com/oauth/authorize",@consumer.authorize_url
|
59
|
-
assert_equal :header,@consumer.scheme
|
60
|
-
assert_equal :post,@consumer.http_method
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_site_without_path
|
64
|
-
@consumer=OAuth::Consumer.new(
|
65
|
-
"key",
|
66
|
-
"secret",
|
67
|
-
{
|
68
|
-
:site=>"http://twitter.com"
|
69
|
-
})
|
70
|
-
request = stub(:oauth! => nil)
|
71
|
-
http = stub(:request => stub(:to_hash => {}))
|
72
|
-
Net::HTTP::Get.expects(:new).with('/people', {}).returns(request)
|
73
|
-
@consumer.expects(:create_http).returns(http)
|
74
|
-
@consumer.request(:get, '/people', nil, {})
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_site_with_path
|
78
|
-
@consumer=OAuth::Consumer.new(
|
79
|
-
"key",
|
80
|
-
"secret",
|
81
|
-
{
|
82
|
-
:site=>"http://identi.ca/api"
|
83
|
-
})
|
84
|
-
request = stub(:oauth! => nil)
|
85
|
-
http = stub(:request => stub(:to_hash => {}))
|
86
|
-
Net::HTTP::Get.expects(:new).with('/api/people', {}).returns(request)
|
87
|
-
@consumer.expects(:create_http).returns(http)
|
88
|
-
@consumer.request(:get, '/people', nil, {})
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_post_of_nested_params_maintains_nesting
|
92
|
-
@consumer=OAuth::Consumer.new(
|
93
|
-
"key",
|
94
|
-
"secret",
|
95
|
-
{
|
96
|
-
:site=>"http://twitter.com"
|
97
|
-
})
|
98
|
-
request = @consumer.create_signed_request(
|
99
|
-
:post,
|
100
|
-
'/people',
|
101
|
-
nil,
|
102
|
-
{},
|
103
|
-
{
|
104
|
-
:key => {
|
105
|
-
:subkey => 'value'
|
106
|
-
}
|
107
|
-
})
|
108
|
-
assert_equal 'key%5Bsubkey%5D=value', request.body
|
109
|
-
assert_equal request.content_type, 'application/x-www-form-urlencoded'
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_override_paths
|
113
|
-
@consumer=OAuth::Consumer.new(
|
114
|
-
"key",
|
115
|
-
"secret",
|
116
|
-
{
|
117
|
-
:site=>"http://twitter.com",
|
118
|
-
:request_token_url=>"http://oauth.twitter.com/request_token",
|
119
|
-
:access_token_url=>"http://oauth.twitter.com/access_token",
|
120
|
-
:authorize_url=>"http://site.twitter.com/authorize"
|
121
|
-
})
|
122
|
-
assert_equal "key",@consumer.key
|
123
|
-
assert_equal "secret",@consumer.secret
|
124
|
-
assert_equal "http://twitter.com",@consumer.site
|
125
|
-
assert_equal "/oauth/request_token",@consumer.request_token_path
|
126
|
-
assert_equal "/oauth/access_token",@consumer.access_token_path
|
127
|
-
assert_equal "http://oauth.twitter.com/request_token",@consumer.request_token_url
|
128
|
-
assert_equal "http://oauth.twitter.com/access_token",@consumer.access_token_url
|
129
|
-
assert_equal "http://site.twitter.com/authorize",@consumer.authorize_url
|
130
|
-
assert_equal :header,@consumer.scheme
|
131
|
-
assert_equal :post,@consumer.http_method
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_token_request_identifies_itself_as_a_token_request
|
135
|
-
request_options = {}
|
136
|
-
@consumer.stubs(:request).returns(create_stub_http_response)
|
137
|
-
@consumer.token_request(:post, '/', 'token', request_options) {}
|
138
|
-
assert_equal true, request_options[:token_request]
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_that_token_response_should_be_uri_parameter_format_as_default
|
142
|
-
@consumer.expects(:request).returns(create_stub_http_response("oauth_token=token&oauth_token_secret=secret"))
|
143
|
-
|
144
|
-
hash = @consumer.token_request(:get, "")
|
145
|
-
|
146
|
-
assert_equal "token", hash[:oauth_token]
|
147
|
-
assert_equal "secret", hash[:oauth_token_secret]
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_can_provided_a_block_to_interpret_token_response
|
151
|
-
@consumer.expects(:request).returns(create_stub_http_response)
|
152
|
-
|
153
|
-
hash = @consumer.token_request(:get, '') {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
|
154
|
-
|
155
|
-
assert_equal 'token', hash[:oauth_token]
|
156
|
-
assert_equal 'secret', hash[:oauth_token_secret]
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_token_request_follows_redirect
|
160
|
-
redirect_url = @request_uri.clone
|
161
|
-
redirect_url.path = "/oauth/example/request_token_redirect.php"
|
162
|
-
stub_request(:get, /.*#{@request_uri.path}/).to_return(:status => 301, :headers => {'Location' => redirect_url.to_s})
|
163
|
-
stub_request(:get, /.*#{redirect_url.path}/).to_return(:body => "oauth_token=token&oauth_token_secret=secret")
|
164
|
-
|
165
|
-
hash = @consumer.token_request(:get, @request_uri.path) {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
|
166
|
-
|
167
|
-
assert_equal 'token', hash[:oauth_token]
|
168
|
-
assert_equal 'secret', hash[:oauth_token_secret]
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_that_can_provide_a_block_to_interpret_a_request_token_response
|
172
|
-
@consumer.expects(:request).returns(create_stub_http_response)
|
173
|
-
|
174
|
-
token = @consumer.get_request_token {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
|
175
|
-
|
176
|
-
assert_equal 'token', token.token
|
177
|
-
assert_equal 'secret', token.secret
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_that_block_is_not_mandatory_for_getting_an_access_token
|
181
|
-
stub_token = mock
|
182
|
-
@consumer.expects(:request).returns(create_stub_http_response("oauth_token=token&oauth_token_secret=secret"))
|
183
|
-
|
184
|
-
token = @consumer.get_access_token(stub_token)
|
185
|
-
|
186
|
-
assert_equal 'token', token.token
|
187
|
-
assert_equal 'secret', token.secret
|
188
|
-
end
|
189
|
-
|
190
|
-
def test_that_can_provide_a_block_to_interpret_an_access_token_response
|
191
|
-
stub_token = mock
|
192
|
-
@consumer.expects(:request).returns(create_stub_http_response)
|
193
|
-
|
194
|
-
token = @consumer.get_access_token(stub_token) {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
|
195
|
-
|
196
|
-
assert_equal 'token', token.token
|
197
|
-
assert_equal 'secret', token.secret
|
198
|
-
end
|
199
|
-
|
200
|
-
def test_that_not_setting_ignore_callback_will_include_oauth_callback_in_request_options
|
201
|
-
request_options = {}
|
202
|
-
@consumer.stubs(:request).returns(create_stub_http_response)
|
203
|
-
|
204
|
-
@consumer.get_request_token(request_options) {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
|
205
|
-
|
206
|
-
assert_equal 'oob', request_options[:oauth_callback]
|
207
|
-
end
|
208
|
-
|
209
|
-
def test_that_setting_ignore_callback_will_exclude_oauth_callback_in_request_options
|
210
|
-
request_options = { :exclude_callback=> true }
|
211
|
-
@consumer.stubs(:request).returns(create_stub_http_response)
|
212
|
-
|
213
|
-
@consumer.get_request_token(request_options) {{ :oauth_token => 'token', :oauth_token_secret => 'secret' }}
|
214
|
-
|
215
|
-
assert_nil request_options[:oauth_callback]
|
216
|
-
end
|
217
|
-
|
218
|
-
private
|
219
|
-
|
220
|
-
def create_stub_http_response expected_body=nil
|
221
|
-
stub_http_response = stub
|
222
|
-
stub_http_response.stubs(:code).returns(200)
|
223
|
-
stub_http_response.stubs(:body).tap {|expectation| expectation.returns(expected_body) unless expected_body.nil? }
|
224
|
-
return stub_http_response
|
225
|
-
end
|
226
|
-
end
|
@@ -1,77 +0,0 @@
|
|
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 < Minitest::Test
|
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
|