signet 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -36
  3. data/Gemfile +5 -4
  4. data/README.md +4 -5
  5. data/Rakefile +86 -37
  6. data/lib/signet.rb +17 -14
  7. data/lib/signet/errors.rb +4 -4
  8. data/lib/signet/oauth_1.rb +128 -153
  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 +302 -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 +527 -524
  26. data/spec/signet/oauth_2/client_spec.rb +612 -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 +50 -43
  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
@@ -11,121 +11,129 @@
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 'signet/oauth_1/credential'
14
+ require "spec_helper"
15
+ require "signet/oauth_1/credential"
16
16
 
17
- describe Signet::OAuth1::Credential, 'with a Hash for initialization' do
17
+ describe Signet::OAuth1::Credential, "with a Hash for initialization" do
18
18
  it 'should accept "oauth_token" and "oauth_token_secret" pairs' do
19
- token = Signet::OAuth1::Credential.new({
20
- "oauth_token" => "dpf43f3p2l4k3l03",
19
+ token = Signet::OAuth1::Credential.new(
20
+ "oauth_token" => "dpf43f3p2l4k3l03",
21
21
  "oauth_token_secret" => "kd94hf93k423kf44"
22
- })
22
+ )
23
23
  expect(token.key).to eq "dpf43f3p2l4k3l03"
24
24
  expect(token.secret).to eq "kd94hf93k423kf44"
25
25
  end
26
26
 
27
- it 'should accept :oauth_token and :oauth_token_secret pairs' do
28
- token = Signet::OAuth1::Credential.new({
29
- :oauth_token => "dpf43f3p2l4k3l03",
30
- :oauth_token_secret => "kd94hf93k423kf44"
31
- })
27
+ it "should accept :oauth_token and :oauth_token_secret pairs" do
28
+ token = Signet::OAuth1::Credential.new(
29
+ oauth_token: "dpf43f3p2l4k3l03",
30
+ oauth_token_secret: "kd94hf93k423kf44"
31
+ )
32
32
  expect(token.key).to eq "dpf43f3p2l4k3l03"
33
33
  expect(token.secret).to eq "kd94hf93k423kf44"
34
34
  end
35
35
 
36
36
  it 'should accept "key" and "secret" pairs' do
37
- token = Signet::OAuth1::Credential.new({
38
- "key" => "dpf43f3p2l4k3l03",
37
+ token = Signet::OAuth1::Credential.new(
38
+ "key" => "dpf43f3p2l4k3l03",
39
39
  "secret" => "kd94hf93k423kf44"
40
- })
40
+ )
41
41
  expect(token.key).to eq "dpf43f3p2l4k3l03"
42
42
  expect(token.secret).to eq "kd94hf93k423kf44"
43
43
  end
44
44
 
45
- it 'should accept :key and :secret pairs' do
45
+ it "should accept :key and :secret pairs" do
46
46
  token = Signet::OAuth1::Credential.new(
47
- :key => "dpf43f3p2l4k3l03",
48
- :secret => "kd94hf93k423kf44"
47
+ key: "dpf43f3p2l4k3l03",
48
+ secret: "kd94hf93k423kf44"
49
49
  )
50
50
  expect(token.key).to eq "dpf43f3p2l4k3l03"
51
51
  expect(token.secret).to eq "kd94hf93k423kf44"
52
52
  end
53
53
 
54
- it 'should not complain about additional parameters' do
55
- token = Signet::OAuth1::Credential.new({
56
- "oauth_token" => "dpf43f3p2l4k3l03",
54
+ it "should not complain about additional parameters" do
55
+ token = Signet::OAuth1::Credential.new(
56
+ "oauth_token" => "dpf43f3p2l4k3l03",
57
57
  "oauth_token_secret" => "kd94hf93k423kf44",
58
- "oauth_version" => "1.0"
59
- })
58
+ "oauth_version" => "1.0"
59
+ )
60
60
  expect(token.key).to eq "dpf43f3p2l4k3l03"
61
61
  expect(token.secret).to eq "kd94hf93k423kf44"
62
62
  end
63
63
 
64
- it 'should allow parameters to be specified as an implicit Hash' do
64
+ it "should allow parameters to be specified as an implicit Hash" do
65
65
  class ParameterHashSet
66
- def initialize(parameters)
67
- @parameters = parameters.inject({}) { |h,(k,v)| h[k]=v; h }
66
+ def initialize parameters
67
+ @parameters = parameters.each_with_object({}) { |(k, v), h| h[k] = v; }
68
68
  end
69
69
 
70
70
  def to_hash
71
- return @parameters
71
+ @parameters
72
72
  end
73
73
  end
74
74
 
75
- token = Signet::OAuth1::Credential.new(ParameterHashSet.new({
76
- "oauth_token" => "dpf43f3p2l4k3l03",
77
- "oauth_token_secret" => "kd94hf93k423kf44",
78
- "oauth_version" => "1.0"
79
- }))
75
+ token = Signet::OAuth1::Credential.new(
76
+ ParameterHashSet.new(
77
+ "oauth_token" => "dpf43f3p2l4k3l03",
78
+ "oauth_token_secret" => "kd94hf93k423kf44",
79
+ "oauth_version" => "1.0"
80
+ )
81
+ )
80
82
  expect(token.key).to eq "dpf43f3p2l4k3l03"
81
83
  expect(token.secret).to eq "kd94hf93k423kf44"
82
84
  end
83
85
 
84
- it 'should allow parameters to be specified as an Enumerable' do
85
- token = Signet::OAuth1::Credential.new([
86
- ["oauth_token", "dpf43f3p2l4k3l03"],
87
- ["oauth_token_secret", "kd94hf93k423kf44"],
88
- ["oauth_version", "1.0"]
89
- ])
86
+ it "should allow parameters to be specified as an Enumerable" do
87
+ token = Signet::OAuth1::Credential.new(
88
+ [
89
+ %w[oauth_token dpf43f3p2l4k3l03],
90
+ %w[oauth_token_secret kd94hf93k423kf44],
91
+ ["oauth_version", "1.0"]
92
+ ]
93
+ )
90
94
  expect(token.key).to eq "dpf43f3p2l4k3l03"
91
95
  expect(token.secret).to eq "kd94hf93k423kf44"
92
96
  end
93
97
 
94
- it 'should allow parameters to be specified as an implicit Array' do
98
+ it "should allow parameters to be specified as an implicit Array" do
95
99
  class ParameterArraySet
96
- def initialize(parameters)
100
+ def initialize parameters
97
101
  @parameters = parameters
98
102
  end
99
103
 
100
104
  def to_ary
101
- return @parameters
105
+ @parameters
102
106
  end
103
107
  end
104
108
 
105
- token = Signet::OAuth1::Credential.new(ParameterArraySet.new([
106
- ["oauth_token", "dpf43f3p2l4k3l03"],
107
- ["oauth_token_secret", "kd94hf93k423kf44"],
108
- ["oauth_version", "1.0"]
109
- ]))
109
+ token = Signet::OAuth1::Credential.new(
110
+ ParameterArraySet.new(
111
+ [
112
+ %w[oauth_token dpf43f3p2l4k3l03],
113
+ %w[oauth_token_secret kd94hf93k423kf44],
114
+ ["oauth_version", "1.0"]
115
+ ]
116
+ )
117
+ )
110
118
  expect(token.key).to eq "dpf43f3p2l4k3l03"
111
119
  expect(token.secret).to eq "kd94hf93k423kf44"
112
120
  end
113
121
 
114
- it 'should raise an error if key and secret are not present' do
122
+ it "should raise an error if key and secret are not present" do
115
123
  expect(lambda do
116
124
  Signet::OAuth1::Credential.new({})
117
125
  end).to raise_error(ArgumentError)
118
126
  end
119
127
 
