signet 0.11.0 → 0.14.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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +51 -15
  3. data/Gemfile +5 -4
  4. data/README.md +4 -6
  5. data/Rakefile +107 -37
  6. data/lib/signet.rb +17 -14
  7. data/lib/signet/errors.rb +4 -4
  8. data/lib/signet/oauth_1.rb +129 -154
  9. data/lib/signet/oauth_1/client.rb +309 -343
  10. data/lib/signet/oauth_1/credential.rb +40 -37
  11. data/lib/signet/oauth_1/server.rb +197 -203
  12. data/lib/signet/oauth_1/signature_methods/hmac_sha1.rb +11 -10
  13. data/lib/signet/oauth_1/signature_methods/plaintext.rb +8 -7
  14. data/lib/signet/oauth_1/signature_methods/rsa_sha1.rb +11 -11
  15. data/lib/signet/oauth_2.rb +41 -43
  16. data/lib/signet/oauth_2/client.rb +328 -313
  17. data/lib/signet/version.rb +2 -73
  18. data/signet.gemspec +37 -39
  19. data/spec/signet/oauth_1/client_spec.rb +313 -315
  20. data/spec/signet/oauth_1/credential_spec.rb +64 -56
  21. data/spec/signet/oauth_1/server_spec.rb +362 -362
  22. data/spec/signet/oauth_1/signature_methods/hmac_sha1_spec.rb +26 -26
  23. data/spec/signet/oauth_1/signature_methods/plaintext_spec.rb +28 -28
  24. data/spec/signet/oauth_1/signature_methods/rsa_sha1_spec.rb +34 -35
  25. data/spec/signet/oauth_1_spec.rb +553 -524
  26. data/spec/signet/oauth_2/client_spec.rb +652 -576
  27. data/spec/signet/oauth_2_spec.rb +88 -89
  28. data/spec/signet_spec.rb +41 -41
  29. data/spec/spec_helper.rb +7 -7
  30. data/spec/spec_helper_spec.rb +8 -8
  31. metadata +64 -52
  32. data/tasks/clobber.rake +0 -2
  33. data/tasks/gem.rake +0 -34
  34. data/tasks/git.rake +0 -40
  35. data/tasks/metrics.rake +0 -41
  36. data/tasks/spec.rake +0 -34
  37. data/tasks/wiki.rake +0 -38
  38. data/tasks/yard.rake +0 -21
@@ -12,77 +12,6 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- # Used to prevent the class/module from being loaded more than once
16
- unless defined? Signet::VERSION
17
- module Signet
18
- module VERSION
19
- MAJOR = 0
20
- MINOR = 11
21
- TINY = 0
22
- PRE = nil
23
-
24
- STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
25
-
26
- # On March 31, 2019, set supported version to 2.4 and recommended to 2.6.
27
- # Thereafter, follow the MRI support schedule: supported means non-EOL,
28
- # and recommended means in normal (rather than security) maintenance.
29
- # See https://www.ruby-lang.org/en/downloads/branches/
30
- ##
31
- # Minimum "supported" Ruby version (non-EOL)
32
- # @private
33
- #
34
- SUPPORTED_VERSION_THRESHOLD = '1.9'.freeze
35
- ##
36
- # Minimum "recommended" Ruby version (normal maintenance)
37
- # @private
38
- #
39
- RECOMMENDED_VERSION_THRESHOLD = '2.4'.freeze
40
- ##
41
- # Check Ruby version and emit a warning if it is old
42
- # @private
43
- #
44
- def self.warn_on_old_ruby_version
45
- return if ENV['GOOGLE_CLOUD_SUPPRESS_RUBY_WARNINGS']
46
- cur_version = Gem::Version.new RUBY_VERSION
47
- if cur_version < Gem::Version.new(SUPPORTED_VERSION_THRESHOLD)
48
- warn_unsupported_ruby cur_version, RECOMMENDED_VERSION_THRESHOLD
49
- elsif cur_version < Gem::Version.new(RECOMMENDED_VERSION_THRESHOLD)
50
- warn_nonrecommended_ruby cur_version, RECOMMENDED_VERSION_THRESHOLD
51
- end
52
- rescue ArgumentError
53
- 'Unable to determine current Ruby version.'
54
- end
55
-
56
- ##
57
- # Print a warning for an EOL version of Ruby
58
- # @private
59
- #
60
- def self.warn_unsupported_ruby cur_version, recommended_version
61
- "WARNING: You are running Ruby #{cur_version}, which has reached" \
62
- " end-of-life and is no longer supported by Ruby Core.\n" \
63
- 'Signet works best on supported versions of' \
64
- ' Ruby. It is strongly recommended that you upgrade to Ruby' \
65
- " #{recommended_version} or later. \n" \
66
- 'See https://www.ruby-lang.org/en/downloads/branches/ for more' \
67
- " info on the Ruby maintenance schedule.\n" \
68
- 'To suppress this message, set the' \
69
- ' GOOGLE_CLOUD_SUPPRESS_RUBY_WARNINGS environment variable.'
70
- end
71
-
72
- ##
73
- # Print a warning for a supported but nearing EOL version of Ruby
74
- # @private
75
- #
76
- def self.warn_nonrecommended_ruby cur_version, recommended_version
77
- "WARNING: You are running Ruby #{cur_version}, which is nearing" \
78
- " end-of-life.\n" \
79
- 'Signet works best on supported versions of' \
80
- " Ruby. Consider upgrading to Ruby #{recommended_version} or later.\n" \
81
- 'See https://www.ruby-lang.org/en/downloads/branches/ for more' \
82
- " info on the Ruby maintenance schedule.\n" \
83
- 'To suppress this message, set the' \
84
- ' GOOGLE_CLOUD_SUPPRESS_RUBY_WARNINGS environment variable.'
85
- end
86
- end
87
- end
15
+ module Signet
16
+ VERSION = "0.14.1".freeze
88
17
  end
@@ -1,46 +1,44 @@
1
- # -*- encoding: utf-8 -*-
2
- # stub: signet 0.5.1 ruby lib
3
- require File.join(File.dirname(__FILE__), 'lib/signet', 'version')
1
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
2
+ require "signet/version"
4
3
 
5
- Gem::Specification.new do |s|
6
- s.name = "signet"
7
- s.version = Signet::VERSION::STRING
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "signet"
6
+ gem.version = Signet::VERSION
8
7
 
9
- s.required_rubygems_version = ">= 1.3.5"
10
- s.require_paths = ["lib"]
11
- s.authors = ["Bob Aman", "Steven Bazyl"]
12
- s.license = "Apache-2.0"
13
- s.description = "Signet is an OAuth 1.0 / OAuth 2.0 implementation.\n"
14
- s.email = "sbazyl@google.com"
15
- s.extra_rdoc_files = ["README.md"]
16
- s.files = %w(signet.gemspec Rakefile LICENSE CHANGELOG.md README.md Gemfile)
17
- s.files += Dir.glob("lib/**/*.rb")
18
- s.files += Dir.glob("spec/**/*.{rb,opts}")
19
- s.files += Dir.glob("vendor/**/*.rb")
20
- s.files += Dir.glob("tasks/**/*")
21
- s.files += Dir.glob("website/**/*")
22
- s.homepage = "https://github.com/google/signet/"
23
- s.rdoc_options = ["--main", "README.md"]
24
- s.summary = "Signet is an OAuth 1.0 / OAuth 2.0 implementation."
25
- s.required_ruby_version = ">= 1.9.3"
8
+ gem.required_rubygems_version = ">= 1.3.5"
9
+ gem.require_paths = ["lib"]
10
+ gem.authors = ["Bob Aman", "Steven Bazyl"]
11
+ gem.license = "Apache-2.0"
12
+ gem.description = "Signet is an OAuth 1.0 / OAuth 2.0 implementation.\n"
13
+ gem.email = "sbazyl@google.com"
14
+ gem.extra_rdoc_files = ["README.md"]
15
+ gem.files = ["signet.gemspec", "Rakefile", "LICENSE", "CHANGELOG.md", "README.md", "Gemfile"]
16
+ gem.files += Dir.glob "lib/**/*.rb"
17
+ gem.files += Dir.glob "spec/**/*.{rb,opts}"
18
+ gem.files += Dir.glob "vendor/**/*.rb"
19
+ gem.files += Dir.glob "tasks/**/*"
20
+ gem.files += Dir.glob "website/**/*"
21
+ gem.homepage = "https://github.com/googleapis/signet"
22
+ gem.rdoc_options = ["--main", "README.md"]
23
+ gem.summary = "Signet is an OAuth 1.0 / OAuth 2.0 implementation."
24
+ gem.required_ruby_version = ">= 2.4.0"
26
25
 
