oauthenticator 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +2 -2
- data/lib/oauthenticator/parse_authorization.rb +5 -9
- data/lib/oauthenticator/rack_authenticator.rb +1 -1
- data/lib/oauthenticator/signable_request.rb +2 -2
- data/lib/oauthenticator/signed_request.rb +1 -1
- data/lib/oauthenticator/version.rb +1 -1
- metadata +11 -144
- data/.simplecov +0 -1
- data/Rakefile.rb +0 -14
- data/test/config_methods_test.rb +0 -44
- data/test/faraday_signer_test.rb +0 -82
- data/test/helper.rb +0 -30
- data/test/parse_authorization_test.rb +0 -86
- data/test/rack_authenticator_test.rb +0 -615
- data/test/rack_test_signer_test.rb +0 -61
- data/test/signable_request_test.rb +0 -676
- data/test/signed_request_test.rb +0 -12
- data/test/test_config_methods.rb +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 781f1dc15efaf29b18f10bd6d17658afaecb9569150d5bb8aa665a97e2970f1c
|
4
|
+
data.tar.gz: c233a50d0369b7f08ba951ced36fc71c1ab139ed8fb5ff8989f78f5d8882f696
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f18da06cfbba676551ff8cdd0c534b77dde1a3c132645f473cfb1cfabd1adff9c1e75fbb964bad7b1c3614f1023252a6bc6dd0fbfb724695a7839e142f9a6b5
|
7
|
+
data.tar.gz: 04107cc48f5fd8f068393f81545c7007f050c9b3743d8716802f3339ced9d7cf989b119a9f87ed38796fc552f3dea8edbb5158e6b6b1cd21fda1ca87074ab41c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -142,7 +142,7 @@ module AwesomeOAuthConfig
|
|
142
142
|
%w(HMAC-SHA1 RSA-SHA1)
|
143
143
|
end
|
144
144
|
|
145
|
-
# consumer secret, looked up by consumer key from
|
145
|
+
# consumer secret, looked up by consumer key from ActiveRecord storage
|
146
146
|
def consumer_secret
|
147
147
|
OAuthConsumer.where(:key => consumer_key).first.try(:secret)
|
148
148
|
end
|
@@ -159,7 +159,7 @@ module AwesomeOAuthConfig
|
|
159
159
|
# OAuthToken.where(:token => token, :consumer_key => consumer_key).any?
|
160
160
|
end
|
161
161
|
|
162
|
-
# whether
|
162
|
+
# whether oauth_body_hash is required (this method defaults to false and may be omitted)
|
163
163
|
def body_hash_required?
|
164
164
|
false
|
165
165
|
end
|
@@ -57,25 +57,21 @@ module OAuthenticator
|
|
57
57
|
return attributes.map { |k,v| {k => v.first} }.inject({}, &:update)
|
58
58
|
end
|
59
59
|
|
60
|
+
# @private
|
61
|
+
URI_PARSER = URI.const_defined?(:DEFAULT_PARSER) ? URI::DEFAULT_PARSER : URI
|
62
|
+
|
60
63
|
# escape a value
|
61
64
|
# @param value [String] value
|
62
65
|
# @return [String] escaped value
|
63
66
|
def escape(value)
|
64
|
-
|
67
|
+
URI_PARSER.escape(value.to_s, /[^a-z0-9\-\.\_\~]/i)
|
65
68
|
end
|
66
69
|
|
67
70
|
# unescape a value
|
68
71
|
# @param value [String] escaped value
|
69
72
|
# @return [String] unescaped value
|
70
73
|
def unescape(value)
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
private
|
75
|
-
|
76
|
-
# @return [Object] a parser that responds to #escape and #unescape
|
77
|
-
def uri_parser
|
78
|
-
@uri_parser ||= URI.const_defined?(:Parser) ? URI::Parser.new : URI
|
74
|
+
URI_PARSER.unescape(value.to_s)
|
79
75
|
end
|
80
76
|
end
|
81
77
|
end
|
@@ -9,7 +9,7 @@ module OAuthenticator
|
|
9
9
|
# body a JSON object indicating errors encountered authenticating the request. The error object is
|
10
10
|
# structured like rails / ActiveResource:
|
11
11
|
#
|
12
|
-
# {'errors'
|
12
|
+
# {'errors' => {'attribute1' => ['messageA', 'messageB'], 'attribute2' => ['messageC']}}
|
13
13
|
class RackAuthenticator
|
14
14
|
# options:
|
15
15
|
#
|
@@ -201,7 +201,7 @@ module OAuthenticator
|
|
201
201
|
|
202
202
|
# section 3.4.1.3
|
203
203
|
#
|
204
|
-
# @return [Array<Array<String> (size 2)>]
|
204
|
+
# @return [Array<Array<String, nil> (size 2)>]
|
205
205
|
def normalized_request_params
|
206
206
|
query_params + protocol_params.reject { |k,v| %w(realm oauth_signature).include?(k) }.to_a + entity_params
|
207
207
|
end
|
@@ -281,7 +281,7 @@ module OAuthenticator
|
|
281
281
|
#
|
282
282
|
# @return [Boolean]
|
283
283
|
def hash_body?
|
284
|
-
BODY_HASH_METHODS
|
284
|
+
BODY_HASH_METHODS.key?(signature_method) && !form_encoded? &&
|
285
285
|
(@attributes.key?('hash_body?') ? @attributes['hash_body?'] : true)
|
286
286
|
end
|
287
287
|
|
@@ -93,7 +93,7 @@ module OAuthenticator
|
|
93
93
|
#
|
94
94
|
# @return [nil, Hash<String, Array<String>>] either nil or a hash of errors
|
95
95
|
def errors
|
96
|
-
return @errors if
|
96
|
+
return @errors if instance_variable_defined?('@errors')
|
97
97
|
@errors = catch(:errors) do
|
98
98
|
if authorization.nil?
|
99
99
|
throw(:errors, {'Authorization' => ["Authorization header is missing"]})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauthenticator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '1.4'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '4.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '1.4'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '4.0'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: json
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
version: '0.9'
|
54
54
|
- - "<"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: '
|
56
|
+
version: '3.0'
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -63,7 +63,7 @@ dependencies:
|
|
63
63
|
version: '0.9'
|
64
64
|
- - "<"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: '
|
66
|
+
version: '3.0'
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: addressable
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,118 +78,6 @@ dependencies:
|
|
78
78
|
- - "~>"
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '2.3'
|
81
|
-
- !ruby/object:Gem::Dependency
|
82
|
-
name: rake
|
83
|
-
requirement: !ruby/object:Gem::Requirement
|
84
|
-
requirements:
|
85
|
-
- - ">="
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version: '0'
|
88
|
-
type: :development
|
89
|
-
prerelease: false
|
90
|
-
version_requirements: !ruby/object:Gem::Requirement
|
91
|
-
requirements:
|
92
|
-
- - ">="
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version: '0'
|
95
|
-
- !ruby/object:Gem::Dependency
|
96
|
-
name: minitest
|
97
|
-
requirement: !ruby/object:Gem::Requirement
|
98
|
-
requirements:
|
99
|
-
- - ">="
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: '0'
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
requirements:
|
106
|
-
- - ">="
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
version: '0'
|
109
|
-
- !ruby/object:Gem::Dependency
|
110
|
-
name: minitest-reporters
|
111
|
-
requirement: !ruby/object:Gem::Requirement
|
112
|
-
requirements:
|
113
|
-
- - ">="
|
114
|
-
- !ruby/object:Gem::Version
|
115
|
-
version: '0'
|
116
|
-
type: :development
|
117
|
-
prerelease: false
|
118
|
-
version_requirements: !ruby/object:Gem::Requirement
|
119
|
-
requirements:
|
120
|
-
- - ">="
|
121
|
-
- !ruby/object:Gem::Version
|
122
|
-
version: '0'
|
123
|
-
- !ruby/object:Gem::Dependency
|
124
|
-
name: rack-test
|
125
|
-
requirement: !ruby/object:Gem::Requirement
|
126
|
-
requirements:
|
127
|
-
- - ">="
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
version: '0'
|
130
|
-
type: :development
|
131
|
-
prerelease: false
|
132
|
-
version_requirements: !ruby/object:Gem::Requirement
|
133
|
-
requirements:
|
134
|
-
- - ">="
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
version: '0'
|
137
|
-
- !ruby/object:Gem::Dependency
|
138
|
-
name: timecop
|
139
|
-
requirement: !ruby/object:Gem::Requirement
|
140
|
-
requirements:
|
141
|
-
- - ">="
|
142
|
-
- !ruby/object:Gem::Version
|
143
|
-
version: '0'
|
144
|
-
type: :development
|
145
|
-
prerelease: false
|
146
|
-
version_requirements: !ruby/object:Gem::Requirement
|
147
|
-
requirements:
|
148
|
-
- - ">="
|
149
|
-
- !ruby/object:Gem::Version
|
150
|
-
version: '0'
|
151
|
-
- !ruby/object:Gem::Dependency
|
152
|
-
name: simplecov
|
153
|
-
requirement: !ruby/object:Gem::Requirement
|
154
|
-
requirements:
|
155
|
-
- - ">="
|
156
|
-
- !ruby/object:Gem::Version
|
157
|
-
version: '0'
|
158
|
-
type: :development
|
159
|
-
prerelease: false
|
160
|
-
version_requirements: !ruby/object:Gem::Requirement
|
161
|
-
requirements:
|
162
|
-
- - ">="
|
163
|
-
- !ruby/object:Gem::Version
|
164
|
-
version: '0'
|
165
|
-
- !ruby/object:Gem::Dependency
|
166
|
-
name: api_hammer
|
167
|
-
requirement: !ruby/object:Gem::Requirement
|
168
|
-
requirements:
|
169
|
-
- - ">="
|
170
|
-
- !ruby/object:Gem::Version
|
171
|
-
version: '0'
|
172
|
-
type: :development
|
173
|
-
prerelease: false
|
174
|
-
version_requirements: !ruby/object:Gem::Requirement
|
175
|
-
requirements:
|
176
|
-
- - ">="
|
177
|
-
- !ruby/object:Gem::Version
|
178
|
-
version: '0'
|
179
|
-
- !ruby/object:Gem::Dependency
|
180
|
-
name: yard
|
181
|
-
requirement: !ruby/object:Gem::Requirement
|
182
|
-
requirements:
|
183
|
-
- - ">="
|
184
|
-
- !ruby/object:Gem::Version
|
185
|
-
version: '0'
|
186
|
-
type: :development
|
187
|
-
prerelease: false
|
188
|
-
version_requirements: !ruby/object:Gem::Requirement
|
189
|
-
requirements:
|
190
|
-
- - ">="
|
191
|
-
- !ruby/object:Gem::Version
|
192
|
-
version: '0'
|
193
81
|
description: OAuthenticator signs and authenticates OAuth 1.0 requests
|
194
82
|
email:
|
195
83
|
- ethan@unth
|
@@ -197,12 +85,10 @@ executables: []
|
|
197
85
|
extensions: []
|
198
86
|
extra_rdoc_files: []
|
199
87
|
files:
|
200
|
-
- ".simplecov"
|
201
88
|
- ".yardopts"
|
202
89
|
- CHANGELOG.md
|
203
90
|
- LICENSE.txt
|
204
91
|
- README.md
|
205
|
-
- Rakefile.rb
|
206
92
|
- lib/oauthenticator.rb
|
207
93
|
- lib/oauthenticator/config_methods.rb
|
208
94
|
- lib/oauthenticator/faraday_signer.rb
|
@@ -212,20 +98,11 @@ files:
|
|
212
98
|
- lib/oauthenticator/signable_request.rb
|
213
99
|
- lib/oauthenticator/signed_request.rb
|
214
100
|
- lib/oauthenticator/version.rb
|
215
|
-
- test/config_methods_test.rb
|
216
|
-
- test/faraday_signer_test.rb
|
217
|
-
- test/helper.rb
|
218
|
-
- test/parse_authorization_test.rb
|
219
|
-
- test/rack_authenticator_test.rb
|
220
|
-
- test/rack_test_signer_test.rb
|
221
|
-
- test/signable_request_test.rb
|
222
|
-
- test/signed_request_test.rb
|
223
|
-
- test/test_config_methods.rb
|
224
101
|
homepage: https://github.com/notEthan/oauthenticator
|
225
102
|
licenses:
|
226
103
|
- MIT
|
227
104
|
metadata: {}
|
228
|
-
post_install_message:
|
105
|
+
post_install_message:
|
229
106
|
rdoc_options: []
|
230
107
|
require_paths:
|
231
108
|
- lib
|
@@ -240,18 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
240
117
|
- !ruby/object:Gem::Version
|
241
118
|
version: '0'
|
242
119
|
requirements: []
|
243
|
-
rubygems_version: 3.
|
244
|
-
signing_key:
|
120
|
+
rubygems_version: 3.1.6
|
121
|
+
signing_key:
|
245
122
|
specification_version: 4
|
246
123
|
summary: OAuth 1.0 request signing and authentication
|
247
|
-
test_files:
|
248
|
-
- test/config_methods_test.rb
|
249
|
-
- test/faraday_signer_test.rb
|
250
|
-
- test/helper.rb
|
251
|
-
- test/parse_authorization_test.rb
|
252
|
-
- test/rack_authenticator_test.rb
|
253
|
-
- test/rack_test_signer_test.rb
|
254
|
-
- test/signable_request_test.rb
|
255
|
-
- test/signed_request_test.rb
|
256
|
-
- test/test_config_methods.rb
|
257
|
-
- ".simplecov"
|
124
|
+
test_files: []
|
data/.simplecov
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
SimpleCov.start
|
data/Rakefile.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'rake/testtask'
|
2
|
-
Rake::TestTask.new do |t|
|
3
|
-
t.name = 'test'
|
4
|
-
t.test_files = FileList['test/**/*_test.rb']
|
5
|
-
t.verbose = true
|
6
|
-
end
|
7
|
-
require 'wwtd/tasks'
|
8
|
-
task 'default' => 'wwtd'
|
9
|
-
|
10
|
-
require 'yard'
|
11
|
-
YARD::Rake::YardocTask.new do |t|
|
12
|
-
end
|
13
|
-
|
14
|
-
require 'api_hammer/tasks'
|
data/test/config_methods_test.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
proc { |p| $:.unshift(p) unless $:.any? { |lp| File.expand_path(lp) == p } }.call(File.expand_path('.', File.dirname(__FILE__)))
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
describe OAuthenticator::SignedRequest do
|
6
|
-
%w(timestamp_valid_period consumer_secret token_secret nonce_used? use_nonce! token_belongs_to_consumer?).each do |method_without_default|
|
7
|
-
it "complains when #{method_without_default} is not implemented" do
|
8
|
-
exc = assert_raises(NotImplementedError) do
|
9
|
-
OAuthenticator::SignedRequest.new({}).public_send(method_without_default)
|
10
|
-
end
|
11
|
-
assert_match(/included in a subclass of OAuthenticator::SignedRequest/, exc.message)
|
12
|
-
end
|
13
|
-
it "uses the method #{method_without_default} when implemented" do
|
14
|
-
called = false
|
15
|
-
mod = Module.new { define_method(method_without_default) { called = true } }
|
16
|
-
OAuthenticator::SignedRequest.including_config(mod).new({}).public_send(method_without_default)
|
17
|
-
assert called
|
18
|
-
end
|
19
|
-
end
|
20
|
-
it "complains when a method without a default is not implemented, using RackAuthenticator" do
|
21
|
-
exc = assert_raises(NotImplementedError) do
|
22
|
-
OAuthenticator::RackAuthenticator.new(proc {}, {:config_methods => Module.new}).call({'HTTP_AUTHORIZATION' => %q(OAuth oauth_timestamp="1")})
|
23
|
-
end
|
24
|
-
assert_match(/passed to OAuthenticator::RackAuthenticator using the option :config_methods./, exc.message)
|
25
|
-
end
|
26
|
-
it "complains RackAuthenticator is not given config methods" do
|
27
|
-
assert_raises(ArgumentError) do
|
28
|
-
OAuthenticator::RackAuthenticator.new(proc {})
|
29
|
-
end
|
30
|
-
end
|
31
|
-
it 'uses timestamp_valid_period if that is implemented but timestamp_valid_past or timestamp_valid_future is not' do
|
32
|
-
called = 0
|
33
|
-
mod = Module.new { define_method(:timestamp_valid_period) { called +=1 } }
|
34
|
-
OAuthenticator::SignedRequest.including_config(mod).new({}).public_send(:timestamp_valid_future)
|
35
|
-
OAuthenticator::SignedRequest.including_config(mod).new({}).public_send(:timestamp_valid_past)
|
36
|
-
assert_equal 2, called
|
37
|
-
end
|
38
|
-
it 'uses the default value for allowed signature methods' do
|
39
|
-
assert_equal %w(RSA-SHA1 HMAC-SHA256 HMAC-SHA512 HMAC-SHA1 PLAINTEXT).sort, OAuthenticator::SignedRequest.new({}).allowed_signature_methods.sort
|
40
|
-
end
|
41
|
-
it 'uses default value for body_hash_required?' do
|
42
|
-
assert_equal false, OAuthenticator::SignedRequest.new({}).body_hash_required?
|
43
|
-
end
|
44
|
-
end
|
data/test/faraday_signer_test.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
proc { |p| $:.unshift(p) unless $:.any? { |lp| File.expand_path(lp) == p } }.call(File.expand_path('.', File.dirname(__FILE__)))
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
# not going to test a ton here, since the Faraday middleware mostly just calls to SignableRequest which is
|
6
|
-
# rather well-tested
|
7
|
-
describe OAuthenticator::FaradaySigner do
|
8
|
-
def assert_response(expected_status, expected_body, faraday_response)
|
9
|
-
assert_equal expected_status.to_i, faraday_response.status.to_i, "Expected status to be #{expected_status.inspect}" +
|
10
|
-
"; got #{faraday_response.status.inspect}. body was: #{faraday_response.body}"
|
11
|
-
assert expected_body === faraday_response.body, "Expected match for #{expected_body}; got #{faraday_response.body}"
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'succeeds' do
|
15
|
-
signing_options = {
|
16
|
-
:signature_method => 'PLAINTEXT',
|
17
|
-
:consumer_key => consumer_key,
|
18
|
-
:consumer_secret => consumer_secret,
|
19
|
-
:token => token,
|
20
|
-
:token_secret => token_secret,
|
21
|
-
}
|
22
|
-
|
23
|
-
connection = Faraday.new(:url => 'http://example.com') do |faraday|
|
24
|
-
faraday.request :oauthenticator_signer, signing_options
|
25
|
-
faraday.adapter :rack, oapp
|
26
|
-
end
|
27
|
-
response = connection.get '/'
|
28
|
-
assert_response 200, '☺', response
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'succeeds with form-encoded with HMAC' do
|
32
|
-
signing_options = {
|
33
|
-
:signature_method => 'HMAC-SHA1',
|
34
|
-
:consumer_key => consumer_key,
|
35
|
-
:consumer_secret => consumer_secret,
|
36
|
-
:token => token,
|
37
|
-
:token_secret => token_secret,
|
38
|
-
}
|
39
|
-
|
40
|
-
connection = Faraday.new(:url => 'http://example.com') do |faraday|
|
41
|
-
faraday.request :url_encoded
|
42
|
-
faraday.request :oauthenticator_signer, signing_options
|
43
|
-
faraday.adapter :rack, oapp
|
44
|
-
end
|
45
|
-
response = connection.put('/', :foo => {:bar => :baz})
|
46
|
-
assert_response 200, '☺', response
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'succeeds with charset' do
|
50
|
-
signing_options = {
|
51
|
-
:signature_method => 'HMAC-SHA1',
|
52
|
-
:consumer_key => consumer_key,
|
53
|
-
:consumer_secret => consumer_secret,
|
54
|
-
:token => token,
|
55
|
-
:token_secret => token_secret,
|
56
|
-
}
|
57
|
-
|
58
|
-
connection = Faraday.new(:url => 'http://example.com', :headers => {'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'}) do |faraday|
|
59
|
-
faraday.request :oauthenticator_signer, signing_options
|
60
|
-
faraday.adapter :rack, oapp
|
61
|
-
end
|
62
|
-
response = connection.post('/', 'a=b')
|
63
|
-
assert_response 200, '☺', response
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'is unauthorized' do
|
67
|
-
signing_options = {
|
68
|
-
:signature_method => 'PLAINTEXT',
|
69
|
-
:consumer_key => consumer_key,
|
70
|
-
:consumer_secret => 'nope',
|
71
|
-
:token => token,
|
72
|
-
:token_secret => 'definitelynot',
|
73
|
-
}
|
74
|
-
|
75
|
-
connection = Faraday.new(:url => 'http://example.com') do |faraday|
|
76
|
-
faraday.request :oauthenticator_signer, signing_options
|
77
|
-
faraday.adapter :rack, oapp
|
78
|
-
end
|
79
|
-
response = connection.get '/'
|
80
|
-
assert_response 401, /Authorization oauth_signature.*is invalid/m, response
|
81
|
-
end
|
82
|
-
end
|
data/test/helper.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
proc { |p| $:.unshift(p) unless $:.any? { |lp| File.expand_path(lp) == p } }.call(File.expand_path('../lib', File.dirname(__FILE__)))
|
2
|
-
|
3
|
-
require 'simplecov'
|
4
|
-
|
5
|
-
require 'byebug'
|
6
|
-
|
7
|
-
# NO EXPECTATIONS
|
8
|
-
ENV["MT_NO_EXPECTATIONS"] = ''
|
9
|
-
|
10
|
-
require 'minitest/autorun'
|
11
|
-
require 'minitest/reporters'
|
12
|
-
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
13
|
-
|
14
|
-
require 'rack/test'
|
15
|
-
require 'timecop'
|
16
|
-
|
17
|
-
require 'oauthenticator'
|
18
|
-
|
19
|
-
require 'test_config_methods'
|
20
|
-
|
21
|
-
class OAuthenticatorConfigSpec < Minitest::Spec
|
22
|
-
after do
|
23
|
-
Timecop.return
|
24
|
-
end
|
25
|
-
|
26
|
-
include TestHelperMethods
|
27
|
-
end
|
28
|
-
|
29
|
-
# register this to be the base class for specs instead of Minitest::Spec
|
30
|
-
Minitest::Spec.register_spec_type(//, OAuthenticatorConfigSpec)
|
@@ -1,86 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
proc { |p| $:.unshift(p) unless $:.any? { |lp| File.expand_path(lp) == p } }.call(File.expand_path('.', File.dirname(__FILE__)))
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
describe 'OAuthenticator.parse_authorization' do
|
6
|
-
let :spec_authorization do
|
7
|
-
%q(OAuth realm="Example",
|
8
|
-
oauth_consumer_key="9djdj82h48djs9d2",
|
9
|
-
oauth_token="kkk9d7dh3k39sjv7",
|
10
|
-
oauth_signature_method="HMAC-SHA1",
|
11
|
-
oauth_timestamp="137131201",
|
12
|
-
oauth_nonce="7d8f3e4a",
|
13
|
-
oauth_signature="r6%2FTJjbCOr97%2F%2BUU0NsvSne7s5g%3D"
|
14
|
-
)
|
15
|
-
end
|
16
|
-
let :spec_authorization_hash do
|
17
|
-
{
|
18
|
-
'realm' => "Example",
|
19
|
-
'oauth_consumer_key' => "9djdj82h48djs9d2",
|
20
|
-
'oauth_token' => "kkk9d7dh3k39sjv7",
|
21
|
-
'oauth_signature_method' => "HMAC-SHA1",
|
22
|
-
'oauth_timestamp' => "137131201",
|
23
|
-
'oauth_nonce' => "7d8f3e4a",
|
24
|
-
'oauth_signature' => "r6/TJjbCOr97/+UU0NsvSne7s5g=",
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'parses the example in the spec' do
|
29
|
-
assert_equal(spec_authorization_hash, OAuthenticator.parse_authorization(spec_authorization))
|
30
|
-
end
|
31
|
-
it 'parses the authorization SignableRequest calculates' do
|
32
|
-
request = OAuthenticator::SignableRequest.new({
|
33
|
-
:request_method => 'POST',
|
34
|
-
:uri => 'http://example.com/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b',
|
35
|
-
:media_type => 'application/x-www-form-urlencoded',
|
36
|
-
:body => 'c2&a3=2+q',
|
37
|
-
:authorization => spec_authorization_hash,
|
38
|
-
:consumer_secret => 'j49sk3j29djd',
|
39
|
-
:token_secret => 'dh893hdasih9',
|
40
|
-
})
|
41
|
-
assert_equal(spec_authorization_hash, OAuthenticator.parse_authorization(request.authorization))
|
42
|
-
end
|
43
|
-
|
44
|
-
describe 'optional linear white space' do
|
45
|
-
{ :space => %q(OAuth a="b", c="d", e="f"),
|
46
|
-
:spaces => %q(OAuth a="b", c="d", e="f" ),
|
47
|
-
:tab => %q(OAuth a="b", c="d", e="f"),
|
48
|
-
:tabs => %q(OAuth a="b", c="d", e="f"),
|
49
|
-
:tabs_and_spaces => %q(OAuth a="b", c="d", e="f"),
|
50
|
-
:none => %q(OAuth a="b",c="d",e="f"),
|
51
|
-
}.map do |name, authorization|
|
52
|
-
it "parses with #{name}" do
|
53
|
-
assert_equal({'a' => 'b', 'c' => 'd', 'e' => 'f'}, OAuthenticator.parse_authorization(authorization))
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it "handles commas inside quoted values" do
|
59
|
-
# note that this is invalid according to the spec; commas should be %-encoded, but this is accepted in
|
60
|
-
# the interests of robustness and consistency (other characters are accepted when they should really be
|
61
|
-
# escaped).
|
62
|
-
header_with_commas = 'OAuth oauth_consumer_key="a,bcd", oauth_nonce="o,LKtec51GQy", oauth_signature="efgh%2Cmnop"'
|
63
|
-
assert_equal({'oauth_consumer_key' => "a,bcd", 'oauth_nonce' => "o,LKtec51GQy", 'oauth_signature' => "efgh,mnop"},
|
64
|
-
OAuthenticator.parse_authorization(header_with_commas))
|
65
|
-
end
|
66
|
-
|
67
|
-
it "raises ParseError on input without a comma between key/value pairs" do
|
68
|
-
assert_raises(OAuthenticator::ParseError) do
|
69
|
-
OAuthenticator.parse_authorization(%q(OAuth oauth_consumer_key="k" oauth_nonce="n"))
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
it "raises ParseError on malformed input" do
|
74
|
-
assert_raises(OAuthenticator::ParseError) { OAuthenticator.parse_authorization(%q(OAuth huh=/)) }
|
75
|
-
end
|
76
|
-
|
77
|
-
it "raises ParseError when the header does not start with 'OAuth '" do
|
78
|
-
assert_raises(OAuthenticator::ParseError) { OAuthenticator.parse_authorization(%q(FooAuth foo="baz")) }
|
79
|
-
end
|
80
|
-
|
81
|
-
it "raises DuplicatedParameter when the header contains duplicated parameters" do
|
82
|
-
assert_raises(OAuthenticator::DuplicatedParameters) do
|
83
|
-
OAuthenticator.parse_authorization(%q(OAuth oauth_nonce="a", oauth_nonce="b"))
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|