120
- it 'should allow key and secret to be passed in as a tuple' do
128
+ it "should allow key and secret to be passed in as a tuple" do
121
129
  token = Signet::OAuth1::Credential.new(
122
- ["dpf43f3p2l4k3l03", "kd94hf93k423kf44"]
130
+ %w[dpf43f3p2l4k3l03 kd94hf93k423kf44]
123
131
  )
124
132
  expect(token.key).to eq "dpf43f3p2l4k3l03"
125
133
  expect(token.secret).to eq "kd94hf93k423kf44"
126
134
  end
127
135
 
128
- it 'should allow key and secret to be passed in as normal parameters' do
136
+ it "should allow key and secret to be passed in as normal parameters" do
129
137
  token = Signet::OAuth1::Credential.new(
130
138
  "dpf43f3p2l4k3l03", "kd94hf93k423kf44"
131
139
  )
@@ -133,16 +141,16 @@ describe Signet::OAuth1::Credential, 'with a Hash for initialization' do
133
141
  expect(token.secret).to eq "kd94hf93k423kf44"
134
142
  end
135
143
 
136
- it 'should raise an error if key or secret are of the wrong type' do
144
+ it "should raise an error if key or secret are of the wrong type" do
137
145
  expect(lambda do
138
- Signet::OAuth1::Credential.new("dpf43f3p2l4k3l03", 42)
146
+ Signet::OAuth1::Credential.new "dpf43f3p2l4k3l03", 42
139
147
  end).to raise_error(TypeError)
140
148
  expect(lambda do
141
- Signet::OAuth1::Credential.new(42, "kd94hf93k423kf44")
149
+ Signet::OAuth1::Credential.new 42, "kd94hf93k423kf44"
142
150
  end).to raise_error(TypeError)
143
151
  end
144
152
 
145
- it 'should raise an error if the wrong number of arguments are passed' do
153
+ it "should raise an error if the wrong number of arguments are passed" do
146
154
  expect(lambda do
147
155
  Signet::OAuth1::Credential.new(
148
156
  "dpf43f3p2l4k3l03", "kd94hf93k423kf44", "something else"
@@ -150,12 +158,12 @@ describe Signet::OAuth1::Credential, 'with a Hash for initialization' do
150
158
  end).to raise_error(ArgumentError)
151
159
  end
152
160
 
153
- it 'should convert to a Hash object' do
161
+ it "should convert to a Hash object" do
154
162
  token = Signet::OAuth1::Credential.new(
155
163
  "dpf43f3p2l4k3l03", "kd94hf93k423kf44"
156
164
  )
157
165
  parameters = token.to_h
158
- expect(parameters['oauth_token']).to eq "dpf43f3p2l4k3l03"
159
- expect(parameters['oauth_token_secret']).to eq "kd94hf93k423kf44"
166
+ expect(parameters["oauth_token"]).to eq "dpf43f3p2l4k3l03"
167
+ expect(parameters["oauth_token_secret"]).to eq "kd94hf93k423kf44"
160
168
  end
161
169
  end
@@ -11,92 +11,91 @@
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 'signet/oauth_1/server'
16
- require 'signet/oauth_1/client'
17
- require 'addressable/uri'
18
- require 'stringio'
14
+ require "spec_helper"
15
+ require "signet/oauth_1/server"
16
+ require "signet/oauth_1/client"
17
+ require "addressable/uri"
18
+ require "stringio"
19
19
 
20
- def merge_body(chunked_body)
20
+ def merge_body chunked_body
21
21
  merged_body = StringIO.new
22
22
  chunked_body.each do |chunk|
23
- merged_body.write(chunk)
23
+ merged_body.write chunk
24
24
  end
25
- return merged_body.string
25
+ merged_body.string
26
26
  end
27
27
 
28
- def make_oauth_signature_header(real_headers={})
29
- [oauth_headers({'oauth_signature' => 'oauth_signature'}.merge(real_headers))]
28
+ def make_oauth_signature_header real_headers = {}
29
+ [oauth_headers({ "oauth_signature" => "oauth_signature" }.merge(real_headers))]
30
30
  end
31
- def make_oauth_token_header(real_headers={})
32
- [oauth_headers({'oauth_token' => 'oauth_token'}.merge(real_headers))]
31
+
32
+ def make_oauth_token_header real_headers = {}
33
+ [oauth_headers({ "oauth_token" => "oauth_token" }.merge(real_headers))]
33
34
  end
34
35
 
35
- def oauth_headers(real_headers={})
36
+ def oauth_headers real_headers = {}
36
37
  headers = {}
37
38
  %w[oauth_consumer_key oauth_timestamp oauth_nonce].each do |key|
38
39
  headers[key] = key
39
40
  end
40
- headers['oauth_signature_method'] = 'HMAC-SHA1'
41
- headers['oauth_version'] = '1.0'
42
- headers.merge!(real_headers)
43
- ['Authorization', ::Signet::OAuth1.generate_authorization_header(headers, nil)]
41
+ headers["oauth_signature_method"] = "HMAC-SHA1"
42
+ headers["oauth_version"] = "1.0"
43
+ headers.merge! real_headers
44
+ ["Authorization", ::Signet::OAuth1.generate_authorization_header(headers, nil)]
44
45
  end
45
46
 
46
- def make_temporary_credential_request(client, callback=nil, uri=nil, realm=nil)
47
+ def make_temporary_credential_request client, callback = nil, uri = nil, realm = nil
47
48
  client.callback = callback if callback
48
- client.temporary_credential_uri = uri || 'http://photos.example.net/initiate'
49
- client.generate_temporary_credential_request(:realm=>realm)
49
+ client.temporary_credential_uri = uri || "http://photos.example.net/initiate"
50
+ client.generate_temporary_credential_request realm: realm
50
51
  end
51
52
 
52
- def make_token_credential_request(client, verifier=nil, realm=nil, uri=nil)
53
- client.token_credential_uri = uri || 'http://photos.example.net/token'
54
- client.generate_token_credential_request(:verifier=>verifier || '12345',
55
- :realm=>realm
56
- )
53
+ def make_token_credential_request client, verifier = nil, realm = nil, uri = nil
54
+ client.token_credential_uri = uri || "http://photos.example.net/token"
55
+ client.generate_token_credential_request(verifier: verifier || "12345",
56
+ realm: realm)
57
57
  end
58
58
 
59
- def make_resource_request(client, real_request={}, realm=nil)
60
-
59
+ def make_resource_request client, real_request = {}, realm = nil
61
60
  client.generate_authenticated_request(
62
- :method => real_request[:method] || 'GET',
63
- :uri => real_request[:uri] || 'http://photos.example.net/photos',
64
- :body=> real_request[:body],
65
- :headers=>real_request[:headers],
66
- :realm=>realm
67
- )
61
+ method: real_request[:method] || "GET",
62
+ uri: real_request[:uri] || "http://photos.example.net/photos",
63
+ body: real_request[:body],
64
+ headers: real_request[:headers],
65
+ realm: realm
66
+ )
68
67
  end
69
68
 
70
69
 
71
- describe Signet::OAuth1::Server, 'unconfigured' do
70
+ describe Signet::OAuth1::Server, "unconfigured" do
72
71
  before do
73
72
  @server = Signet::OAuth1::Server.new
74
73
  end
75
- it 'should not have a client_credential Proc' do
74
+ it "should not have a client_credential Proc" do
76
75
  expect(@server.client_credential).to eq nil
77
76
  end
78
- it 'should not have a token_credential Proc' do
77
+ it "should not have a token_credential Proc" do
79
78
  expect(@server.token_credential).to eq nil
80
79
  end
81
- it 'should not have a nonce_timestamp Proc' do
80
+ it "should not have a nonce_timestamp Proc" do
82
81
  expect(@server.nonce_timestamp).to eq nil