27
- s.add_runtime_dependency 'addressable', '~> 2.3'
28
- s.add_runtime_dependency 'faraday', '~> 0.9'
29
- s.add_runtime_dependency 'multi_json', '~> 1.10'
30
- s.add_runtime_dependency 'jwt', '>= 1.5', '< 3.0'
26
+ gem.add_runtime_dependency "addressable", "~> 2.3"
27
+ gem.add_runtime_dependency "faraday", ">= 0.17.3", "< 2.0"
28
+ gem.add_runtime_dependency "jwt", ">= 1.5", "< 3.0"
29
+ gem.add_runtime_dependency "multi_json", "~> 1.10"
31
30
 
32
- s.add_development_dependency 'rake', '~> 12.0'
33
- s.add_development_dependency 'yard', '~> 0.9', '>= 0.9.12'
34
- s.add_development_dependency 'rspec', '~> 3.1'
35
- s.add_development_dependency 'launchy', '~> 2.4'
36
- s.add_development_dependency 'kramdown', '~> 1.5'
37
- s.add_development_dependency 'simplecov', '~> 0.9'
31
+ gem.add_development_dependency "google-style", "~> 0.3"
32
+ gem.add_development_dependency "kramdown", "~> 1.5"
33
+ gem.add_development_dependency "launchy", "~> 2.4"
34
+ gem.add_development_dependency "rake", "~> 12.0"
35
+ gem.add_development_dependency "rspec", "~> 3.1"
36
+ gem.add_development_dependency "simplecov", "~> 0.9"
37
+ gem.add_development_dependency "yard", "~> 0.9", ">= 0.9.12"
38
38
 
39
- s.post_install_message = Signet::VERSION::warn_on_old_ruby_version
40
-
41
- if s.respond_to?(:metadata)
42
- s.metadata['changelog_uri'] = 'https://github.com/google/signet/blob/master/CHANGELOG.md'
43
- s.metadata['source_code_uri'] = 'https://github.com/google/signet'
44
- s.metadata['bug_tracker_uri'] = 'https://github.com/google/signet/issues'
39
+ if gem.respond_to? :metadata
40
+ gem.metadata["changelog_uri"] = "https://github.com/googleapis/signet/blob/master/CHANGELOG.md"
41
+ gem.metadata["source_code_uri"] = "https://github.com/googleapis/signet"
42
+ gem.metadata["bug_tracker_uri"] = "https://github.com/googleapis/signet/issues"
45
43
  end
46
44
  end
@@ -11,100 +11,98 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
- require 'spec_helper'
15
- require 'multi_json'
16
- require 'signet/oauth_1/client'
17
- require 'addressable/uri'
18
- require 'stringio'
14
+ require "spec_helper"
15
+ require "multi_json"
16
+ require "signet/oauth_1/client"
17
+ require "addressable/uri"
18
+ require "stringio"
19
19
 
20
20
  conn = Faraday.default_connection
21
21
 
22
- def merge_body(chunked_body)
23
- if chunked_body == nil
24
- raise ArgumentError, "Expected chunked body, got nil."
25
- end
22
+ def merge_body chunked_body
23
+ raise ArgumentError, "Expected chunked body, got nil." if chunked_body == nil
26
24
  merged_body = StringIO.new
27
25
  chunked_body.each do |chunk|
28
- merged_body.write(chunk)
26
+ merged_body.write chunk
29
27
  end
30
- return merged_body.string
28
+ merged_body.string
31
29
  end
32
30
 
33
- describe Signet::OAuth1::Client, 'unconfigured' do
31
+ describe Signet::OAuth1::Client, "unconfigured" do
34
32
  before do
35
33
  @client = Signet::OAuth1::Client.new
36
34
  end
37
35
 
38
- it 'should have no temporary_credential_uri' do
36
+ it "should have no temporary_credential_uri" do
39
37
  expect(@client.temporary_credential_uri).to be_nil
40
38
  end
41
39
 
42
- it 'should allow the temporary_credential_uri to be set to a String' do
40
+ it "should allow the temporary_credential_uri to be set to a String" do
43
41
  @client.temporary_credential_uri = "http://example.com/"
44
42
  expect(@client.temporary_credential_uri.to_s).to eq "http://example.com/"
45
43
  end
46
44
 
47
- it 'should allow the temporary_credential_uri to be set to a URI' do
45
+ it "should allow the temporary_credential_uri to be set to a URI" do
48
46
  @client.temporary_credential_uri =
49
- Addressable::URI.parse("http://example.com/")
47
+ Addressable::URI.parse "http://example.com/"
50
48
  expect(@client.temporary_credential_uri.to_s).to eq "http://example.com/"
51
49
  end
52
50
 
53
- it 'should have no authorization_uri' do
51
+ it "should have no authorization_uri" do
54
52
  expect(@client.authorization_uri).to be_nil
55
53
  end
56
54
 
57
- it 'should allow the authorization_uri to be set to a String' do
58
- @client.authorization_uri = 'http://example.com/authorize'
55
+ it "should allow the authorization_uri to be set to a String" do
56
+ @client.authorization_uri = "http://example.com/authorize"
59
57
  expect(@client.authorization_uri.to_s).to include(
60
- 'http://example.com/authorize'
58
+ "http://example.com/authorize"
61
59
  )
62
60
  end
63
61
 
64
- it 'should allow the authorization_uri to be set to a Hash' do
62
+ it "should allow the authorization_uri to be set to a Hash" do
65
63
  @client.authorization_uri = {
66
- :scheme => 'http', :host => 'example.com', :path => '/authorize'
64
+ scheme: "http", host: "example.com", path: "/authorize"
67
65
  }
68
66
  expect(@client.authorization_uri.to_s).to include(
69
- 'http://example.com/authorize'
67
+ "http://example.com/authorize"
70
68
  )
71
69
  end
72
70
 
73
- it 'should allow the authorization_uri to be set to a URI' do
71
+ it "should allow the authorization_uri to be set to a URI" do
74
72
  @client.authorization_uri =
75
- Addressable::URI.parse('http://example.com/authorize')
73
+ Addressable::URI.parse "http://example.com/authorize"
76
74
  expect(@client.authorization_uri.to_s).to include(
77
- 'http://example.com/authorize'
75
+ "http://example.com/authorize"
78
76
  )
79
77
  end
80
78
 
81
- it 'should have no token_credential_uri' do
79
+ it "should have no token_credential_uri" do
82
80
  expect(@client.token_credential_uri).to be_nil
83
81
  end
84
82
 
85
- it 'should allow the token_credential_uri to be set to a String' do
83
+ it "should allow the token_credential_uri to be set to a String" do
86
84
  @client.token_credential_uri = "http://example.com/"
87
85
  expect(@client.token_credential_uri.to_s).to eq "http://example.com/"
88
86
  end
89
87
 
90
- it 'should allow the token_credential_uri to be set to a Hash' do
88
+ it "should allow the token_credential_uri to be set to a Hash" do
91
89
  @client.token_credential_uri = {
92
- :scheme => 'http', :host => 'example.com', :path => '/token'
90
+ scheme: "http", host: "example.com", path: "/token"
93
91
  }
94
- expect(@client.token_credential_uri.to_s).to eq 'http://example.com/token'
92
+ expect(@client.token_credential_uri.to_s).to eq "http://example.com/token"
95
93
  end
96
94
 
97
- it 'should allow the token_credential_uri to be set to a URI' do
95
+ it "should allow the token_credential_uri to be set to a URI" do
98
96
  @client.token_credential_uri =
99
- Addressable::URI.parse("http://example.com/")
97
+ Addressable::URI.parse "http://example.com/"
100
98
  expect(@client.token_credential_uri.to_s).to eq "http://example.com/"
101
99
  end
102
100
 
103
- it 'should have no client_credential' do
101
+ it "should have no client_credential" do
104
102
  expect(@client.client_credential).to be_nil
