mzsanford-oauth 0.3.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +91 -0
- data/License.txt +20 -0
- data/Manifest.txt +84 -0
- data/README.rdoc +71 -0
- data/Rakefile +36 -0
- data/TODO +31 -0
- data/bin/oauth +5 -0
- data/examples/yql.rb +44 -0
- data/lib/oauth.rb +4 -0
- data/lib/oauth/cli.rb +342 -0
- data/lib/oauth/client.rb +4 -0
- data/lib/oauth/client/action_controller_request.rb +54 -0
- data/lib/oauth/client/helper.rb +83 -0
- data/lib/oauth/client/net_http.rb +106 -0
- data/lib/oauth/consumer.rb +337 -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 +78 -0
- data/lib/oauth/oauth.rb +11 -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 +61 -0
- data/lib/oauth/request_proxy/base.rb +165 -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 +65 -0
- data/lib/oauth/request_proxy/rack_request.rb +40 -0
- data/lib/oauth/server.rb +66 -0
- data/lib/oauth/signature.rb +37 -0
- data/lib/oauth/signature/base.rb +91 -0
- data/lib/oauth/signature/hmac/base.rb +12 -0
- data/lib/oauth/signature/hmac/md5.rb +9 -0
- data/lib/oauth/signature/hmac/rmd160.rb +9 -0
- data/lib/oauth/signature/hmac/sha1.rb +9 -0
- data/lib/oauth/signature/hmac/sha2.rb +9 -0
- data/lib/oauth/signature/md5.rb +13 -0
- data/lib/oauth/signature/plaintext.rb +23 -0
- data/lib/oauth/signature/rsa/sha1.rb +45 -0
- data/lib/oauth/signature/sha1.rb +13 -0
- data/lib/oauth/token.rb +7 -0
- data/lib/oauth/tokens/access_token.rb +68 -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/lib/oauth/version.rb +3 -0
- data/oauth.gemspec +49 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -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/keys/rsa.cert +11 -0
- data/test/keys/rsa.pem +16 -0
- data/test/test_access_token.rb +28 -0
- data/test/test_action_controller_request_proxy.rb +127 -0
- data/test/test_consumer.rb +361 -0
- data/test/test_helper.rb +10 -0
- data/test/test_hmac_sha1.rb +21 -0
- data/test/test_net_http_client.rb +204 -0
- data/test/test_net_http_request_proxy.rb +73 -0
- data/test/test_rack_request_proxy.rb +40 -0
- data/test/test_request_token.rb +53 -0
- data/test/test_rsa_sha1.rb +59 -0
- data/test/test_server.rb +40 -0
- data/test/test_signature.rb +19 -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/website/index.html +87 -0
- data/website/index.txt +73 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +212 -0
data/test/test_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/oauth'
|
3
|
+
|
4
|
+
begin
|
5
|
+
# load redgreen unless running from within TextMate (in which case ANSI
|
6
|
+
# color codes mess with the output)
|
7
|
+
require 'redgreen' unless ENV['TM_CURRENT_LINE']
|
8
|
+
rescue LoadError
|
9
|
+
nil
|
10
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'oauth/signature/hmac/sha1'
|
3
|
+
|
4
|
+
class TestSignatureHmacSha1 < Test::Unit::TestCase
|
5
|
+
def test_that_hmac_sha1_implements_hmac_sha1
|
6
|
+
assert OAuth::Signature.available_methods.include?('hmac-sha1')
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_that_get_request_from_oauth_test_cases_produces_matching_signature
|
10
|
+
request = Net::HTTP::Get.new('/photos?file=vacation.jpg&size=original&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_token=nnch734d00sl2jdk&oauth_timestamp=1191242096&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA1')
|
11
|
+
|
12
|
+
consumer = OAuth::Consumer.new('dpf43f3p2l4k3l03', 'kd94hf93k423kf44')
|
13
|
+
token = OAuth::Token.new('nnch734d00sl2jdk', 'pfkkdhi9sl3r4s00')
|
14
|
+
|
15
|
+
signature = OAuth::Signature.sign(request, { :consumer => consumer,
|
16
|
+
:token => token,
|
17
|
+
:uri => 'http://photos.example.net/photos' } )
|
18
|
+
|
19
|
+
assert_equal 'tR3+Ty81lMeYAr/Fid0kMTYa/WM=', signature
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,204 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'oauth/client/net_http'
|
3
|
+
require 'oauth/version'
|
4
|
+
|
5
|
+
class NetHTTPClientTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@consumer = OAuth::Consumer.new('consumer_key_86cad9', '5888bf0345e5d237')
|
9
|
+
@token = OAuth::Token.new('token_411a7f', '3196ffd991c8ebdb')
|
10
|
+
@request_uri = URI.parse('http://example.com/test?key=value')
|
11
|
+
@request_parameters = { 'key' => 'value' }
|
12
|
+
@nonce = 225579211881198842005988698334675835446
|
13
|
+
@timestamp = "1199645624"
|
14
|
+
@http = Net::HTTP.new(@request_uri.host, @request_uri.port)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_that_using_auth_headers_on_get_requests_works
|
18
|
+
request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
|
19
|
+
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
20
|
+
|
21
|
+
assert_equal 'GET', request.method
|
22
|
+
assert_equal '/test?key=value', request.path
|
23
|
+
assert_equal "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"1oO2izFav1GP4kEH2EskwXkCRFg%3D\", oauth_version=\"1.0\"".split(', ').sort, request['authorization'].split(', ').sort
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_that_using_auth_headers_on_post_requests_works
|
27
|
+
request = Net::HTTP::Post.new(@request_uri.path)
|
28
|
+
request.set_form_data( @request_parameters )
|
29
|
+
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
30
|
+
|
31
|
+
assert_equal 'POST', request.method
|
32
|
+
assert_equal '/test', request.path
|
33
|
+
assert_equal 'key=value', request.body
|
34
|
+
assert_equal "OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"26g7wHTtNO6ZWJaLltcueppHYiI%3D\", oauth_version=\"1.0\"".split(', ').sort, request['authorization'].split(', ').sort
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_that_version_is_added_to_existing_user_agent
|
38
|
+
request = Net::HTTP::Post.new(@request_uri.path)
|
39
|
+
request['User-Agent'] = "MyApp"
|
40
|
+
request.set_form_data( @request_parameters )
|
41
|
+
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
42
|
+
|
43
|
+
assert_equal "MyApp (OAuth gem v#{OAuth::VERSION})", request['User-Agent']
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_that_version_is_set_when_no_user_agent
|
47
|
+
request = Net::HTTP::Post.new(@request_uri.path)
|
48
|
+
request.set_form_data( @request_parameters )
|
49
|
+
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
50
|
+
|
51
|
+
assert_equal "OAuth gem v#{OAuth::VERSION}", request['User-Agent']
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_that_using_post_params_works
|
55
|
+
request = Net::HTTP::Post.new(@request_uri.path)
|
56
|
+
request['User-Agent'] = "MyApp"
|
57
|
+
request.set_form_data( @request_parameters )
|
58
|
+
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
59
|
+
|
60
|
+
assert_equal "MyApp (OAuth gem v#{OAuth::VERSION})", request['User-Agent']
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_that_version_is_set_when_no_user_agent
|
64
|
+
request = Net::HTTP::Post.new(@request_uri.path)
|
65
|
+
request.set_form_data( @request_parameters )
|
66
|
+
request.oauth!(@http, @consumer, @token, {:nonce => @nonce, :timestamp => @timestamp})
|
67
|
+
|
68
|
+
assert_equal "OAuth gem v#{OAuth::VERSION}", request['User-Agent']
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_that_using_get_params_works
|
72
|
+
request = Net::HTTP::Get.new(@request_uri.path + "?" + request_parameters_to_s)
|
73
|
+
request.oauth!(@http, @consumer, @token, {:scheme => 'query_string', :nonce => @nonce, :timestamp => @timestamp})
|
74
|
+
|
75
|
+
assert_equal 'GET', request.method
|
76
|
+
uri = URI.parse(request.path)
|
77
|
+
assert_equal '/test', uri.path
|
78
|
+
assert_equal nil, uri.fragment
|
79
|
+
assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=1oO2izFav1GP4kEH2EskwXkCRFg%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join("&")
|
80
|
+
assert_equal nil, request['authorization']
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_that_using_post_params_works
|
84
|
+
request = Net::HTTP::Post.new(@request_uri.path)
|
85
|
+
request.set_form_data( @request_parameters )
|
86
|
+
request.oauth!(@http, @consumer, @token, {:scheme => 'body', :nonce => @nonce, :timestamp => @timestamp})
|
87
|
+
|
88
|
+
assert_equal 'POST', request.method
|
89
|
+
assert_equal '/test', request.path
|
90
|
+
assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=26g7wHTtNO6ZWJaLltcueppHYiI%3d&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", request.body.split("&").sort.join("&")
|
91
|
+
assert_equal nil, request['authorization']
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_that_using_post_with_uri_params_works
|
95
|
+
request = Net::HTTP::Post.new(@request_uri.path + "?" + request_parameters_to_s)
|
96
|
+
request.oauth!(@http, @consumer, @token, {:scheme => 'query_string', :nonce => @nonce, :timestamp => @timestamp})
|
97
|
+
|
98
|
+
assert_equal 'POST', request.method
|
99
|
+
uri = URI.parse(request.path)
|
100
|
+
assert_equal '/test', uri.path
|
101
|
+
assert_equal nil, uri.fragment
|
102
|
+
assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=26g7wHTtNO6ZWJaLltcueppHYiI%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join('&')
|
103
|
+
assert_equal nil, request.body
|
104
|
+
assert_equal nil, request['authorization']
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_that_using_post_with_uri_and_form_params_works
|
108
|
+
request = Net::HTTP::Post.new(@request_uri.path + "?" + request_parameters_to_s)
|
109
|
+
request.set_form_data( { 'key2' => 'value2' } )
|
110
|
+
request.oauth!(@http, @consumer, @token, {:scheme => :query_string, :nonce => @nonce, :timestamp => @timestamp})
|
111
|
+
|
112
|
+
assert_equal 'POST', request.method
|
113
|
+
uri = URI.parse(request.path)
|
114
|
+
assert_equal '/test', uri.path
|
115
|
+
assert_equal nil, uri.fragment
|
116
|
+
assert_equal "key=value&oauth_consumer_key=consumer_key_86cad9&oauth_nonce=225579211881198842005988698334675835446&oauth_signature=4kSU8Zd1blWo3W6qJH7eaRTMkg0%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1199645624&oauth_token=token_411a7f&oauth_version=1.0", uri.query.split("&").sort.join('&')
|
117
|
+
assert_equal "key2=value2", request.body
|
118
|
+
assert_equal nil, request['authorization']
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
def test_example_from_specs
|
123
|
+
consumer=OAuth::Consumer.new("dpf43f3p2l4k3l03","kd94hf93k423kf44")
|
124
|
+
token = OAuth::Token.new('nnch734d00sl2jdk', 'pfkkdhi9sl3r4s00')
|
125
|
+
request_uri = URI.parse('http://photos.example.net/photos?file=vacation.jpg&size=original')
|
126
|
+
nonce = 'kllo9940pd9333jh'
|
127
|
+
timestamp = "1191242096"
|
128
|
+
http = Net::HTTP.new(request_uri.host, request_uri.port)
|
129
|
+
|
130
|
+
request = Net::HTTP::Get.new(request_uri.path + "?" + request_uri.query)
|
131
|
+
signature_base_string=request.signature_base_string(http, consumer, token, {:nonce => nonce, :timestamp => timestamp})
|
132
|
+
assert_equal 'GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal',signature_base_string
|
133
|
+
|
134
|
+
# request = Net::HTTP::Get.new(request_uri.path + "?" + request_uri.query)
|
135
|
+
request.oauth!(http, consumer, token, {:nonce => nonce, :timestamp => timestamp,:realm=>"http://photos.example.net/"})
|
136
|
+
|
137
|
+
assert_equal 'GET', request.method
|
138
|
+
assert_equal 'OAuth realm="http://photos.example.net/", oauth_nonce="kllo9940pd9333jh", oauth_signature_method="HMAC-SHA1", oauth_token="nnch734d00sl2jdk", oauth_timestamp="1191242096", oauth_consumer_key="dpf43f3p2l4k3l03", oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D", oauth_version="1.0"'.split(', ').sort, request['authorization'].split(', ').sort
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_step_by_step_token_request
|
143
|
+
consumer=OAuth::Consumer.new(
|
144
|
+
"key",
|
145
|
+
"secret")
|
146
|
+
request_uri = URI.parse('http://term.ie/oauth/example/request_token.php')
|
147
|
+
nonce = rand(2**128).to_s
|
148
|
+
timestamp = Time.now.to_i.to_s
|
149
|
+
http = Net::HTTP.new(request_uri.host, request_uri.port)
|
150
|
+
|
151
|
+
request = Net::HTTP::Get.new(request_uri.path)
|
152
|
+
signature_base_string=request.signature_base_string(http, consumer, nil, {:scheme=>:query_string,:nonce => nonce, :timestamp => timestamp})
|
153
|
+
assert_equal "GET&http%3A%2F%2Fterm.ie%2Foauth%2Fexample%2Frequest_token.php&oauth_consumer_key%3Dkey%26oauth_nonce%3D#{nonce}%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D#{timestamp}%26oauth_version%3D1.0",signature_base_string
|
154
|
+
|
155
|
+
# request = Net::HTTP::Get.new(request_uri.path)
|
156
|
+
request.oauth!(http, consumer, nil, {:scheme=>:query_string,:nonce => nonce, :timestamp => timestamp})
|
157
|
+
assert_equal 'GET', request.method
|
158
|
+
assert_nil request.body
|
159
|
+
assert_nil request['authorization']
|
160
|
+
# assert_equal 'OAuth oauth_nonce="kllo9940pd9333jh", oauth_signature_method="HMAC-SHA1", oauth_token="", oauth_timestamp="'+timestamp+'", oauth_consumer_key="key", oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D", oauth_version="1.0"', request['authorization']
|
161
|
+
|
162
|
+
response=http.request(request)
|
163
|
+
assert_equal "200",response.code
|
164
|
+
# assert_equal request['authorization'],response.body
|
165
|
+
assert_equal "oauth_token=requestkey&oauth_token_secret=requestsecret",response.body
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_that_put_bodies_not_signed
|
169
|
+
request = Net::HTTP::Put.new(@request_uri.path)
|
170
|
+
request.body = "<?xml version=\"1.0\"?><foo><bar>baz</bar></foo>"
|
171
|
+
request["Content-Type"] = "application/xml"
|
172
|
+
signature_base_string=request.signature_base_string(@http, @consumer, nil, { :nonce => @nonce, :timestamp => @timestamp })
|
173
|
+
assert_equal "PUT&http%3A%2F%2Fexample.com%2Ftest&oauth_consumer_key%3Dconsumer_key_86cad9%26oauth_nonce%3D225579211881198842005988698334675835446%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1199645624%26oauth_version%3D1.0", signature_base_string
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_that_put_bodies_not_signed_even_if_form_urlencoded
|
177
|
+
request = Net::HTTP::Put.new(@request_uri.path)
|
178
|
+
request.set_form_data( { 'key2' => 'value2' } )
|
179
|
+
signature_base_string=request.signature_base_string(@http, @consumer, nil, { :nonce => @nonce, :timestamp => @timestamp })
|
180
|
+
assert_equal "PUT&http%3A%2F%2Fexample.com%2Ftest&oauth_consumer_key%3Dconsumer_key_86cad9%26oauth_nonce%3D225579211881198842005988698334675835446%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1199645624%26oauth_version%3D1.0", signature_base_string
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_that_post_bodies_signed_if_form_urlencoded
|
184
|
+
request = Net::HTTP::Post.new(@request_uri.path)
|
185
|
+
request.set_form_data( { 'key2' => 'value2' } )
|
186
|
+
signature_base_string=request.signature_base_string(@http, @consumer, nil, { :nonce => @nonce, :timestamp => @timestamp })
|
187
|
+
assert_equal "POST&http%3A%2F%2Fexample.com%2Ftest&key2%3Dvalue2%26oauth_consumer_key%3Dconsumer_key_86cad9%26oauth_nonce%3D225579211881198842005988698334675835446%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1199645624%26oauth_version%3D1.0", signature_base_string
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_that_post_bodies_not_signed_if_other_content_type
|
191
|
+
request = Net::HTTP::Post.new(@request_uri.path)
|
192
|
+
request.body = "<?xml version=\"1.0\"?><foo><bar>baz</bar></foo>"
|
193
|
+
request["Content-Type"] = "application/xml"
|
194
|
+
signature_base_string=request.signature_base_string(@http, @consumer, nil, { :nonce => @nonce, :timestamp => @timestamp })
|
195
|
+
assert_equal "POST&http%3A%2F%2Fexample.com%2Ftest&oauth_consumer_key%3Dconsumer_key_86cad9%26oauth_nonce%3D225579211881198842005988698334675835446%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1199645624%26oauth_version%3D1.0", signature_base_string
|
196
|
+
end
|
197
|
+
|
198
|
+
protected
|
199
|
+
|
200
|
+
def request_parameters_to_s
|
201
|
+
@request_parameters.map { |k,v| "#{k}=#{v}" }.join("&")
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'oauth/request_proxy/net_http'
|
3
|
+
|
4
|
+
class NetHTTPRequestProxyTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_that_proxy_simple_get_request_works
|
7
|
+
request = Net::HTTP::Get.new('/test?key=value')
|
8
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value'})
|
9
|
+
|
10
|
+
expected_parameters = {'key' => ['value']}
|
11
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
12
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
13
|
+
assert_equal 'GET', request_proxy.method
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_that_proxy_simple_post_request_works_with_arguments
|
17
|
+
request = Net::HTTP::Post.new('/test')
|
18
|
+
params = {'key' => 'value'}
|
19
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params})
|
20
|
+
|
21
|
+
expected_parameters = {'key' => ['value']}
|
22
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
23
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
24
|
+
assert_equal 'POST', request_proxy.method
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_that_proxy_simple_post_request_works_with_form_data
|
28
|
+
request = Net::HTTP::Post.new('/test')
|
29
|
+
params = {'key' => 'value'}
|
30
|
+
request.set_form_data(params)
|
31
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'})
|
32
|
+
|
33
|
+
expected_parameters = {'key' => ['value']}
|
34
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
35
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
36
|
+
assert_equal 'POST', request_proxy.method
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_that_proxy_simple_put_request_works_with_argugments
|
40
|
+
request = Net::HTTP::Put.new('/test')
|
41
|
+
params = {'key' => 'value'}
|
42
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params})
|
43
|
+
|
44
|
+
expected_parameters = {'key' => ['value']}
|
45
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
46
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
47
|
+
assert_equal 'PUT', request_proxy.method
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_that_proxy_simple_put_request_works_with_form_data
|
51
|
+
request = Net::HTTP::Put.new('/test')
|
52
|
+
params = {'key' => 'value'}
|
53
|
+
request.set_form_data(params)
|
54
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test'})
|
55
|
+
|
56
|
+
expected_parameters = {}
|
57
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
58
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
59
|
+
assert_equal 'PUT', request_proxy.method
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_that_proxy_post_request_works_with_mixed_parameter_sources
|
63
|
+
request = Net::HTTP::Post.new('/test?key=value')
|
64
|
+
request.set_form_data({'key2' => 'value2'})
|
65
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value', :parameters => {'key3' => 'value3'}})
|
66
|
+
|
67
|
+
expected_parameters = {'key' => ['value'], 'key2' => ['value2'], 'key3' => ['value3']}
|
68
|
+
assert_equal expected_parameters, request_proxy.parameters_for_signature
|
69
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
70
|
+
assert_equal 'POST', request_proxy.method
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'oauth/request_proxy/rack_request'
|
3
|
+
require 'rack/request'
|
4
|
+
require 'rack/mock'
|
5
|
+
|
6
|
+
class RackRequestProxyTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_that_proxy_simple_get_request_works
|
9
|
+
request = Rack::Request.new(Rack::MockRequest.env_for('http://example.com/test?key=value'))
|
10
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value'})
|
11
|
+
|
12
|
+
expected_parameters = {'key' => 'value'}
|
13
|
+
assert_equal expected_parameters, request_proxy.parameters
|
14
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
15
|
+
assert_equal 'GET', request_proxy.method
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_that_proxy_simple_post_request_works
|
19
|
+
request = Rack::Request.new(Rack::MockRequest.env_for('http://example.com/test', :method => 'POST'))
|
20
|
+
params = {'key' => 'value'}
|
21
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test', :parameters => params})
|
22
|
+
|
23
|
+
expected_parameters = {'key' => 'value'}
|
24
|
+
assert_equal expected_parameters, request_proxy.parameters
|
25
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
26
|
+
assert_equal 'POST', request_proxy.method
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_that_proxy_post_and_get_request_works
|
30
|
+
request = Rack::Request.new(Rack::MockRequest.env_for('http://example.com/test?key=value', :method => 'POST', :input => 'key2=value2'))
|
31
|
+
params = {'key2' => 'value2'}
|
32
|
+
request_proxy = OAuth::RequestProxy.proxy(request, {:uri => 'http://example.com/test?key=value', :parameters => params})
|
33
|
+
|
34
|
+
expected_parameters = {'key' => 'value', 'key2' => 'value2'}
|
35
|
+
assert_equal expected_parameters, request_proxy.parameters
|
36
|
+
assert_equal 'http://example.com/test', request_proxy.normalized_uri
|
37
|
+
assert_equal 'POST', request_proxy.method
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'oauth/token'
|
3
|
+
require 'oauth/consumer'
|
4
|
+
|
5
|
+
class StubbedToken < OAuth::RequestToken
|
6
|
+
define_method :build_authorize_url_promoted do |root_domain, params|
|
7
|
+
build_authorize_url root_domain, params
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class TestRequestToken < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
# setup a fake req. token. mocking Consumer would be more appropriate...
|
14
|
+
@request_token = OAuth::RequestToken.new(
|
15
|
+
OAuth::Consumer.new("key", "secret", {}),
|
16
|
+
"key",
|
17
|
+
"secret"
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_request_token_builds_authorize_url_connectly_with_additional_params
|
22
|
+
auth_url = @request_token.authorize_url({:oauth_callback => "github.com"})
|
23
|
+
assert_not_nil auth_url
|
24
|
+
assert_match(/oauth_token/, auth_url)
|
25
|
+
assert_match(/oauth_callback/, auth_url)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_request_token_builds_authorize_url_connectly_with_no_or_nil_params
|
29
|
+
# we should only have 1 key in the url returned if we didn't pass anything.
|
30
|
+
# this is the only required param to authenticate the client.
|
31
|
+
auth_url = @request_token.authorize_url(nil)
|
32
|
+
assert_not_nil auth_url
|
33
|
+
assert_match(/\?oauth_token=/, auth_url)
|
34
|
+
|
35
|
+
auth_url = @request_token.authorize_url
|
36
|
+
assert_not_nil auth_url
|
37
|
+
assert_match(/\?oauth_token=/, auth_url)
|
38
|
+
end
|
39
|
+
|
40
|
+
#TODO: mock out the Consumer to test the Consumer/AccessToken interaction.
|
41
|
+
def test_get_access_token
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_build_authorize_url
|
45
|
+
@stubbed_token = StubbedToken.new(nil, nil, nil)
|
46
|
+
assert_respond_to @stubbed_token, :build_authorize_url_promoted
|
47
|
+
url = @stubbed_token.build_authorize_url_promoted(
|
48
|
+
"http://github.com/oauth/authorize",
|
49
|
+
{:foo => "bar bar"})
|
50
|
+
assert url
|
51
|
+
assert_equal "http://github.com/oauth/authorize?foo=bar+bar", url
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'oauth/consumer'
|
3
|
+
require 'oauth/signature/rsa/sha1'
|
4
|
+
|
5
|
+
class TestSignatureRsaSha1 < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@request = Net::HTTP::Get.new('/photos?file=vacaction.jpg&size=original&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_timestamp=1196666512&oauth_nonce=13917289812797014437&oauth_signature_method=RSA-SHA1')
|
9
|
+
|
10
|
+
@consumer = OAuth::Consumer.new('dpf43f3p2l4k3l03', OpenSSL::PKey::RSA.new(IO.read(File.dirname(__FILE__) + "/keys/rsa.pem")))
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_that_rsa_sha1_implements_rsa_sha1
|
15
|
+
assert OAuth::Signature.available_methods.include?('rsa-sha1')
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_that_get_request_from_oauth_test_cases_produces_matching_signature_base_string
|
19
|
+
sbs = OAuth::Signature.signature_base_string(@request, { :consumer => @consumer,
|
20
|
+
:uri => 'http://photos.example.net/photos' } )
|
21
|
+
|
22
|
+
assert_equal 'GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacaction.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3D13917289812797014437%26oauth_signature_method%3DRSA-SHA1%26oauth_timestamp%3D1196666512%26oauth_version%3D1.0%26size%3Doriginal', sbs
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_that_get_request_from_oauth_test_cases_produces_matching_signature
|
26
|
+
signature = OAuth::Signature.sign(@request, { :consumer => @consumer,
|
27
|
+
:uri => 'http://photos.example.net/photos' } )
|
28
|
+
|
29
|
+
assert_equal 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=', signature
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_that_get_request_from_oauth_test_cases_produces_matching_signature_using_private_key_file
|
34
|
+
@consumer = OAuth::Consumer.new('dpf43f3p2l4k3l03',nil)
|
35
|
+
|
36
|
+
signature = OAuth::Signature.sign(@request, { :consumer => @consumer,
|
37
|
+
:private_key_file=>File.dirname(__FILE__) + "/keys/rsa.pem",
|
38
|
+
:uri => 'http://photos.example.net/photos' } )
|
39
|
+
|
40
|
+
assert_equal 'jvTp/wX1TYtByB1m+Pbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2/9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW//e+RinhejgCuzoH26dyF8iY2ZZ/5D1ilgeijhV/vBka5twt399mXwaYdCwFYE=', signature
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_that_get_request_from_oauth_test_cases_verifies_signature
|
44
|
+
@request = Net::HTTP::Get.new('/photos?oauth_signature_method=RSA-SHA1&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_timestamp=1196666512&oauth_nonce=13917289812797014437&file=vacaction.jpg&size=original&oauth_signature=jvTp%2FwX1TYtByB1m%2BPbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2%2F9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW%2F%2Fe%2BRinhejgCuzoH26dyF8iY2ZZ%2F5D1ilgeijhV%2FvBka5twt399mXwaYdCwFYE%3D')
|
45
|
+
@consumer = OAuth::Consumer.new('dpf43f3p2l4k3l03',OpenSSL::X509::Certificate.new(IO.read(File.dirname(__FILE__) + "/keys/rsa.cert")))
|
46
|
+
|
47
|
+
assert OAuth::Signature.verify(@request, { :consumer => @consumer,
|
48
|
+
:uri => 'http://photos.example.net/photos' } )
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_that_get_request_from_oauth_test_cases_verifies_signature_with_pem
|
53
|
+
@request = Net::HTTP::Get.new('/photos?oauth_signature_method=RSA-SHA1&oauth_version=1.0&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_timestamp=1196666512&oauth_nonce=13917289812797014437&file=vacaction.jpg&size=original&oauth_signature=jvTp%2FwX1TYtByB1m%2BPbyo0lnCOLIsyGCH7wke8AUs3BpnwZJtAuEJkvQL2%2F9n4s5wUmUl4aCI4BwpraNx4RtEXMe5qg5T1LVTGliMRpKasKsW%2F%2Fe%2BRinhejgCuzoH26dyF8iY2ZZ%2F5D1ilgeijhV%2FvBka5twt399mXwaYdCwFYE%3D')
|
54
|
+
assert OAuth::Signature.verify(@request, { :consumer => @consumer,
|
55
|
+
:uri => 'http://photos.example.net/photos' } )
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|