83
82
  end
84
- it 'should not have a verifier Proc' do
83
+ it "should not have a verifier Proc" do
85
84
  expect(@server.verifier).to eq nil
86
85
  end
87
86
  end
88
87
 
89
88
 
90
- describe Signet::OAuth1::Server, 'configured' do
89
+ describe Signet::OAuth1::Server, "configured" do
91
90
  before do
92
91
  @server = Signet::OAuth1::Server.new
93
- @client_credential_key = 'dpf43f3p2l4k3l03'
94
- @client_credential_secret = 'kd94hf93k423kf44'
95
- @token_credential_key = 'nnch734d00sl2jdk'
96
- @token_credential_secret = 'pfkkdhi9sl3r4s00'
97
- @temporary_credential_key = 'hh5s93j4hdidpola'
98
- @temporary_credential_secret = 'hdhd0244k9j7ao03'
99
- @verifier = 'hfdp7dh39dks9884'
92
+ @client_credential_key = "dpf43f3p2l4k3l03"
93
+ @client_credential_secret = "kd94hf93k423kf44"
94
+ @token_credential_key = "nnch734d00sl2jdk"
95
+ @token_credential_secret = "pfkkdhi9sl3r4s00"
96
+ @temporary_credential_key = "hh5s93j4hdidpola"
97
+ @temporary_credential_secret = "hdhd0244k9j7ao03"
98
+ @verifier = "hfdp7dh39dks9884"
100
99
 
101
100
  @server.client_credential =
102
101
  lambda do |x|
@@ -117,10 +116,10 @@ describe Signet::OAuth1::Server, 'configured' do
117
116
  lambda do |nonce, timestamp|
118
117
  !(nonce.nil? && timestamp.nil?)
119
118
  end
120
- @server.verifier = lambda { |x| x == @verifier }
119
+ @server.verifier = ->(x) { x == @verifier }
121
120
  end
122
121
 
123
- it 'should raise an error if the client credential Proc is not set' do
122
+ it "should raise an error if the client credential Proc is not set" do
124
123
  @server.client_credential = nil
125
124
  expect(lambda do
126
125
  @server.authenticate_resource_request
@@ -148,96 +147,98 @@ describe Signet::OAuth1::Server, 'configured' do
148
147
  end).to raise_error(ArgumentError)
149
148
  end
150
149
 
151
- it 'should raise an error if no request is provided' do
150
+ it "should raise an error if no request is provided" do
152
151
  expect(lambda do
153
152
  @server.authenticate_resource_request
154
153
  end).to raise_error(ArgumentError)
155
154
  end
156
155
 
157
- it 'should raise an error if a bogus request is provided' do
156
+ it "should raise an error if a bogus request is provided" do
158
157
  expect(lambda do
159
158
  @server.authenticate_resource_request(
160
- :request => []
159
+ request: []
161
160
  )
162
161
  end).to raise_error(ArgumentError)
163
162
  end
164
163
 
165
- it 'should raise an error if no Authentication header is provided' do
164
+ it "should raise an error if no Authentication header is provided" do
166
165
  expect(lambda do
167
166
  @server.authenticate_resource_request(
168
- :method => 'GET',
169
- :uri => 'https://photos.example.net/photos',
170
- :headers => [['Authorization', '']],
171
- :body => ''
167
+ method: "GET",
168
+ uri: "https://photos.example.net/photos",
169
+ headers: [["Authorization", ""]],
170
+ body: ""
172
171
  )
173
172
  end).to raise_error(Signet::MalformedAuthorizationError)
174
173
  end
175
174
 
176
- it 'should raise an error if no URI is provided' do
175
+ it "should raise an error if no URI is provided" do
177
176
  expect(lambda do
178
177
  @server.authenticate_resource_request(
179
- :method => 'GET',
180
- :headers => [],
181
- :body => ''
178
+ method: "GET",
179
+ headers: [],
180
+ body: ""
182
181
  )
183
182
  end).to raise_error(ArgumentError)
184
183
  end
185
184
 
186
- it 'should reject a request with the wrong signature method' do
187
- bad_method = 'FOO'
185
+ it "should reject a request with the wrong signature method" do
186
+ bad_method = "FOO"
188
187
  expect(lambda do
189
188
  @server.authenticate_resource_request(
190
- :method => 'GET',
191
- :uri => 'http://photos.example.net/photos',
192
- :headers=>make_oauth_token_header({'oauth_signature_method'=>bad_method})
189
+ method: "GET",
190
+ uri: "http://photos.example.net/photos",
191
+ headers: make_oauth_token_header("oauth_signature_method"=>bad_method)
193
192
  )
194
193
  end).to raise_error(NotImplementedError,
195
- "Unsupported signature method: #{bad_method}"
196
- )
194
+ "Unsupported signature method: #{bad_method}")
197
195
  end
198
196
 
199
197
 
200
- describe 'calling find_temporary_credential' do
201
- it 'should return a Signet credential if the Proc provides one' do
198
+ describe "calling find_temporary_credential" do
199
+ it "should return a Signet credential if the Proc provides one" do
202
200
  @server.temporary_credential =
203
201
  lambda do |x|
204
202
  x.nil? ? nil : Signet::OAuth1::Credential.new(
205
- @temporary_credential_key, @temporary_credential_secret
206
- )
203
+ @temporary_credential_key, @temporary_credential_secret
204
+ )
207
205
  end
208
206
  expect(@server.find_temporary_credential(@temporary_credential_key)).to eq(
209
207
  Signet::OAuth1::Credential.new(@temporary_credential_key,
210
- @temporary_credential_secret))
208
+ @temporary_credential_secret)
209
+ )
211
210
  end
212
- it 'should return a Signet credential if the Proc provides a key/secret pair' do
211
+ it "should return a Signet credential if the Proc provides a key/secret pair" do
213
212
  @server.temporary_credential =
214
- lambda do |x|
215
- {:key=>@temporary_credential_key, :secret=>@temporary_credential_secret}
213
+ lambda do |_x|
214
+ { key: @temporary_credential_key, secret: @temporary_credential_secret }
216
215
  end
217
216
  expect(@server.find_temporary_credential(@temporary_credential_key)).to eq(
218
217
  Signet::OAuth1::Credential.new(@temporary_credential_key,
219
- @temporary_credential_secret))
218
+ @temporary_credential_secret)
219
+ )
220
220
  end
221
- it 'should return a Signet credential if the Proc provides ' +
222
- 'a key/secret Enumerable' do
221
+ it "should return a Signet credential if the Proc provides " \
222
+ "a key/secret Enumerable" do
223
223
  @server.temporary_credential =
224
- lambda do |x|
224
+ lambda do |_x|
225
225
  [@temporary_credential_key, @temporary_credential_secret]
226
226
  end
227
227
  expect(@server.find_temporary_credential(@temporary_credential_key)).to eq(
228
228
  Signet::OAuth1::Credential.new(@temporary_credential_key,
229
- @temporary_credential_secret))
229
+ @temporary_credential_secret)
230
+ )
230
231
  end
231
232
 
232
- it 'should return nil if the Proc does not provide a usable response' do
233
- @server.temporary_credential = lambda {|x| nil }
233
+ it "should return nil if the Proc does not provide a usable response" do
234
+ @server.temporary_credential = ->(_x) { nil }
234
235
  expect(@server.find_temporary_credential(@temporary_credential_key)).to eq nil
235
236
  end
236
237
  end
237
238
 
238
239
 
239
- describe 'calling find_client_credential' do
240
- it 'should return a Signet credential if the Proc provides one' do
240
+ describe "calling find_client_credential" do
241
+ it "should return a Signet credential if the Proc provides one" do
241
242
  @server.client_credential =
242
243
  lambda do |x|