105
103
  end
106
104
 
107
- it 'should raise an error for partially set client credentials' do
105
+ it "should raise an error for partially set client credentials" do
108
106
  @client.client_credential_key = "12345"
109
107
  @client.client_credential_secret = nil
110
108
  expect(lambda do
@@ -112,7 +110,7 @@ describe Signet::OAuth1::Client, 'unconfigured' do
112
110
  end).to raise_error(ArgumentError)
113
111
  end
114
112
 
115
- it 'should raise an error for partially set client credentials' do
113
+ it "should raise an error for partially set client credentials" do
116
114
  @client.client_credential_key = nil
117
115
  @client.client_credential_secret = "54321"
118
116
  expect(lambda do
@@ -120,16 +118,16 @@ describe Signet::OAuth1::Client, 'unconfigured' do
120
118
  end).to raise_error(ArgumentError)
121
119
  end
122
120
 
123
- it 'should allow the client_credential to be set to a ' +
124
- 'Signet::OAuth1::Credential' do
121
+ it "should allow the client_credential to be set to a " \
122
+ "Signet::OAuth1::Credential" do
125
123
  @client.client_credential =
126
- Signet::OAuth1::Credential.new("12345", "54321")
124
+ Signet::OAuth1::Credential.new "12345", "54321"
127
125
  expect(@client.client_credential_key).to eq "12345"
128
126
  expect(@client.client_credential_secret).to eq "54321"
129
127
  expect(@client.client_credential).to eq Signet::OAuth1::Credential.new("12345", "54321")
130
128
  end
131
129
 
132
- it 'should allow the client_credential to be set to nil' do
130
+ it "should allow the client_credential to be set to nil" do
133
131
  @client.client_credential_key = "12345"
134
132
  @client.client_credential_secret = "54321"
135
133
  expect(@client.client_credential_key).to eq "12345"
@@ -140,95 +138,95 @@ describe Signet::OAuth1::Client, 'unconfigured' do
140
138
  expect(@client.client_credential_secret).to be_nil
141
139
  end
142
140
 
143
- it 'should not allow the client_credential to be set to a bogus value' do
141
+ it "should not allow the client_credential to be set to a bogus value" do
144
142
  expect(lambda do
145
143
  @client.client_credential = 42
146
144
  end).to raise_error(TypeError)
147
145
  end
148
146
 
149
- it 'should have no client_credential_key' do
147
+ it "should have no client_credential_key" do
150
148
  expect(@client.client_credential_key).to be_nil
151
149
  end
152
150
 
153
- it 'should allow the client_credential_key to be set to a String' do
151
+ it "should allow the client_credential_key to be set to a String" do
154
152
  @client.client_credential_key = "12345"
155
153
  expect(@client.client_credential_key).to eq "12345"
156
154
  end
157
155
 
158
- it 'should not allow the client_credential_key to be set to a non-String' do
156
+ it "should not allow the client_credential_key to be set to a non-String" do
159
157
  expect(lambda do
160
- @client.client_credential_key = 12345
158
+ @client.client_credential_key = 12_345
161
159
  end).to raise_error(TypeError)
162
160
  end
163
161
 
164
- it 'should have no client_credential_secret' do
162
+ it "should have no client_credential_secret" do
165
163
  expect(@client.client_credential_secret).to be_nil
166
164
  end
167
165
 
168
- it 'should allow the client_credential_secret to be set to a String' do
166
+ it "should allow the client_credential_secret to be set to a String" do
169
167
  @client.client_credential_secret = "54321"
170
168
  expect(@client.client_credential_secret).to eq "54321"
171
169
  end
172
170
 
173
- it 'should not allow the client_credential_secret ' +
174
- 'to be set to a non-String' do
171
+ it "should not allow the client_credential_secret " \
172
+ "to be set to a non-String" do
175
173
  expect(lambda do
176
- @client.client_credential_secret = 54321
174
+ @client.client_credential_secret = 54_321
177
175
  end).to raise_error(TypeError)
178
176
  end
179
177
 
180
- it 'should have an out-of-band callback' do
178
+ it "should have an out-of-band callback" do
181
179
  expect(@client.callback).to eq ::Signet::OAuth1::OUT_OF_BAND
182
180
  end
183
181
 
184
- it 'should allow the callback to be set to a String' do
182
+ it "should allow the callback to be set to a String" do
185
183
  @client.callback = "http://example.com/callback"
186
184
  expect(@client.callback).to eq "http://example.com/callback"
187
185
  end
188
186
 
189
- it 'should allow the callback to be set to a URI' do
187
+ it "should allow the callback to be set to a URI" do
190
188
  @client.callback =
191
- Addressable::URI.parse("http://example.com/callback")
189
+ Addressable::URI.parse "http://example.com/callback"
192
190
  expect(@client.callback).to eq "http://example.com/callback"
193
191
  end
194
192
 
195
- it 'should not allow the callback to be set to a non-String' do
193
+ it "should not allow the callback to be set to a non-String" do
196
194
  expect(lambda do
197
- @client.callback = 12345
195
+ @client.callback = 12_345
198
196
  end).to raise_error(TypeError)
199
197
  end
200
198
 
201
- it 'should raise an error if the temporary credentials URI is not set' do
202
- @client.client_credential_key = 'dpf43f3p2l4k3l03'
203
- @client.client_credential_secret = 'kd94hf93k423kf44'
199
+ it "should raise an error if the temporary credentials URI is not set" do
200
+ @client.client_credential_key = "dpf43f3p2l4k3l03"
201
+ @client.client_credential_secret = "kd94hf93k423kf44"
204
202
  expect(lambda do
205
203
  @client.generate_temporary_credential_request
206
204
  end).to raise_error(ArgumentError)
207
205
  end
208
206
 
209
- it 'should raise an error if the client credential key is not set' do
207
+ it "should raise an error if the client credential key is not set" do
210
208
  @client.temporary_credential_uri =
211
- 'http://example.com/temporary_credentials'
212
- @client.client_credential_secret = 'kd94hf93k423kf44'
209
+ "http://example.com/temporary_credentials"
210
+ @client.client_credential_secret = "kd94hf93k423kf44"
213
211
  expect(lambda do
214
212
  @client.generate_temporary_credential_request
215
213
  end).to raise_error(ArgumentError)
216
214
  end
217
215
 
218
- it 'should raise an error if the client credential secret is not set' do
216
+ it "should raise an error if the client credential secret is not set" do
219
217
  @client.temporary_credential_uri =
220
- 'http://example.com/temporary_credentials'
221
- @client.client_credential_key = 'dpf43f3p2l4k3l03'
218
+ "http://example.com/temporary_credentials"
219
+ @client.client_credential_key = "dpf43f3p2l4k3l03"
222
220
  expect(lambda do
223
221
  @client.generate_temporary_credential_request
224
222
  end).to raise_error(ArgumentError)
225
223
  end
226
224
 
227
- it 'should have no temporary_credential' do
225
+ it "should have no temporary_credential" do
228
226
  expect(@client.temporary_credential).to be_nil
229
227
  end
230
228
 
231
- it 'should raise an error for partially set temporary credentials' do
229
+ it "should raise an error for partially set temporary credentials" do
232
230
  @client.temporary_credential_key = "12345"
233
231
  @client.temporary_credential_secret = nil
234
232
  expect(lambda do
@@ -236,7 +234,7 @@ describe Signet::OAuth1::Client, 'unconfigured' do
236
234
  end).to raise_error(ArgumentError)
237
235
  end
238
236
 
239
- it 'should raise an error for partially set temporary credentials' do
237
+ it "should raise an error for partially set temporary credentials" do
240
238
  @client.temporary_credential_key = nil
241
239
  @client.temporary_credential_secret = "54321"
242
240
  expect(lambda do
@@ -244,16 +242,16 @@ describe Signet::OAuth1::Client, 'unconfigured' do
244
242
  end).to raise_error(ArgumentError)
245
243
  end
246
244
 
247
- it 'should allow the temporary_credential to be set to a ' +
248
- 'Signet::OAuth1::Credential' do
245
+ it "should allow the temporary_credential to be set to a " \
246
+ "Signet::OAuth1::Credential" do
249
247
  @client.temporary_credential =
