oauthenticator 1.3.5 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16ab24b09d173ed8caca336faa49d9cc263513b5a1b918f656985dff431caa61
4
- data.tar.gz: d3439a11045ed50fb9c72ccb85d137c72ea04b04189d58729b24ca365744937f
3
+ metadata.gz: 781f1dc15efaf29b18f10bd6d17658afaecb9569150d5bb8aa665a97e2970f1c
4
+ data.tar.gz: c233a50d0369b7f08ba951ced36fc71c1ab139ed8fb5ff8989f78f5d8882f696
5
5
  SHA512:
6
- metadata.gz: bd14158bfbc8c6ff4f998226ae110d5d3c9d251fb011968dd5ddc7d3fd1d131450e5dce683e1590728218527ea2a9f31e82b17f81b674eb4ea391a4d68d0bdb0
7
- data.tar.gz: 82aef9ae6b004bcd95b5cf6a96c198089195022b3a131ec1346a62a2c18d3db1b6b2eae54af4ba41e665ef57677dc72bed6a9f886615fdeb53e7351e0a697918
6
+ metadata.gz: 0f18da06cfbba676551ff8cdd0c534b77dde1a3c132645f473cfb1cfabd1adff9c1e75fbb964bad7b1c3614f1023252a6bc6dd0fbfb724695a7839e142f9a6b5
7
+ data.tar.gz: 04107cc48f5fd8f068393f81545c7007f050c9b3743d8716802f3339ced9d7cf989b119a9f87ed38796fc552f3dea8edbb5158e6b6b1cd21fda1ca87074ab41c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 1.4.1
2
+
3
+ - compatible with rack 3
4
+ - compatible with faraday 2
5
+
6
+ # 1.4.0
7
+
8
+ - support signature methods HMAC-SHA256, HMAC-SHA512
9
+
1
10
  # 1.3.5
2
11
 
3
12
  - relax faraday and rack gem dependency constraints
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 awesome storage
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 oauth_body_hash_is_required (this method defaults to false and may be omitted)
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
@@ -66,9 +66,10 @@ module OAuthenticator
66
66
  end
67
67
 
68
68
  # the signature methods which the application will accept. this MUST be a subset of the signature methods
69
- # defined in the OAuth 1.0 protocol: `%w(HMAC-SHA1 RSA-SHA1 PLAINTEXT)`. the default value for this is all
70
- # allowed signature methods, and may remain unimplemented if you wish to allow all defined signature
71
- # methods.
69
+ # defined in the OAuth 1.0 protocol plus OAuthenticator-defined extensions:
70
+ # `%w(HMAC-SHA1 RSA-SHA1 PLAINTEXT HMAC-SHA512 HMAC-SHA256)`.
71
+ # the default value for this is all allowed signature methods, and may remain unimplemented if you wish
72
+ # to allow all defined signature methods.
72
73
  #
73
74
  # @return [Array<String>]
74
75
  def allowed_signature_methods
@@ -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
- uri_parser.escape(value.to_s, /[^a-z0-9\-\.\_\~]/i)
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
- uri_parser.unescape(value.to_s)
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': {'attribute1': ['messageA', 'messageB'], 'attribute2': ['messageC']}}
12
+ # {'errors' => {'attribute1' => ['messageA', 'messageB'], 'attribute2' => ['messageC']}}
13
13
  class RackAuthenticator
14
14
  # options:
15
15
  #
@@ -33,6 +33,7 @@ end
33
33
 
34
34
  class Rack::Test::Session
35
35
  actual_process_request = instance_method(:process_request)
36
+ remove_method(:process_request)
36
37
  define_method(:process_request) do |uri, env, &block|
37
38
  oauth_attrs = Thread.current[:oauthenticator_rack_test_attributes]
38
39
  if oauth_attrs
@@ -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[signature_method] && !form_encoded? &&
284
+ BODY_HASH_METHODS.key?(signature_method) && !form_encoded? &&
285
285
  (@attributes.key?('hash_body?') ? @attributes['hash_body?'] : true)
286
286
  end
287
287
 
@@ -304,9 +304,33 @@ module OAuthenticator
304
304
  #
305
305
  # @return [String]
306
306
  def hmac_sha1_signature