243
244
  x.nil? ? nil : Signet::OAuth1::Credential.new(@client_credential_key,
@@ -245,37 +246,40 @@ describe Signet::OAuth1::Server, 'configured' do
245
246
  end
246
247
  expect(@server.find_client_credential(@client_credential_key)).to eq(
247
248
  Signet::OAuth1::Credential.new(@client_credential_key,
248
- @client_credential_secret))
249
+ @client_credential_secret)
250
+ )
249
251
  end
250
- it 'should return a Signet credential if the Proc provides a key/secret pair' do
252
+ it "should return a Signet credential if the Proc provides a key/secret pair" do
251
253
  @server.client_credential =
252
- lambda do |x|
253
- {:key=>@client_credential_key, :secret=>@client_credential_secret}
254
+ lambda do |_x|
255
+ { key: @client_credential_key, secret: @client_credential_secret }
254
256
  end
255
257
  expect(@server.find_client_credential(@client_credential_key)).to eq(
256
258
  Signet::OAuth1::Credential.new(@client_credential_key,
257
- @client_credential_secret))
259
+ @client_credential_secret)
260
+ )
258
261
  end
259
- it 'should return a Signet credential if the Proc provides ' +
260
- 'a key/secret Enumerable' do
262
+ it "should return a Signet credential if the Proc provides " \
263
+ "a key/secret Enumerable" do
261
264
  @server.client_credential =
262
- lambda do |x|
265
+ lambda do |_x|
263
266
  [@client_credential_key, @client_credential_secret]
264
267
  end
265
268
  expect(@server.find_client_credential(@client_credential_key)).to eq(
266
269
  Signet::OAuth1::Credential.new(@client_credential_key,
267
- @client_credential_secret))
270
+ @client_credential_secret)
271
+ )
268
272
  end
269
273
 
270
- it 'should return nil if the Proc does not provide a usable response' do
271
- @server.client_credential = lambda {|x| nil }
274
+ it "should return nil if the Proc does not provide a usable response" do
275
+ @server.client_credential = ->(_x) { nil }
272
276
  expect(@server.find_client_credential(@client_credential_key)).to be_nil
273
277
  end
274
278
  end
275
279
 
276
280
 
277
- describe 'calling find_token_credential' do
278
- it 'should return a Signet credential if the Proc provides one' do
281
+ describe "calling find_token_credential" do
282
+ it "should return a Signet credential if the Proc provides one" do
279
283
  @server.token_credential =
280
284
  lambda do |x|
281
285
  x.nil? ? nil : Signet::OAuth1::Credential.new(@token_credential_key,
@@ -283,557 +287,553 @@ describe Signet::OAuth1::Server, 'configured' do
283
287
  end
284
288
  expect(@server.find_token_credential(@token_credential_key)).to eq(
285
289
  Signet::OAuth1::Credential.new(@token_credential_key,
286
- @token_credential_secret))
290
+ @token_credential_secret)
291
+ )
287
292
  end
288
293
 
289
- it 'should return a Signet credential if the Proc provides a key/secret pair' do
294
+ it "should return a Signet credential if the Proc provides a key/secret pair" do
290
295
  @server.token_credential =
291
- lambda do |x|
292
- {:key=>@token_credential_key, :secret=>@token_credential_secret}
296
+ lambda do |_x|
297
+ { key: @token_credential_key, secret: @token_credential_secret }
293
298
  end
294
299
  expect(@server.find_token_credential(@token_credential_key)).to eq(
295
300
  Signet::OAuth1::Credential.new(@token_credential_key,
296
- @token_credential_secret))
301
+ @token_credential_secret)
302
+ )
297
303
  end
298
304
 
299
- it 'should return a Signet credential if the Proc provides ' +
300
- 'a key/secret Enumerable' do
305
+ it "should return a Signet credential if the Proc provides " \
306
+ "a key/secret Enumerable" do
301
307
  @server.token_credential =
302
- lambda do |x|
308
+ lambda do |_x|
303
309
  [@token_credential_key, @token_credential_secret]
304
310
  end
305
311
  expect(@server.find_token_credential(@token_credential_key)).to eq(
306
312
  Signet::OAuth1::Credential.new(@token_credential_key,
307
- @token_credential_secret))
313
+ @token_credential_secret)
314
+ )
308
315
  end
309
316
 
310
- it 'should return nil if the Proc does not provide a usable response' do
311
- @server.token_credential = lambda {|x| nil }
317
+ it "should return nil if the Proc does not provide a usable response" do
318
+ @server.token_credential = ->(_x) { nil }
312
319
  expect(@server.find_token_credential(@token_credential_key)).to be_nil
313
320
  end
314
321
  end
315
322
 
316
323
 
317
- describe 'calling find_verifier' do
318
- it 'should return false if server verifier returns false' do
319
- @server.verifier = lambda {|x| false }
324
+ describe "calling find_verifier" do
325
+ it "should return false if server verifier returns false" do
326
+ @server.verifier = ->(_x) { false }
320
327
  expect(@server.find_verifier(@verifier)).to eq false
321
328
  end
322
- it 'should return false if server verifier returns nil' do
323
- @server.verifier = lambda {|x| nil }
329
+ it "should return false if server verifier returns nil" do
330
+ @server.verifier = ->(_x) { nil }
324
331
  expect(@server.find_verifier(@verifier)).to eq false
325
332
  end
326
- it 'should return true if server verifier returns a random object' do
327
- @server.verifier = lambda {|x| x.succ}
333
+ it "should return true if server verifier returns a random object" do
334
+ @server.verifier = ->(x) { x.succ }
328
335
  expect(@server.find_verifier(@verifier)).to eq true
329
336
  end
330
337
  end
331
338
 
332
- describe 'calling validate_nonce_timestamp' do
333
- it 'should return false if nonce_timestamp Proc returns false' do
334
- @server.nonce_timestamp = lambda {|n,t| false}
335
- expect(@server.validate_nonce_timestamp('nonce', 'timestamp')).to be false
339
+ describe "calling validate_nonce_timestamp" do
340
+ it "should return false if nonce_timestamp Proc returns false" do
341
+ @server.nonce_timestamp = ->(_n, _t) { false }
342
+ expect(@server.validate_nonce_timestamp("nonce", "timestamp")).to be false
336
343
  end
337
- it 'should return false if nonce_timestamp Proc returns nil' do
338
- @server.nonce_timestamp = lambda {|n,t| nil}
339
- expect(@server.validate_nonce_timestamp('nonce', 'timestamp')).to be false
344
+ it "should return false if nonce_timestamp Proc returns nil" do
345
+ @server.nonce_timestamp = ->(_n, _t) { nil }
346
+ expect(@server.validate_nonce_timestamp("nonce", "timestamp")).to be false
340
347
  end
341
- it 'should return true if nonce_timestamp Proc returns a random object' do
342
- @server.nonce_timestamp = lambda {|n,t| n+t.to_s}
343
- expect(@server.validate_nonce_timestamp('nonce', 'timestamp')).to be true
348
+ it "should return true if nonce_timestamp Proc returns a random object" do
349
+ @server.nonce_timestamp = ->(n, t) { n + t.to_s }
350
+ expect(@server.validate_nonce_timestamp("nonce", "timestamp")).to be true
344
351
  end
345
352
  end
346
353
 
347
354
 
348
- describe 'expecting a request for a temporary credential' do
355
+ describe "expecting a request for a temporary credential" do
349
356
  before do
350
357
  @client = Signet::OAuth1::Client.new(
351
- :client_credential_key=>@client_credential_key,
352
- :client_credential_secret=>@client_credential_secret,
353
- :temporary_credential_uri=>
354
- 'http://photos.example.net/initiate')
358
+ client_credential_key: @client_credential_key,
359
+ client_credential_secret: @client_credential_secret,
360
+ temporary_credential_uri: "http://photos.example.net/initiate"
361
+ )
355
362
  end