250
- Signet::OAuth1::Credential.new("12345", "54321")
248
+ Signet::OAuth1::Credential.new "12345", "54321"
251
249
  expect(@client.temporary_credential_key).to eq "12345"
252
250
  expect(@client.temporary_credential_secret).to eq "54321"
253
- expect(@client.temporary_credential).to eq Signet::OAuth1::Credential.new("12345", "54321")
251
+ expect(@client.temporary_credential).to eq Signet::OAuth1::Credential.new("12345", "54321")
254
252
  end
255
253
 
256
- it 'should allow the temporary_credential to be set to nil' do
254
+ it "should allow the temporary_credential to be set to nil" do
257
255
  @client.temporary_credential_key = "12345"
258
256
  @client.temporary_credential_secret = "54321"
259
257
  expect(@client.temporary_credential_key).to eq "12345"
@@ -264,49 +262,49 @@ describe Signet::OAuth1::Client, 'unconfigured' do
264
262
  expect(@client.temporary_credential_secret).to be_nil
265
263
  end
266
264
 
267
- it 'should not allow the temporary_credential to be set to a bogus value' do
265
+ it "should not allow the temporary_credential to be set to a bogus value" do
268
266
  expect(lambda do
269
267
  @client.temporary_credential = 42
270
268
  end).to raise_error(TypeError)
271
269
  end
272
270
 
273
- it 'should have no temporary_credential_key' do
271
+ it "should have no temporary_credential_key" do
274
272
  expect(@client.temporary_credential_key).to be_nil
275
273
  end
276
274
 
277
- it 'should allow the temporary_credential_key to be set to a String' do
275
+ it "should allow the temporary_credential_key to be set to a String" do
278
276
  @client.temporary_credential_key = "12345"
279
277
  expect(@client.temporary_credential_key).to eq "12345"
280
278
  end
281
279
 
282
- it 'should not allow the temporary_credential_key ' +
283
- 'to be set to a non-String' do
280
+ it "should not allow the temporary_credential_key " \
281
+ "to be set to a non-String" do
284
282
  expect(lambda do
285
- @client.temporary_credential_key = 12345
283
+ @client.temporary_credential_key = 12_345
286
284
  end).to raise_error(TypeError)
287
285
  end
288
286
 
289
- it 'should have no temporary_credential_secret' do
287
+ it "should have no temporary_credential_secret" do
290
288
  expect(@client.temporary_credential_secret).to be_nil
291
289
  end
292
290
 
293
- it 'should allow the temporary_credential_secret to be set to a String' do
291
+ it "should allow the temporary_credential_secret to be set to a String" do
294
292
  @client.temporary_credential_secret = "54321"
295
293
  expect(@client.temporary_credential_secret).to eq "54321"
296
294
  end
297
295
 
298
- it 'should not allow the temporary_credential_secret ' +
299
- 'to be set to a non-String' do
296
+ it "should not allow the temporary_credential_secret " \
297
+ "to be set to a non-String" do
300
298
  expect(lambda do
301
- @client.temporary_credential_secret = 54321
299
+ @client.temporary_credential_secret = 54_321
302
300
  end).to raise_error(TypeError)
303
301
  end
304
302
 
305
- it 'should have no token_credential' do
303
+ it "should have no token_credential" do
306
304
  expect(@client.token_credential).to be_nil
307
305
  end
308
306
 
309
- it 'should raise an error for partially set token credentials' do
307
+ it "should raise an error for partially set token credentials" do
310
308
  @client.token_credential_key = "12345"
311
309
  @client.token_credential_secret = nil
312
310
  expect(lambda do
@@ -314,7 +312,7 @@ describe Signet::OAuth1::Client, 'unconfigured' do
314
312
  end).to raise_error(ArgumentError)
315
313
  end
316
314
 
317
- it 'should raise an error for partially set token credentials' do
315
+ it "should raise an error for partially set token credentials" do
318
316
  @client.token_credential_key = nil
319
317
  @client.token_credential_secret = "54321"
320
318
  expect(lambda do
@@ -322,16 +320,16 @@ describe Signet::OAuth1::Client, 'unconfigured' do
322
320
  end).to raise_error(ArgumentError)
323
321
  end
324
322
 
325
- it 'should allow the token_credential to be set to a ' +
326
- 'Signet::OAuth1::Credential' do
323
+ it "should allow the token_credential to be set to a " \
324
+ "Signet::OAuth1::Credential" do
327
325
  @client.token_credential =
328
- Signet::OAuth1::Credential.new("12345", "54321")
326
+ Signet::OAuth1::Credential.new "12345", "54321"
329
327
  expect(@client.token_credential_key).to eq "12345"
330
328
  expect(@client.token_credential_secret).to eq "54321"
331
329
  expect(@client.token_credential).to eq Signet::OAuth1::Credential.new("12345", "54321")
332
330
  end
333
331
 
334
- it 'should allow the token_credential to be set to nil' do
332
+ it "should allow the token_credential to be set to nil" do
335
333
  @client.token_credential_key = "12345"
336
334
  @client.token_credential_secret = "54321"
337
335
  expect(@client.token_credential_key).to eq "12345"
@@ -342,470 +340,470 @@ describe Signet::OAuth1::Client, 'unconfigured' do
342
340
  expect(@client.token_credential_secret).to be_nil
343
341
  end
344
342
 
345
- it 'should not allow the token_credential to be set to a bogus value' do
343
+ it "should not allow the token_credential to be set to a bogus value" do
346
344
  expect(lambda do
347
345
  @client.token_credential = 42
348
346
  end).to raise_error(TypeError)
349
347
  end
350
348
 
351
- it 'should have no token_credential_key' do
349
+ it "should have no token_credential_key" do
352
350
  expect(@client.token_credential_key).to be_nil
353
351
  end
354
352
 
355
- it 'should allow the token_credential_key to be set to a String' do
353
+ it "should allow the token_credential_key to be set to a String" do
356
354
  @client.token_credential_key = "12345"
357
355
  expect(@client.token_credential_key).to eq "12345"
358
356
  end
359
357
 
360
- it 'should not allow the token_credential_key ' +
361
- 'to be set to a non-String' do
358
+ it "should not allow the token_credential_key " \
359
+ "to be set to a non-String" do
362
360
  expect(lambda do
363
- @client.token_credential_key = 12345
361
+ @client.token_credential_key = 12_345
364
362
  end).to raise_error(TypeError)
365
363
  end
366
364
 
367
- it 'should have no token_credential_secret' do
365
+ it "should have no token_credential_secret" do
368
366
  expect(@client.token_credential_secret).to be_nil
369
367
  end
370
368
 
371
- it 'should allow the token_credential_secret to be set to a String' do
369
+ it "should allow the token_credential_secret to be set to a String" do
372
370
  @client.token_credential_secret = "54321"
373
371
  expect(@client.token_credential_secret).to eq "54321"
374
372
  end
375
373
 
376
- it 'should not allow the token_credential_secret ' +
377
- 'to be set to a non-String' do
374
+ it "should not allow the token_credential_secret " \
375
+ "to be set to a non-String" do
378
376
  expect(lambda do
379
- @client.token_credential_secret = 54321
377
+ @client.token_credential_secret = 54_321
380
378
  end).to raise_error(TypeError)
381
379
  end
382
380
 
383
- it 'should not allow the two_legged flag ' +
384
- 'to be set to a non-Boolean' do
381
+ it "should not allow the two_legged flag " \
382
+ "to be set to a non-Boolean" do
385
383
  expect(lambda do
386
384
  @client.two_legged = 42
387
385
  end).to raise_error(TypeError)
388
386
  end
389
387
  end
390
388
 
391
- describe Signet::OAuth1::Client, 'configured' do
389
+ describe Signet::OAuth1::Client, "configured" do
392
390
  before do
393
391
  @client = Signet::OAuth1::Client.new
394
392
  @client.temporary_credential_uri =
395
- 'http://example.com/temporary_credentials'
393
+ "http://example.com/temporary_credentials"
396
394
  @client.authorization_uri =
397
- 'http://example.com/authorize'
395
+ "http://example.com/authorize"
398
396
  @client.token_credential_uri =