307
+ hmac_digest_signature(OpenSSL::Digest::SHA1)
308
+ end
309
+
310
+ # signature, with method HMAC-SHA256. OAuthenticator extension, outside of spec. do not use.
311
+ # unless you want to.
312
+ #
313
+ # @return [String]
314
+ def hmac_sha256_signature
315
+ hmac_digest_signature(OpenSSL::Digest::SHA256)
316
+ end
317
+
318
+ # signature, with method HMAC-SHA512. OAuthenticator extension, outside of spec. do not use.
319
+ # unless you want to.
320
+ #
321
+ # @return [String]
322
+ def hmac_sha512_signature
323
+ hmac_digest_signature(OpenSSL::Digest::SHA512)
324
+ end
325
+
326
+ # signature with a HMAC digest
327
+ #
328
+ # @param digest_class [Class] the digest class
329
+ # @return [String]
330
+ def hmac_digest_signature(digest_class)
307
331
  # hmac secret is same as plaintext signature
308
332
  secret = plaintext_signature
309
- Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, secret, signature_base)).gsub(/\n/, '')
333
+ Base64.encode64(OpenSSL::HMAC.digest(digest_class.new, secret, signature_base)).gsub(/\n/, '')
310
334
  end
311
335
 
312
336
  # signature, with method plaintext. section 3.4.4
@@ -320,13 +344,39 @@ module OAuthenticator
320
344
  #
321
345
  # @return [String]
322
346
  def sha1_body_hash
323
- Base64.encode64(OpenSSL::Digest::SHA1.digest(read_body)).gsub(/\n/, '')
347
+ digest_body_hash(OpenSSL::Digest::SHA1)
348
+ end
349
+
350
+ # body hash, with a signature method which uses SHA256. OAuthenticator extension, outside of spec.
351
+ # do not use. unless you want to.
352
+ #
353
+ # @return [String]
354
+ def sha256_body_hash
355
+ digest_body_hash(OpenSSL::Digest::SHA256)
356
+ end
357
+
358
+ # body hash, with a signature method which uses SHA512. OAuthenticator extension, outside of spec.
359
+ # do not use. unless you want to.
360
+ #
361
+ # @return [String]
362
+ def sha512_body_hash
363
+ digest_body_hash(OpenSSL::Digest::SHA512)
364
+ end
365
+
366
+ # body hash with a given digest
367
+ #
368
+ # @param digest_class [Class] the digest class
369
+ # @return [String]
370
+ def digest_body_hash(digest_class)
371
+ Base64.encode64(digest_class.digest(read_body)).gsub(/\n/, '')
324
372
  end
325
373
 
326
374
  # map of oauth signature methods to their signature instance methods on this class
327
375
  SIGNATURE_METHODS = {
328
376
  'RSA-SHA1'.freeze => instance_method(:rsa_sha1_signature),
329
377
  'HMAC-SHA1'.freeze => instance_method(:hmac_sha1_signature),
378
+ 'HMAC-SHA256'.freeze => instance_method(:hmac_sha256_signature),
379
+ 'HMAC-SHA512'.freeze => instance_method(:hmac_sha512_signature),
330
380
  'PLAINTEXT'.freeze => instance_method(:plaintext_signature),
331
381
  }.freeze
332
382
 
@@ -335,6 +385,8 @@ module OAuthenticator
335
385
  BODY_HASH_METHODS = {
336
386
  'RSA-SHA1'.freeze => instance_method(:sha1_body_hash),
337
387
  'HMAC-SHA1'.freeze => instance_method(:sha1_body_hash),
388
+ 'HMAC-SHA256'.freeze => instance_method(:sha256_body_hash),
389
+ 'HMAC-SHA512'.freeze => instance_method(:sha512_body_hash),
338
390
  }.freeze
339
391
  end
340
392
  end
@@ -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 instance_variables.any? { |ivar| ivar.to_s == '@errors' }
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"]})
@@ -234,13 +234,13 @@ module OAuthenticator
234
234
  require 'oauthenticator/config_methods'
235
235
  include ConfigMethods
236
236
 
237
- private
238
-
239
237
  # hash of header params. keys should be a subset of OAUTH_ATTRIBUTE_KEYS.
240
238
  def oauth_header_params
241
239
  @oauth_header_params ||= OAuthenticator.parse_authorization(authorization)
242
240
  end
243
241
 
242
+ private
243
+
244
244
  # raise a nice error message for a method that needs to be implemented on a module of config methods
245
245
  def config_method_not_implemented
246
246
  caller_name = caller[0].match(%r(in `(.*?)'))[1]
@@ -1,5 +1,5 @@
1
1
  # OAuthenticator
2
2
  module OAuthenticator
3
3
  # OAuthenticator::VERSION
4
- VERSION = "1.3.5"
4
+ VERSION = "1.4.1"
5
5
  end
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.3.5
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: 2020-08-13 00:00:00.000000000 Z
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: '3.0'
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: '3.0'
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: '2.0'
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: '2.0'
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.0.6
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'
@@ -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-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
@@ -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)