356
363
 
357
- it 'should raise an error if the client credential Proc is not set' do
364
+ it "should raise an error if the client credential Proc is not set" do
358
365
  @server.client_credential = nil
359
366
  expect(lambda do
360
367
  @server.authenticate_temporary_credential_request(
361
- :request=>make_temporary_credential_request(@client)
368
+ request: make_temporary_credential_request(@client)
362
369
  )
363
370
  end).to raise_error(ArgumentError)
364
371
  end
365
- it 'should reject an malformed request' do
366
- bad_request = make_temporary_credential_request(@client, nil, 'https://photos.example.net/photos')
367
- bad_request.headers['Authorization'].gsub!(/(OAuth)(.+)/, "#{$1}")
372
+ it "should reject an malformed request" do
373
+ bad_request = make_temporary_credential_request @client, nil, "https://photos.example.net/photos"
374
+ bad_request.headers["Authorization"].gsub!(/(OAuth)(.+)/, (Regexp.last_match 1).to_s)
368
375
  expect(lambda do
369
376
  @server.authenticate_temporary_credential_request(
370
- :request=>bad_request
377
+ request: bad_request
371
378
  )
372
379
  end).to raise_error(Signet::MalformedAuthorizationError)
373
380
  end
374
381
 
375
- it 'should call a user-supplied Proc to validate a nonce/timestamp pair' do
376
- nonce_callback = double('nonce')
377
- expect(nonce_callback).to receive(:call).once.with(an_instance_of(String),
378
- an_instance_of(String)
379
- ).and_return(true)
382
+ it "should call a user-supplied Proc to validate a nonce/timestamp pair" do
383
+ nonce_callback = double "nonce"
384
+ expect(nonce_callback).to receive(:call).once.with(
385
+ an_instance_of(String), an_instance_of(String)
386
+ ).and_return(true)
380
387
 
381
388
  @server.nonce_timestamp = nonce_callback
382
389
  @server.authenticate_temporary_credential_request(
383
- :request=>make_temporary_credential_request(@client)
390
+ request: make_temporary_credential_request(@client)
384
391
  )
385
392
  end
386
393
 
387
394
  it "should return 'oob' for a valid request without an oauth_callback" do
388
- bad_request = make_temporary_credential_request(@client)
395
+ bad_request = make_temporary_credential_request @client
389
396
  expect(@server.authenticate_temporary_credential_request(
390
- :request=>bad_request
391
- )).to eq 'oob'
397
+ request: bad_request
398
+ )).to eq "oob"
392
399
  end
393
- it 'should return the oauth_callback for a valid request ' +
394
- 'with an oauth_callback' do
395
- callback = 'http://printer.example.com/ready'
400
+ it "should return the oauth_callback for a valid request " \
401
+ "with an oauth_callback" do
402
+ callback = "http://printer.example.com/ready"
396
403
  expect(@server.authenticate_temporary_credential_request(
397
- :request=>make_temporary_credential_request(@client, callback)
398
- )).to eq callback
404
+ request: make_temporary_credential_request(@client, callback)
405
+ )).to eq callback
399
406
  end
400
- it 'should return false for an unauthenticated request' do
401
- bad_request = make_temporary_credential_request(@client)
407
+ it "should return false for an unauthenticated request" do
408
+ bad_request = make_temporary_credential_request @client
402
409
  bad_request.headers["Authorization"].gsub!(/oauth_signature=\".+\"/,
403
- "oauth_signature=\"foobar\"")
410
+ "oauth_signature=\"foobar\"")
404
411
  expect(@server.authenticate_temporary_credential_request(
405
- :request=>bad_request
406
- )).to eq false
412
+ request: bad_request
413
+ )).to eq false
407
414
  end
408
- it 'should return nil from #request_realm if no realm is provided' do
409
- req = make_temporary_credential_request(@client)
415
+ it "should return nil from #request_realm if no realm is provided" do
416
+ req = make_temporary_credential_request @client
410
417
  expect(@server.request_realm(
411
- :request=>req
412
- )).to eq nil
418
+ request: req
419
+ )).to eq nil
413
420
  end
414
421
 
415
- describe 'with a Realm provided' do
416
- it 'should return the realm from #request_realm' do
417
- req = make_temporary_credential_request(@client, nil, nil, 'Photos')
422
+ describe "with a Realm provided" do
423
+ it "should return the realm from #request_realm" do
424
+ req = make_temporary_credential_request @client, nil, nil, "Photos"
418
425
  expect(@server.request_realm(
419
- :request=>req
420
- )).to eq 'Photos'
426
+ request: req
427
+ )).to eq "Photos"
421
428
  end
422
429
  it 'should return "oob" with a valid request without an oauth_callback' do
423
- req = make_temporary_credential_request(@client, nil, nil, 'Photos')
430
+ req = make_temporary_credential_request @client, nil, nil, "Photos"
424
431
  expect(@server.authenticate_temporary_credential_request(
425
- :request=>req
426
- )).to eq 'oob'
432
+ request: req
433
+ )).to eq "oob"
427
434
  end
428
435
  end
429
-
430
436
  end
431
437
 
432
438
 
433
- describe 'expecting a request for a token credential' do
439
+ describe "expecting a request for a token credential" do
434
440
  before do
435
441
  @client = Signet::OAuth1::Client.new(
436
- :client_credential_key=>@client_credential_key,
437
- :client_credential_secret=>@client_credential_secret,
438
- :temporary_credential_key=>@temporary_credential_key,
439
- :temporary_credential_secret=>@temporary_credential_secret,
440
- :token_credential_uri=>'http://photos.example.net/token'
441
- )
442
- @return_hash = {:client_credential=>Signet::OAuth1::Credential.new(@client_credential_key, @client_credential_secret),
443
- :temporary_credential=>Signet::OAuth1::Credential.new(@temporary_credential_key, @temporary_credential_secret),
444
- :realm=>nil
445
- }
446
- end
447
-
448
- it 'should reject an malformed request' do
449
- bad_request = make_token_credential_request(@client)
450
- bad_request.headers["Authorization"].gsub!(/(OAuth)(.+)/, "#{$1}")
442
+ client_credential_key: @client_credential_key,
443
+ client_credential_secret: @client_credential_secret,
444
+ temporary_credential_key: @temporary_credential_key,
445
+ temporary_credential_secret: @temporary_credential_secret,
446
+ token_credential_uri: "http://photos.example.net/token"
447
+ )
448
+ @return_hash = { client_credential: Signet::OAuth1::Credential.new(@client_credential_key, @client_credential_secret),
449
+ temporary_credential: Signet::OAuth1::Credential.new(@temporary_credential_key, @temporary_credential_secret),
450
+ realm: nil }
451
+ end
452
+
453
+ it "should reject an malformed request" do
454
+ bad_request = make_token_credential_request @client
455
+ bad_request.headers["Authorization"].gsub!(/(OAuth)(.+)/, (Regexp.last_match 1).to_s)
451
456
 
452
457
  expect(lambda do
453
458
  @server.authenticate_token_credential_request(
454
- :request=>bad_request
459
+ request: bad_request
455
460
  )
456
461
  end).to raise_error(Signet::MalformedAuthorizationError)
457
462
  end
458
- it 'should call a user-supplied Proc to validate a nonce/timestamp pair' do
459
- nonce_callback = double('nonce')
463
+ it "should call a user-supplied Proc to validate a nonce/timestamp pair" do
464
+ nonce_callback = double "nonce"
460
465
  expect(nonce_callback).to receive(:call).once.with(
461
466
  an_instance_of(String), an_instance_of(String)
462
467
  ).and_return(true)
463
468
  @server.nonce_timestamp = nonce_callback