399
- 'http://example.com/token_credentials'
400
- @client.callback = 'http://example.com/callback'
401
- @client.client_credential_key = 'dpf43f3p2l4k3l03'
402
- @client.client_credential_secret = 'kd94hf93k423kf44'
403
- @client.temporary_credential_key = 'hh5s93j4hdidpola'
404
- @client.temporary_credential_secret = 'hdhd0244k9j7ao03'
405
- @client.token_credential_key = 'nnch734d00sl2jdk'
406
- @client.token_credential_secret = 'pfkkdhi9sl3r4s00'
397
+ "http://example.com/token_credentials"
398
+ @client.callback = "http://example.com/callback"
399
+ @client.client_credential_key = "dpf43f3p2l4k3l03"
400
+ @client.client_credential_secret = "kd94hf93k423kf44"
401
+ @client.temporary_credential_key = "hh5s93j4hdidpola"
402
+ @client.temporary_credential_secret = "hdhd0244k9j7ao03"
403
+ @client.token_credential_key = "nnch734d00sl2jdk"
404
+ @client.token_credential_secret = "pfkkdhi9sl3r4s00"
407
405
  end
408
406
 
409
- it 'should generate a JSON representation of the client' do
407
+ it "should generate a JSON representation of the client" do
410
408
  json = @client.to_json
411
409
  expect(json).not_to be_nil
412
410
 
413
- deserialized = MultiJson.load(json)
414
- expect(deserialized["temporary_credential_uri"]).to eq 'http://example.com/temporary_credentials'
411
+ deserialized = MultiJson.load json
412
+ expect(deserialized["temporary_credential_uri"]).to eq "http://example.com/temporary_credentials"
415
413
  expect(deserialized["authorization_uri"]).to include(
416
- 'http://example.com/authorize')
417
- expect(deserialized["token_credential_uri"]).to eq 'http://example.com/token_credentials'
418
- expect(deserialized["callback"]).to eq 'http://example.com/callback'
419
- expect(deserialized["client_credential_key"]).to eq 'dpf43f3p2l4k3l03'
420
- expect(deserialized["client_credential_secret"]).to eq 'kd94hf93k423kf44'
421
- expect(deserialized["temporary_credential_key"]).to eq 'hh5s93j4hdidpola'
422
- expect(deserialized["temporary_credential_secret"]).to eq 'hdhd0244k9j7ao03'
423
- expect(deserialized["token_credential_key"]).to eq 'nnch734d00sl2jdk'
424
- expect(deserialized["token_credential_secret"]).to eq 'pfkkdhi9sl3r4s00'
425
- end
426
-
427
- it 'should generate an authorization URI with a callback' do
414
+ "http://example.com/authorize"
415
+ )
416
+ expect(deserialized["token_credential_uri"]).to eq "http://example.com/token_credentials"
417
+ expect(deserialized["callback"]).to eq "http://example.com/callback"
418
+ expect(deserialized["client_credential_key"]).to eq "dpf43f3p2l4k3l03"
419
+ expect(deserialized["client_credential_secret"]).to eq "kd94hf93k423kf44"
420
+ expect(deserialized["temporary_credential_key"]).to eq "hh5s93j4hdidpola"
421
+ expect(deserialized["temporary_credential_secret"]).to eq "hdhd0244k9j7ao03"
422
+ expect(deserialized["token_credential_key"]).to eq "nnch734d00sl2jdk"
423
+ expect(deserialized["token_credential_secret"]).to eq "pfkkdhi9sl3r4s00"
424
+ end
425
+
426
+ it "should generate an authorization URI with a callback" do
428
427
  @client.temporary_credential_key = nil
429
- expect(@client.authorization_uri.to_s).to eq 'http://example.com/authorize?oauth_callback=http://example.com/callback'
428
+ expect(@client.authorization_uri.to_s).to eq "http://example.com/authorize?oauth_callback=http://example.com/callback"
430
429
  end
431
430
 
432
- it 'should generate an authorization URI with a temporary credential' do
431
+ it "should generate an authorization URI with a temporary credential" do
433
432
  @client.callback = nil
434
433
  expect(@client.authorization_uri.to_s).to include(
435
- 'oauth_token=hh5s93j4hdidpola'
434
+ "oauth_token=hh5s93j4hdidpola"
436
435
  )
437
436
  end
438
437
 
439
- it 'should generate an authorization URI both a callback and ' +
440
- 'a temporary credential' do
438
+ it "should generate an authorization URI both a callback and " \
439
+ "a temporary credential" do
441
440
  expect(@client.authorization_uri.to_s).to include(
442
- 'oauth_callback=http://example.com/callback'
441
+ "oauth_callback=http://example.com/callback"
443
442
  )
444
443
  expect(@client.authorization_uri.to_s).to include(
445
- 'oauth_token=hh5s93j4hdidpola'
444
+ "oauth_token=hh5s93j4hdidpola"
446
445
  )
447
446
  end
448
447
 
449
- it 'should generate an authorization URI with additional parameters' do
448
+ it "should generate an authorization URI with additional parameters" do
450
449
  authorization_uri = @client.authorization_uri(
451
- :additional_parameters => {:domain => 'www.example.com'}
450
+ additional_parameters: { domain: "www.example.com" }
452
451
  )
453
452
  expect(authorization_uri.to_s).to include(
454
- 'oauth_callback=http://example.com/callback'
453
+ "oauth_callback=http://example.com/callback"
455
454
  )
456
455
  expect(authorization_uri.to_s).to include(
457
- 'oauth_token=hh5s93j4hdidpola'
456
+ "oauth_token=hh5s93j4hdidpola"
458
457
  )
459
458
  expect(authorization_uri.to_s).to include(
460
- 'domain=www.example.com'
459
+ "domain=www.example.com"
461
460
  )
462
461
  end
463
462
 
464
- it 'should raise an error if the verifier is not provided' do
463
+ it "should raise an error if the verifier is not provided" do
465
464
  expect(lambda do
466
465
  @client.generate_token_credential_request
467
466
  end).to raise_error(ArgumentError)
468
467
  expect(lambda do
469
- @client.generate_token_credential_request(:verifier => nil)
468
+ @client.generate_token_credential_request verifier: nil
470
469
  end).to raise_error(ArgumentError)
471
470
  end
472
471
 
473
- it 'should raise an error if the token credentials URI is not set' do
472
+ it "should raise an error if the token credentials URI is not set" do
474
473
  @client.token_credential_uri = nil
475
474
  expect(lambda do
476
- @client.generate_token_credential_request(:verifier => '12345')
475
+ @client.generate_token_credential_request verifier: "12345"
477
476
  end).to raise_error(ArgumentError)
478
477
  end
479
478
 
480
- it 'should raise an error if the client credential key is not set' do
479
+ it "should raise an error if the client credential key is not set" do
481
480
  @client.client_credential_key = nil
482
481
  expect(lambda do
483
- @client.generate_token_credential_request(:verifier => '12345')
482
+ @client.generate_token_credential_request verifier: "12345"
484
483
  end).to raise_error(ArgumentError)
485
484
  end
486
485
 
487
- it 'should raise an error if the client credential secret is not set' do
486
+ it "should raise an error if the client credential secret is not set" do
488
487
  @client.client_credential_secret = nil
489
488
  expect(lambda do
490
- @client.generate_token_credential_request(:verifier => '12345')
489
+ @client.generate_token_credential_request verifier: "12345"
491
490
  end).to raise_error(ArgumentError)
492
491
  end
493
492
 
494
- it 'should raise an error if the temporary credential key is not set' do
493
+ it "should raise an error if the temporary credential key is not set" do
495
494
  @client.temporary_credential_key = nil
496
495
  expect(lambda do
497
- @client.generate_token_credential_request(:verifier => '12345')
496
+ @client.generate_token_credential_request verifier: "12345"
498
497
  end).to raise_error(ArgumentError)
499
498
  end
500
499
 
501
- it 'should raise an error if the temporary credential secret is not set' do
500
+ it "should raise an error if the temporary credential secret is not set" do
502
501
  @client.temporary_credential_secret = nil
503
502
  expect(lambda do
504
- @client.generate_token_credential_request(:verifier => '12345')
503
+ @client.generate_token_credential_request verifier: "12345"
505
504
  end).to raise_error(ArgumentError)
506
505
  end
507
506
 
508
- it 'should raise an error if the client credential key is not set' do
507
+ it "should raise an error if the client credential key is not set" do
509
508
  @client.client_credential_key = nil
510
509
  expect(lambda do
511
510
  @client.generate_authenticated_request
512
511
  end).to raise_error(ArgumentError)
513
512
  end
514
513
 
515
- it 'should raise an error if the client credential secret is not set' do
514
+ it "should raise an error if the client credential secret is not set" do
516
515
  @client.client_credential_secret = nil
517
516
  expect(lambda do
518
517
  @client.generate_authenticated_request
519
518
  end).to raise_error(ArgumentError)
520
519
  end
521
520
 
522
- it 'should raise an error if the token credential key is not set' do
521
+ it "should raise an error if the token credential key is not set" do
523
522
  @client.token_credential_key = nil
524
523
  expect(lambda do
525
524
  @client.generate_authenticated_request
526
525
  end).to raise_error(ArgumentError)
527
526
  end
528
527
 
529
- it 'should raise an error if the token credential secret is not set' do
528
+ it "should raise an error if the token credential secret is not set" do
530
529
  @client.token_credential_secret = nil
531
530
  expect(lambda do
532
531
  @client.generate_authenticated_request
533
532
  end).to raise_error(ArgumentError)
534
533
  end
535
534
 
536
- it 'should raise an error if no request is provided' do
535
+ it "should raise an error if no request is provided" do
537
536
  expect(lambda do
538
537
  @client.generate_authenticated_request
539
538
  end).to raise_error(ArgumentError)
540
539
  end
541
540
 
542
- it 'should raise an error if a bogus request is provided' do
543
- expect {
544
- @client.generate_authenticated_request(
545
- :request => []
546
- )
547
- }.to raise_error(ArgumentError)
541
+ it "should raise an error if a bogus request is provided" do
542
+ expect do
543
+ @client.generate_authenticated_request(
544
+ request: []
545
+ )
546
+ end.to raise_error(ArgumentError)
548
547
  end
549
548
 
550
- it 'should not raise an error if a request is ' +
551
- 'provided without a connection' do
549
+ it "should not raise an error if a request is "\
550
+ "provided without a connection" do
552
551
  request = @client.generate_authenticated_request(
553
- :request => conn.build_request(:get) do |req|
554
- req.url('http://www.example.com/')
552
+ request: conn.build_request(:get) do |req|
553
+ req.url "http://www.example.com/"
555
554
  end
556
555
  )
557
556
  end
558
557
 
559
- it 'should raise an error if no URI is provided' do
558
+ it "should raise an error if no URI is provided" do
560
559
  expect(lambda do
561
560
  @client.generate_authenticated_request(
562
- :method => 'GET',
563
- :headers => [],
564
- :body => ''
561
+ :method => "GET",
562
+ headers: [],
563
+ :body => ""
565
564
  )
566
565
  end).to raise_error(ArgumentError)
567
566
  end
568
567
 
569
- it 'should not raise an error if a request body is chunked' do
568
+ it "should not raise an error if a request body is chunked" do
570
569
  request = @client.generate_authenticated_request(
571
- :method => 'POST',
572
- :uri => 'https://photos.example.net/photos',
573
- :body => ['A chunked body.']
570
+ method: "POST",
571
+ :uri => "https://photos.example.net/photos",
572
+ :body => ["A chunked body."]
574
573
  )
575
574
  expect(request).to be_kind_of(Faraday::Request)
576
- expect(request.body).to eq 'A chunked body.'
575
+ expect(request.body).to eq "A chunked body."
577
576
  end
578
577
 
579
- it 'should not raise an error if a request body is chunked' do
578
+ it "should not raise an error if a request body is chunked" do
580
579
  chunked_body = StringIO.new
581
- chunked_body.write('A chunked body.')
580
+ chunked_body.write "A chunked body."
582
581
  chunked_body.rewind
583
582
  request = @client.generate_authenticated_request(
584
- :method => 'POST',
585
- :uri => 'https://photos.example.net/photos',
586
- :body => chunked_body
583
+ method: "POST",
584
+ :uri => "https://photos.example.net/photos",
585
+ :body => chunked_body
587
586
  )
588
587
  expect(request).to be_kind_of(Faraday::Request)
589
- expect(request.body).to eq 'A chunked body.'
588
+ expect(request.body).to eq "A chunked body."
590
589
  end
591
590
 
592
- it 'should raise an error if a request body is of a bogus type' do
591
+ it "should raise an error if a request body is of a bogus type" do
593
592
  expect(lambda do
594
593
  @client.generate_authenticated_request(
595
- :method => 'POST',
596
- :uri => 'https://photos.example.net/photos',
597
- :body => 42
594
+ method: "POST",
595
+ :uri => "https://photos.example.net/photos",
596
+ :body => 42
598
597
  )
599
598
  end).to raise_error(TypeError)
600
599
  end
601
600
 
602
- it 'should correctly fetch the temporary credentials' do
601
+ it "should correctly fetch the temporary credentials" do
603
602
  # Repeat this because signatures change from test to test
604
603
  10.times do
605
604
  request = @client.generate_temporary_credential_request
606
605
  expect(request.method).to eq :post
607
- expect(request.path).to eq 'http://example.com/temporary_credentials'
608
- authorization_header = request.headers['Authorization']
606
+ expect(request.path).to eq "http://example.com/temporary_credentials"
607
+ authorization_header = request.headers["Authorization"]
609
608
  parameters = ::Signet::OAuth1.parse_authorization_header(
610
609
  authorization_header
611
- ).inject({}) { |h,(k,v)| h[k]=v; h }
612
- expect(parameters).not_to have_key('oauth_client_credential_key')
613
- expect(parameters).not_to have_key('oauth_temporary_credential_key')
614
- expect(parameters).not_to have_key('oauth_token')
615
- expect(parameters['oauth_nonce']).to match(/^\w+$/)
616
- expect(parameters['oauth_callback']).to eq @client.callback
617
- expect(parameters['oauth_timestamp']).to match(/^\d+$/)
618
- expect(parameters['oauth_signature_method']).to eq 'HMAC-SHA1'
619
- expect(parameters['oauth_consumer_key']).to eq @client.client_credential_key
620
- expect(parameters['oauth_signature']).to match(/^[a-zA-Z0-9\=\/\+]+$/)
621
- expect(parameters['oauth_version']).to eq '1.0'
610
+ ).inject({}) { |h, (k, v)| h[k] = v; h }
611
+ expect(parameters).not_to have_key("oauth_client_credential_key")
612
+ expect(parameters).not_to have_key("oauth_temporary_credential_key")
613
+ expect(parameters).not_to have_key("oauth_token")
614
+ expect(parameters["oauth_nonce"]).to match(/^\w+$/)
615
+ expect(parameters["oauth_callback"]).to eq @client.callback
616
+ expect(parameters["oauth_timestamp"]).to match(/^\d+$/)
617
+ expect(parameters["oauth_signature_method"]).to eq "HMAC-SHA1"
618
+ expect(parameters["oauth_consumer_key"]).to eq @client.client_credential_key
619
+ expect(parameters["oauth_signature"]).to match(%r{^[a-zA-Z0-9\=/\+]+$})
620
+ expect(parameters["oauth_version"]).to eq "1.0"
622
621
  end
623
622
  end
624
623
 
625
- it 'should correctly fetch the token credentials' do
624
+ it "should correctly fetch the token credentials" do
626
625
  # Repeat this because signatures change from test to test
627
626
  10.times do
628
627
  request = @client.generate_token_credential_request(
629
- :verifier => '473f82d3'
628
+ verifier: "473f82d3"
630
629
  )
631
630
  expect(request.method).to eq :post