464
469
  @server.authenticate_token_credential_request(
465
- :request=>make_token_credential_request(@client)
470
+ request: make_token_credential_request(@client)
466
471
  )
467
472
  end
468
- it 'should return an informational hash for a valid request' do
473
+ it "should return an informational hash for a valid request" do
469
474
  expect(@server.authenticate_token_credential_request(
470
- :request=>make_token_credential_request(@client)
471
- )).to eq @return_hash
475
+ request: make_token_credential_request(@client)
476
+ )).to eq @return_hash
472
477
  end
473
- it 'should return nil for an unauthenticated request' do
474
- bad_request = make_token_credential_request(@client)
478
+ it "should return nil for an unauthenticated request" do
479
+ bad_request = make_token_credential_request @client
475
480
  bad_request.headers["Authorization"].gsub!(/oauth_signature=\".+\"/,
476
- "oauth_signature=\"foobar\"")
481
+ "oauth_signature=\"foobar\"")
477
482
  expect(@server.authenticate_token_credential_request(
478
- :request=>bad_request
479
- )).to eq nil
483
+ request: bad_request
484
+ )).to eq nil
480
485
  end
481
- it 'should call a user-supplied Proc to fetch the client credential' do
486
+ it "should call a user-supplied Proc to fetch the client credential" do
482
487
  client_cred = Signet::OAuth1::Credential.new(@client_credential_key,
483
- @client_credential_secret )
484
- key_callback = double('client_cred')
488
+ @client_credential_secret)
489
+ key_callback = double "client_cred"
485
490
  expect(key_callback).to receive(:call).at_least(:once).with(
486
491
  @client_credential_key
487
492
  ).and_return(client_cred)
488
493
 
489
494
  @server.client_credential = key_callback
490
495
  @server.authenticate_token_credential_request(
491
- :request=>make_token_credential_request(@client)
496
+ request: make_token_credential_request(@client)
492
497
  )
493
498
  end
494
499
 
495
- it 'should call a user-supplied Proc to fetch the temporary token credential' do
500
+ it "should call a user-supplied Proc to fetch the temporary token credential" do
496
501
  temp_cred = Signet::OAuth1::Credential.new(@temporary_credential_key,
497
502
  @temporary_credential_secret)
498
- temp_callback = double('temp_cred')
503
+ temp_callback = double "temp_cred"
499
504
  expect(temp_callback).to receive(:call).at_least(:once).with(
500
505
  @temporary_credential_key
501
506
  ).and_return(temp_cred)
502
507
 
503
508
  @server.temporary_credential = temp_callback
504
509
  @server.authenticate_token_credential_request(
505
- :request=>make_token_credential_request(@client)
510
+ request: make_token_credential_request(@client)
506
511
  )
507
512
  end
508
- it 'should return nil from #request_realm if no realm is provided' do
509
- req = make_token_credential_request(@client)
513
+ it "should return nil from #request_realm if no realm is provided" do
514
+ req = make_token_credential_request @client
510
515
  expect(@server.request_realm(
511
- :request=>req
512
- )).to eq nil
516
+ request: req
517
+ )).to eq nil
513
518
  end
514
519
 
515
- describe 'with a Realm provided' do
520
+ describe "with a Realm provided" do
516
521
  before do
517
- @realm = 'Photos'
522
+ @realm = "Photos"
518
523
  @return_hash[:realm] = @realm
519
524
  end
520
- it 'should return the realm from #request_realm' do
521
- req = make_token_credential_request(@client, nil, @realm)
525
+ it "should return the realm from #request_realm" do
526
+ req = make_token_credential_request @client, nil, @realm
522
527
  expect(@server.request_realm(
523
- :request=>req
524
- )).to eq @realm
528
+ request: req
529
+ )).to eq @realm
525
530
  end
526
- it 'should an informational hash with a valid request' do
527
- req = make_token_credential_request(@client, nil, @realm)
531
+ it "should an informational hash with a valid request" do
532
+ req = make_token_credential_request @client, nil, @realm
528
533
  expect(@server.authenticate_token_credential_request(
529
- :request=>req
530
- )).to eq @return_hash
534
+ request: req
535
+ )).to eq @return_hash
531
536
  end
532
537
  end
533
-
534
538
  end
535
539
 
536
540
 
537
- describe 'expecting a request for a protected resource' do
538
- before(:each) do
541
+ describe "expecting a request for a protected resource" do
542
+ before :each do
539
543
  @client = Signet::OAuth1::Client.new(
540
- :client_credential_key=>@client_credential_key,
541
- :client_credential_secret=>@client_credential_secret,
542
- :token_credential_key=>@token_credential_key,
543
- :token_credential_secret=>@token_credential_secret
544
- )
545
- @return_hash = {:client_credential=>Signet::OAuth1::Credential.new(@client_credential_key, @client_credential_secret),
546
- :token_credential=>Signet::OAuth1::Credential.new(@token_credential_key, @token_credential_secret),
547
- :realm=>nil
548
- }
549
- end
550
-
551
- it 'should not raise an error if a request body is chunked(as Array)' do
544
+ client_credential_key: @client_credential_key,
545
+ client_credential_secret: @client_credential_secret,
546
+ token_credential_key: @token_credential_key,
547
+ token_credential_secret: @token_credential_secret
548
+ )
549
+ @return_hash = { client_credential: Signet::OAuth1::Credential.new(@client_credential_key, @client_credential_secret),
550
+ token_credential: Signet::OAuth1::Credential.new(@token_credential_key, @token_credential_secret),
551
+ realm: nil }
552
+ end
553
+
554
+ it "should not raise an error if a request body is chunked(as Array)" do
552
555
  approved = @server.authenticate_resource_request(
553
- :method => 'POST',
554
- :uri => 'https://photos.example.net/photos',
555
- :body => ['A chunked body.'],
556
- :headers => make_oauth_signature_header
556
+ method: "POST",
557
+ uri: "https://photos.example.net/photos",
558
+ body: ["A chunked body."],
559
+ headers: make_oauth_signature_header
557
560
  )
558
561
  expect(approved).to eq nil
559
562
  end
560
563
 
561
- it 'should not raise an error if a request body is chunked(as StringIO)' do
564
+ it "should not raise an error if a request body is chunked(as StringIO)" do
562
565
  chunked_body = StringIO.new
563
- chunked_body.write('A chunked body.')
566
+ chunked_body.write "A chunked body."
564
567
  chunked_body.rewind
565
568
  approved = @server.authenticate_resource_request(
566
- :method => 'POST',
567
- :uri => 'https://photos.example.net/photos',
568
- :body => chunked_body,
569
- :headers => make_oauth_signature_header
569
+ method: "POST",
570
+ uri: "https://photos.example.net/photos",
571
+ body: chunked_body,
572
+ headers: make_oauth_signature_header
570
573
  )
571
574
  expect(approved).to eq nil
572
575
  end
573
576
 
574
- it 'should raise an error if a request body is of a bogus type' do
577
+ it "should raise an error if a request body is of a bogus type" do
575
578
  expect(lambda do
576
579
  @server.authenticate_resource_request(
577
- :method => 'POST',
578
- :uri => 'https://photos.example.net/photos',
579
- :body => 42,
580
- :headers => make_oauth_signature_header
580
+ method: "POST",
581
+ uri: "https://photos.example.net/photos",
582
+ body: 42,
583
+ headers: make_oauth_signature_header
581
584
  )
582
585
  end).to raise_error(TypeError)
583
586
  end
584
- it 'should use form parameters in signature if request is a POSTed form' do
587
+ it "should use form parameters in signature if request is a POSTed form" do
585
588
  req = make_resource_request(
586
589
  @client,
587
- {:method=>'POST',
588
- :headers=>{'Content-Type'=>'application/x-www-form-urlencoded'},
589
- :body=>'c2&a3=2+q'})
590
- expect(@server.authenticate_resource_request(:request=>req)).to eq @return_hash
590
+ method: "POST",
591
+ headers: { "Content-Type"=>"application/x-www-form-urlencoded" },
592
+ body: "c2&a3=2+q"
593
+ )
594
+ expect(@server.authenticate_resource_request(request: req)).to eq @return_hash
591
595
  end
592
- it 'should raise an error if signature is x-www-form-encoded ' +
593
- 'but does not send form parameters in header' do
596
+ it "should raise an error if signature is x-www-form-encoded " \
597
+ "but does not send form parameters in header" do
594
598
 
595
599
  # Make a full request so that we can sign against the form parameters
596
600
  # that will be removed.
597
601
  req = make_resource_request(
598
602
  @client,
599
- {:method=>'POST',
600
- :headers=>{'Content-Type'=>'application/x-www-form-urlencoded'},
601
- :body=>'c2&a3=2+q'})
603
+ method: "POST",
604
+ headers: { "Content-Type"=>"application/x-www-form-urlencoded" },
605
+ body: "c2&a3=2+q"
606
+ )
602
607
 
603
- req.headers["Authorization"].gsub!(/c2=\"\", a3=\"2%20q\", /, '')
608
+ req.headers["Authorization"].gsub!(/c2=\"\", a3=\"2%20q\", /, "")
604
609
 
605
610
  expect(lambda do
606
- @server.authenticate_resource_request(:request=>req)
611
+ @server.authenticate_resource_request request: req
607
612
  end).to raise_error(Signet::MalformedAuthorizationError,
608
- 'Request is of type application/x-www-form-urlencoded but ' +
609
- 'Authentication header did not include form values'
610
- )
613
+ "Request is of type application/x-www-form-urlencoded but " \
614
+ "Authentication header did not include form values")
611
615
  end
612
616
 
613
- it 'should call a user-supplied Proc to validate a nonce/timestamp pair' do
614
- nonce_callback = double('nonce')
617
+ it "should call a user-supplied Proc to validate a nonce/timestamp pair" do
618
+ nonce_callback = double "nonce"
615
619
  expect(nonce_callback).to receive(:call).once.with(
616
620
  an_instance_of(String), an_instance_of(String)
617
621
  ).and_return(true)
618
622
 
619
623
  @server.nonce_timestamp = nonce_callback
620
624
  @server.authenticate_resource_request(
621
- :request=>make_resource_request(@client)
625
+ request: make_resource_request(@client)
622
626
  )
623
627
  end
624
628
 
625
- it 'should call a user-supplied Proc to fetch the client credential' do
629
+ it "should call a user-supplied Proc to fetch the client credential" do
626
630
  client_cred = Signet::OAuth1::Credential.new(@client_credential_key,
627
- @client_credential_secret )
628
- key_callback = double('client_cred' )
631
+ @client_credential_secret)
632
+ key_callback = double "client_cred"
629
633
  expect(key_callback).to receive(:call).at_least(:once).with(
630
634
  @client_credential_key
631
635
  ).and_return(client_cred)
632
636
 
633
637
  @server.client_credential = key_callback
634
638
  @server.authenticate_resource_request(
635
- :request=>make_resource_request(@client)
639
+ request: make_resource_request(@client)
636
640
  )
637
641
  end
638
642
 
639
- it 'should call a user-supplied Proc to fetch the token credential' do
643
+ it "should call a user-supplied Proc to fetch the token credential" do
640
644
  token_cred = Signet::OAuth1::Credential.new(@token_credential_key,
641
645
  @token_credential_secret)
642
- key_callback = double('token_cred' )
646
+ key_callback = double "token_cred"
643
647
  expect(key_callback).to receive(:call).at_least(:once).with(
644
648
  @token_credential_key
645
649
  ).and_return(token_cred)
646
650
 
647
651
  @server.token_credential = key_callback
648
652
  @server.authenticate_resource_request(
649
- :request=>make_resource_request(@client)
653
+ request: make_resource_request(@client)
650
654
  )
651
655
  end
652
656
 
653
- it 'should return a Hash for a valid request' do
657
+ it "should return a Hash for a valid request" do
654
658
  expect(@server.authenticate_resource_request(
655
- :request=>make_resource_request(@client)
656
- )).to eq @return_hash
659
+ request: make_resource_request(@client)
660
+ )).to eq @return_hash
657
661
  end
658
- it 'should return nil for a unauthenticated request' do
659
- bad_request = make_resource_request(@client)
662
+ it "should return nil for a unauthenticated request" do
663
+ bad_request = make_resource_request @client
660
664
  bad_request.headers["Authorization"].gsub!(/oauth_signature=\".+\"/,
661
- "oauth_signature=\"foobar\"")
662
- expect(@server.authenticate_resource_request(:request=>bad_request)).to eq nil
665
+ "oauth_signature=\"foobar\"")
666
+ expect(@server.authenticate_resource_request(request: bad_request)).to eq nil
663
667
  end
664
- it 'should return nil from #request_realm if no realm is provided' do
665
- req = make_resource_request(@client)
668
+ it "should return nil from #request_realm if no realm is provided" do
669
+ req = make_resource_request @client
666
670
  expect(@server.request_realm(
667
- :request=>req
668
- )).to eq nil
671
+ request: req
672
+ )).to eq nil
669
673
  end
670
674
 
671
- describe 'with a Realm provided' do
675
+ describe "with a Realm provided" do
672
676
  before do
673
- @realm = 'Photos'
677
+ @realm = "Photos"
674
678
  @return_hash[:realm] = @realm
675
679
  end
676
- it 'should return the realm from #request_realm' do
680
+ it "should return the realm from #request_realm" do
677
681
  req = make_resource_request(@client, {}, @realm)
678
682
  expect(@server.request_realm(
679
- :request=>req
680
- )).to eq @realm
683
+ request: req
684
+ )).to eq @realm
681
685
  end
682
- it 'should return a hash containing the realm with a valid request' do
686
+ it "should return a hash containing the realm with a valid request" do
683
687
  req = make_resource_request(@client, {}, @realm)
684
688
  expect(@server.authenticate_resource_request(
685
- :request=>req
686
- )).to eq @return_hash
689
+ request: req
690
+ )).to eq @return_hash
687
691
  end
688
692
  end
689
-
690
693
  end
691
694
 
692
695
 
693
696
  describe "expecting a two-legged request for a protected resource" do
694
697
  before do
695
698
  @client = Signet::OAuth1::Client.new(
696
- :client_credential_key=>@client_credential_key,
697
- :client_credential_secret=>@client_credential_secret,
698
- :two_legged=>true)
699
+ client_credential_key: @client_credential_key,
700
+ client_credential_secret: @client_credential_secret,
701
+ two_legged: true
702
+ )
699
703
 
700
- @return_hash = {:client_credential=>Signet::OAuth1::Credential.new(@client_credential_key, @client_credential_secret),
701
- :token_credential=>nil,
702
- :realm=>nil
703
- }
704
+ @return_hash = { client_credential: Signet::OAuth1::Credential.new(@client_credential_key, @client_credential_secret),
705
+ token_credential: nil,
706
+ realm: nil }
704
707
  end
705
- it 'should not raise an error if a request body is chunked(as Array)' do
708
+ it "should not raise an error if a request body is chunked(as Array)" do
706
709
  approved = @server.authenticate_resource_request(
707
- :method => 'POST',
708
- :uri => 'https://photos.example.net/photos',
709
- :body => ['A chunked body.'],
710
- :headers => make_oauth_signature_header,
711
- :two_legged=>true
710
+ method: "POST",
711
+ uri: "https://photos.example.net/photos",
712
+ body: ["A chunked body."],
713
+ headers: make_oauth_signature_header,
714
+ two_legged: true
712
715
  )