632
- expect(request.path).to eq 'http://example.com/token_credentials'
633
- authorization_header = request.headers['Authorization']
631
+ expect(request.path).to eq "http://example.com/token_credentials"
632
+ authorization_header = request.headers["Authorization"]
634
633
  parameters = ::Signet::OAuth1.parse_authorization_header(
635
634
  authorization_header
636
- ).inject({}) { |h,(k,v)| h[k]=v; h }
637
- expect(parameters).not_to have_key('oauth_client_credential_key')
638
- expect(parameters).not_to have_key('oauth_temporary_credential_key')
639
- expect(parameters).not_to have_key('oauth_callback')
640
- expect(parameters['oauth_nonce']).to match(/^\w+$/)
641
- expect(parameters['oauth_timestamp']).to match(/^\d+$/)
642
- expect(parameters['oauth_signature_method']).to eq 'HMAC-SHA1'
643
- expect(parameters['oauth_consumer_key']).to eq @client.client_credential_key
644
- expect(parameters['oauth_token']).to eq @client.temporary_credential_key
645
- expect(parameters['oauth_signature']).to match(/^[a-zA-Z0-9\=\/\+]+$/)
646
- expect(parameters['oauth_verifier']).to eq '473f82d3'
647
- expect(parameters['oauth_version']).to eq '1.0'
635
+ ).inject({}) { |h, (k, v)| h[k] = v; h }
636
+ expect(parameters).not_to have_key("oauth_client_credential_key")
637
+ expect(parameters).not_to have_key("oauth_temporary_credential_key")
638
+ expect(parameters).not_to have_key("oauth_callback")
639
+ expect(parameters["oauth_nonce"]).to match(/^\w+$/)
640
+ expect(parameters["oauth_timestamp"]).to match(/^\d+$/)
641
+ expect(parameters["oauth_signature_method"]).to eq "HMAC-SHA1"
642
+ expect(parameters["oauth_consumer_key"]).to eq @client.client_credential_key
643
+ expect(parameters["oauth_token"]).to eq @client.temporary_credential_key
644
+ expect(parameters["oauth_signature"]).to match(%r{^[a-zA-Z0-9\=/\+]+$})
645
+ expect(parameters["oauth_verifier"]).to eq "473f82d3"
646
+ expect(parameters["oauth_version"]).to eq "1.0"
648
647
  end
649
648
  end
650
649
 
651
- it 'should correctly fetch the protected resource' do
650
+ it "should correctly fetch the protected resource" do
652
651
  # Repeat this because signatures change from test to test
653
652
  10.times do
654
653
  original_request = [
655
- 'GET',
656
- 'https://photos.example.net/photos?file=vacation.jpg&size=original',
657
- [['Host', 'photos.example.net']],
658
- ['']
654
+ "GET",
655
+ "https://photos.example.net/photos?file=vacation.jpg&size=original",
656
+ [["Host", "photos.example.net"]],
657
+ [""]
659
658
  ]
660
659
  signed_request = @client.generate_authenticated_request(
661
- :request => original_request
660
+ request: original_request
662
661
  )
663
662
  expect(signed_request.method).to eq :get
664
- expect(signed_request.path).to eq 'https://photos.example.net/photos'
665
- expect(signed_request.params).to eq({"file"=>"vacation.jpg", "size"=>"original"})
666
- authorization_header = signed_request.headers['Authorization']
667
- expect(signed_request.body).to eq ''
663
+ expect(signed_request.path).to eq "https://photos.example.net/photos"
664
+ expect(signed_request.params).to eq({ "file" => "vacation.jpg", "size" => "original" })
665
+ authorization_header = signed_request.headers["Authorization"]
666
+ expect(signed_request.body).to eq ""
668
667
  parameters = ::Signet::OAuth1.parse_authorization_header(
669
668
  authorization_header
670
- ).inject({}) { |h,(k,v)| h[k]=v; h }
671
- expect(parameters).not_to have_key('oauth_client_credential_key')
672
- expect(parameters).not_to have_key('oauth_temporary_credential_key')
673
- expect(parameters).not_to have_key('oauth_token_credential_key')
674
- expect(parameters).not_to have_key('oauth_callback')
675
- expect(parameters['oauth_nonce']).to match(/^\w+$/)
676
- expect(parameters['oauth_timestamp']).to match(/^\d+$/)
677
- expect(parameters['oauth_signature_method']).to eq 'HMAC-SHA1'
678
- expect(parameters['oauth_consumer_key']).to eq @client.client_credential_key
679
- expect(parameters['oauth_token']).to eq @client.token_credential_key
680
- expect(parameters['oauth_signature']).to match(/^[a-zA-Z0-9\=\/\+]+$/)
681
- expect(parameters['oauth_version']).to eq '1.0'
669
+ ).inject({}) { |h, (k, v)| h[k] = v; h }
670
+ expect(parameters).not_to have_key("oauth_client_credential_key")
671
+ expect(parameters).not_to have_key("oauth_temporary_credential_key")
672
+ expect(parameters).not_to have_key("oauth_token_credential_key")
673
+ expect(parameters).not_to have_key("oauth_callback")
674
+ expect(parameters["oauth_nonce"]).to match(/^\w+$/)
675
+ expect(parameters["oauth_timestamp"]).to match(/^\d+$/)
676
+ expect(parameters["oauth_signature_method"]).to eq "HMAC-SHA1"
677
+ expect(parameters["oauth_consumer_key"]).to eq @client.client_credential_key
678
+ expect(parameters["oauth_token"]).to eq @client.token_credential_key
679
+ expect(parameters["oauth_signature"]).to match(%r{^[a-zA-Z0-9\=/\+]+$})
680
+ expect(parameters["oauth_version"]).to eq "1.0"
682
681
  end
683
682
  end
684
683
 
685
- it 'should correctly fetch the protected resource' do
684
+ it "should correctly fetch the protected resource" do
686
685
  # Repeat this because signatures change from test to test
687
686
  10.times do
688
687
  original_request = [
689
- 'POST',
690
- 'https://photos.example.net/photos',
688
+ "POST",
689
+ "https://photos.example.net/photos",
691
690
  [
692
- ['Host', 'photos.example.net'],
693
- ['Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'],
694
- ['Content-Length', '31'],
691
+ ["Host", "photos.example.net"],
692
+ ["Content-Type", "application/x-www-form-urlencoded; charset=utf-8"],
693
+ ["Content-Length", "31"]
695
694
  ],
696
- ['file=vacation.jpg&size=original']
695
+ ["file=vacation.jpg&size=original"]
697
696
  ]
698
697
  signed_request = @client.generate_authenticated_request(
699
- :request => original_request
698
+ request: original_request
700
699
  )
701
700
  expect(signed_request.method).to eq :post
702
- expect(signed_request.path).to eq 'https://photos.example.net/photos'
703
- authorization_header = signed_request.headers['Authorization']
704
- expect(signed_request.body).to eq 'file=vacation.jpg&size=original'
701
+ expect(signed_request.path).to eq "https://photos.example.net/photos"
702
+ authorization_header = signed_request.headers["Authorization"]
703
+ expect(signed_request.body).to eq "file=vacation.jpg&size=original"
705
704
  parameters = ::Signet::OAuth1.parse_authorization_header(
706
705
  authorization_header
707
- ).inject({}) { |h,(k,v)| h[k]=v; h }
708
- expect(parameters).not_to have_key('oauth_client_credential_key')
709
- expect(parameters).not_to have_key('oauth_temporary_credential_key')
710
- expect(parameters).not_to have_key('oauth_token_credential_key')
711
- expect(parameters).not_to have_key('oauth_callback')
712
- expect(parameters['oauth_nonce']).to match(/^\w+$/)
713
- expect(parameters['oauth_timestamp']).to match(/^\d+$/)
714
- expect(parameters['oauth_signature_method']).to eq 'HMAC-SHA1'
715
- expect(parameters['oauth_consumer_key']).to eq @client.client_credential_key
716
- expect(parameters['oauth_token']).to eq @client.token_credential_key
717
- expect(parameters['oauth_signature']).to match(/^[a-zA-Z0-9\=\/\+]+$/)
718
- expect(parameters['oauth_version']).to eq '1.0'
706
+ ).inject({}) { |h, (k, v)| h[k] = v; h }
707
+ expect(parameters).not_to have_key("oauth_client_credential_key")
708
+ expect(parameters).not_to have_key("oauth_temporary_credential_key")
709
+ expect(parameters).not_to have_key("oauth_token_credential_key")
710
+ expect(parameters).not_to have_key("oauth_callback")
711
+ expect(parameters["oauth_nonce"]).to match(/^\w+$/)
712
+ expect(parameters["oauth_timestamp"]).to match(/^\d+$/)
713
+ expect(parameters["oauth_signature_method"]).to eq "HMAC-SHA1"
714
+ expect(parameters["oauth_consumer_key"]).to eq @client.client_credential_key
715
+ expect(parameters["oauth_token"]).to eq @client.token_credential_key
716
+ expect(parameters["oauth_signature"]).to match(%r{^[a-zA-Z0-9\=/\+]+$})
717
+ expect(parameters["oauth_version"]).to eq "1.0"
719
718
  end