713
716
  expect(approved).to eq nil
714
717
  end
715
718
 
716
- it 'should not raise an error if a request body is chunked(as StringIO)' do
719
+ it "should not raise an error if a request body is chunked(as StringIO)" do
717
720
  chunked_body = StringIO.new
718
- chunked_body.write('A chunked body.')
721
+ chunked_body.write "A chunked body."
719
722
  chunked_body.rewind
720
723
  approved = @server.authenticate_resource_request(
721
- :method => 'POST',
722
- :uri => 'https://photos.example.net/photos',
723
- :body => chunked_body,
724
- :headers => make_oauth_signature_header,
725
- :two_legged=>true
724
+ method: "POST",
725
+ uri: "https://photos.example.net/photos",
726
+ body: chunked_body,
727
+ headers: make_oauth_signature_header,
728
+ two_legged: true
726
729
  )
727
730
  expect(approved).to eq nil
728
731
  end
729
732
 
730
- it 'should raise an error if a request body is of a bogus type' do
733
+ it "should raise an error if a request body is of a bogus type" do
731
734
  expect(lambda do
732
735
  @server.authenticate_resource_request(
733
- :method => 'POST',
734
- :uri => 'https://photos.example.net/photos',
735
- :body => 42,
736
- :headers => make_oauth_signature_header,
737
- :two_legged=>true
736
+ method: "POST",
737
+ uri: "https://photos.example.net/photos",
738
+ body: 42,
739
+ headers: make_oauth_signature_header,
740
+ two_legged: true
738
741
  )
739
742
  end).to raise_error(TypeError)
740
743
  end
741
- it 'should use form parameters in signature if request is a POSTed form' do
744
+ it "should use form parameters in signature if request is a POSTed form" do
742
745
  req = make_resource_request(
743
746
  @client,
744
- {:method=>'POST',
745
- :headers=>{'Content-Type'=>'application/x-www-form-urlencoded'},
746
- :body=>'c2&a3=2+q'}
747
+ method: "POST",
748
+ headers: { "Content-Type"=>"application/x-www-form-urlencoded" },
749
+ body: "c2&a3=2+q"
747
750
  )
748
751
  expect(@server.authenticate_resource_request(
749
- :request=>req, :two_legged=>true
750
- )).to eq @return_hash
752
+ request: req, two_legged: true
753
+ )).to eq @return_hash
751
754
  end
752
- it 'should raise an error if signature is x-www-form-encoded '+
753
- 'but does not send form parameters in header' do
755
+ it "should raise an error if signature is x-www-form-encoded " \
756
+ "but does not send form parameters in header" do
754
757
 
755
758
  # Make a full request so that we can sign against the form parameters
756
759
  # that will be removed.
757
760
  req = make_resource_request(
758
761
  @client,
759
- {:method=>'POST',
760
- :headers=>{'Content-Type'=>'application/x-www-form-urlencoded'},
761
- :body=>'c2&a3=2+q'}
762
+ method: "POST",
763
+ headers: { "Content-Type"=>"application/x-www-form-urlencoded" },
764
+ body: "c2&a3=2+q"
762
765
  )
763
766
 
764
- req.headers["Authorization"].gsub!(/c2=\"\", a3=\"2%20q\", /, '')
767
+ req.headers["Authorization"].gsub!(/c2=\"\", a3=\"2%20q\", /, "")
765
768
 
766
769
  expect(lambda do
767
- @server.authenticate_resource_request(:request=>req, :two_legged=>true)
770
+ @server.authenticate_resource_request request: req, two_legged: true
768
771
  end).to raise_error(Signet::MalformedAuthorizationError,
769
- 'Request is of type application/x-www-form-urlencoded but '+
770
- 'Authentication header did not include form values'
771
- )
772
+ "Request is of type application/x-www-form-urlencoded but " \
773
+ "Authentication header did not include form values")
772
774
  end
773
775
 
774
- it 'should call a user-supplied Proc to validate a nonce/timestamp pair' do
775
- nonce_callback = double('nonce')
776
+ it "should call a user-supplied Proc to validate a nonce/timestamp pair" do
777
+ nonce_callback = double "nonce"
776
778
  expect(nonce_callback).to receive(:call).once.with(
777
779
  an_instance_of(String), an_instance_of(String)
778
780
  ).and_return(true)
779
781
 
780
782
  @server.nonce_timestamp = nonce_callback
781
783
  @server.authenticate_resource_request(
782
- :request=>make_resource_request(@client), :two_legged=>true
784
+ request: make_resource_request(@client), two_legged: true
783
785
  )
784
786
  end
785
787
 
786
- it 'should call a user-supplied Proc to fetch the client credential' do
788
+ it "should call a user-supplied Proc to fetch the client credential" do
787
789
  client_cred = Signet::OAuth1::Credential.new(@client_credential_key,
788
- @client_credential_secret )
789
- key_callback = double('client_cred')
790
+ @client_credential_secret)
791
+ key_callback = double "client_cred"
790
792
  expect(key_callback).to receive(:call).at_least(:once).with(
791
793
  @client_credential_key
792
794
  ).and_return(client_cred)
793
795
 
794
796
  @server.client_credential = key_callback
795
797
  @server.authenticate_resource_request(
796
- :request=>make_resource_request(@client), :two_legged=>true
798
+ request: make_resource_request(@client), two_legged: true
797
799
  )
798
800
  end
799
801
 
800
- it 'should return a informational hash for a valid request' do
802
+ it "should return a informational hash for a valid request" do
801
803
  expect(@server.authenticate_resource_request(
802
- :request=>make_resource_request(@client), :two_legged=>true
803
- )).to eq @return_hash
804
+ request: make_resource_request(@client), two_legged: true
805
+ )).to eq @return_hash
804
806
  end
805
- it 'should return false for a unauthenticated request' do
806
- bad_request = make_resource_request(@client)
807
+ it "should return false for a unauthenticated request" do
808
+ bad_request = make_resource_request @client
807
809
  bad_request.headers["Authorization"].gsub!(/oauth_signature=\".+\"/,
808
- "oauth_signature=\"foobar\"")
809
- expect(@server.authenticate_resource_request(:request=>bad_request)).to eq nil
810
+ "oauth_signature=\"foobar\"")
811
+ expect(@server.authenticate_resource_request(request: bad_request)).to eq nil
810
812
  end
811
- it 'should return nil from #request_realm if no realm is provided' do
812
- req = make_resource_request(@client)
813
+ it "should return nil from #request_realm if no realm is provided" do
814
+ req = make_resource_request @client
813
815
  expect(@server.request_realm(
814
- :request=>req
815
- )).to eq nil
816
+ request: req
817
+ )).to eq nil
816
818
  end
817
- describe 'with a Realm provided' do
819
+ describe "with a Realm provided" do
818
820
  before do
819
- @realm = 'Photos'
821
+ @realm = "Photos"
820
822
  @return_hash[:realm] = @realm
821
823
  end
822
- it 'should return the realm from #request_realm' do
824
+ it "should return the realm from #request_realm" do
823
825
  req = make_resource_request(@client, {}, @realm)
824
826
  expect(@server.request_realm(
825
- :request=>req, :two_legged=>true
826
- )).to eq @realm
827
+ request: req, two_legged: true
828
+ )).to eq @realm
827
829
  end
828
830
 
829
- it 'should return a hash containing the realm with a valid request' do
831
+ it "should return a hash containing the realm with a valid request" do
830
832
  req = make_resource_request(@client, {}, @realm)
831
833
  expect(@server.authenticate_resource_request(
832
- :request=>req, :two_legged=>true
833
- )).to eq @return_hash
834
+ request: req, two_legged: true
835
+ )).to eq @return_hash
834
836
  end
835
837
  end
836
-
837
838
  end
838
-
839
839
  end