720
719
  end
721
720
 
722
- describe 'with Faraday requests' do
723
-
724
- it 'should correctly get the protected resource' do
721
+ describe "with Faraday requests" do
722
+ it "should correctly get the protected resource" do
725
723
  # Repeat this because signatures change from test to test
726
724
  10.times do
727
- original_request = conn.build_request(:get) do |req|
725
+ original_request = conn.build_request :get do |req|
728
726
  req.url(
729
- 'https://photos.example.net/photos?file=vacation.jpg&size=original'
727
+ "https://photos.example.net/photos?file=vacation.jpg&size=original"
730
728
  )
731
729
  req.headers = Faraday::Utils::Headers.new(
732
- [['Host', 'photos.example.net']]
730
+ [["Host", "photos.example.net"]]
733
731
  )
734
- req.body = ''
732
+ req.body = ""
735
733
  end
736
734
 
737
735
  signed_request = @client.generate_authenticated_request(
738
- :request => original_request
736
+ request: original_request
739
737
  )
740
738
 
741
739
  # Should be same request object
742
- expect(original_request['Authorization']).to eq signed_request['Authorization']
740
+ expect(original_request["Authorization"]).to eq signed_request["Authorization"]
743
741
 
744
742
  expect(signed_request.method).to eq :get
745
- expect(signed_request.path).to eq 'https://photos.example.net/photos'
746
- expect(signed_request.params).to eq ({"file"=>"vacation.jpg", "size"=>"original"})
747
- authorization_header = signed_request.headers['Authorization']
748
- expect(signed_request.body).to eq ''
743
+ expect(signed_request.path).to eq "https://photos.example.net/photos"
744
+ expect(signed_request.params).to eq ({ "file" => "vacation.jpg", "size" => "original" })
745
+ authorization_header = signed_request.headers["Authorization"]
746
+ expect(signed_request.body).to eq ""
749
747
  parameters = ::Signet::OAuth1.parse_authorization_header(
750
748
  authorization_header
751
- ).inject({}) { |h,(k,v)| h[k]=v; h }
752
- expect(parameters).not_to have_key('oauth_client_credential_key')
753
- expect(parameters).not_to have_key('oauth_temporary_credential_key')
754
- expect(parameters).not_to have_key('oauth_token_credential_key')
755
- expect(parameters).not_to have_key('oauth_callback')
756
- expect(parameters['oauth_nonce']).to match(/^\w+$/)
757
- expect(parameters['oauth_timestamp']).to match(/^\d+$/)
758
- expect(parameters['oauth_signature_method']).to eq 'HMAC-SHA1'
759
- expect(parameters['oauth_consumer_key']).to eq @client.client_credential_key
760
- expect(parameters['oauth_token']).to eq @client.token_credential_key
761
- expect(parameters['oauth_signature']).to match(/^[a-zA-Z0-9\=\/\+]+$/)
762
- expect(parameters['oauth_version']).to eq '1.0'
749
+ ).inject({}) { |h, (k, v)| h[k] = v; h }
750
+ expect(parameters).not_to have_key("oauth_client_credential_key")
751
+ expect(parameters).not_to have_key("oauth_temporary_credential_key")
752
+ expect(parameters).not_to have_key("oauth_token_credential_key")
753
+ expect(parameters).not_to have_key("oauth_callback")
754
+ expect(parameters["oauth_nonce"]).to match(/^\w+$/)
755
+ expect(parameters["oauth_timestamp"]).to match(/^\d+$/)
756
+ expect(parameters["oauth_signature_method"]).to eq "HMAC-SHA1"
757
+ expect(parameters["oauth_consumer_key"]).to eq @client.client_credential_key
758
+ expect(parameters["oauth_token"]).to eq @client.token_credential_key
759
+ expect(parameters["oauth_signature"]).to match(%r{^[a-zA-Z0-9\=/\+]+$})
760
+ expect(parameters["oauth_version"]).to eq "1.0"
763
761
  end
764
762
  end
765
763
 
766
- it 'should correctly post the protected resource' do
764
+ it "should correctly post the protected resource" do
767
765
  # Repeat this because signatures change from test to test
768
766
  10.times do
769
- original_request = conn.build_request(:post) do |req|
770
- req.url('https://photos.example.net/photos')
767
+ original_request = conn.build_request :post do |req|
768
+ req.url "https://photos.example.net/photos"
771
769
  req.headers = Faraday::Utils::Headers.new([
772
- ['Host', 'photos.example.net'],
773
- ['Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'],
774
- ['Content-Length', '31'],
775
- ])
770
+ ["Host", "photos.example.net"],
771
+ ["Content-Type", "application/x-www-form-urlencoded; charset=utf-8"],
772
+ ["Content-Length", "31"]
773
+ ])
776
774
  req.body = {
777
- 'size' => 'original',
778
- 'file' => 'vacation.jpg'
775
+ "size" => "original",
776
+ "file" => "vacation.jpg"
779
777
  }
780
778
  end
781
779
 
782
780
  signed_request = @client.generate_authenticated_request(
783
- :request => original_request
781
+ request: original_request
784
782
  )
785
783
 
786
784
  # Should be same request object
787
- expect(original_request['Authorization']).to eq signed_request['Authorization']
785
+ expect(original_request["Authorization"]).to eq signed_request["Authorization"]
788
786
 
789
787
  expect(signed_request.method).to eq :post
790
- expect(signed_request.path).to eq 'https://photos.example.net/photos'
791
- authorization_header = signed_request.headers['Authorization']
788
+ expect(signed_request.path).to eq "https://photos.example.net/photos"
789
+ authorization_header = signed_request.headers["Authorization"]
792
790
  # Can't rely on the order post parameters are encoded in.
793
- expect(signed_request.body).to include('file=vacation.jpg')
794
- expect(signed_request.body).to include('size=original')
791
+ expect(signed_request.body).to include("file=vacation.jpg")
792
+ expect(signed_request.body).to include("size=original")
795
793
  parameters = ::Signet::OAuth1.parse_authorization_header(
796
794
  authorization_header
797
- ).inject({}) { |h,(k,v)| h[k]=v; h }
798
- expect(parameters).not_to have_key('oauth_client_credential_key')
799
- expect(parameters).not_to have_key('oauth_temporary_credential_key')
800
- expect(parameters).not_to have_key('oauth_token_credential_key')
801
- expect(parameters).not_to have_key('oauth_callback')
802
- expect(parameters['oauth_nonce']).to match(/^\w+$/)
803
- expect(parameters['oauth_timestamp']).to match(/^\d+$/)
804
- expect(parameters['oauth_signature_method']).to eq 'HMAC-SHA1'
805
- expect(parameters['oauth_consumer_key']).to eq @client.client_credential_key
806
- expect(parameters['oauth_token']).to eq @client.token_credential_key
807
- expect(parameters['oauth_signature']).to match(/^[a-zA-Z0-9\=\/\+]+$/)
808
- expect(parameters['oauth_version']).to eq '1.0'
795
+ ).inject({}) { |h, (k, v)| h[k] = v; h }
796
+ expect(parameters).not_to have_key("oauth_client_credential_key")
797
+ expect(parameters).not_to have_key("oauth_temporary_credential_key")
798
+ expect(parameters).not_to have_key("oauth_token_credential_key")
799
+ expect(parameters).not_to have_key("oauth_callback")
800
+ expect(parameters["oauth_nonce"]).to match(/^\w+$/)
801
+ expect(parameters["oauth_timestamp"]).to match(/^\d+$/)
802
+ expect(parameters["oauth_signature_method"]).to eq "HMAC-SHA1"
803
+ expect(parameters["oauth_consumer_key"]).to eq @client.client_credential_key
804
+ expect(parameters["oauth_token"]).to eq @client.token_credential_key
805
+ expect(parameters["oauth_signature"]).to match(%r{^[a-zA-Z0-9\=/\+]+$})
806
+ expect(parameters["oauth_version"]).to eq "1.0"
809
807
  end
810
808
  end
811
809
  end