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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +51 -15
- data/Gemfile +5 -4
- data/README.md +4 -6
- data/Rakefile +107 -37
- data/lib/signet.rb +17 -14
- data/lib/signet/errors.rb +4 -4
- data/lib/signet/oauth_1.rb +129 -154
- data/lib/signet/oauth_1/client.rb +309 -343
- data/lib/signet/oauth_1/credential.rb +40 -37
- data/lib/signet/oauth_1/server.rb +197 -203
- data/lib/signet/oauth_1/signature_methods/hmac_sha1.rb +11 -10
- data/lib/signet/oauth_1/signature_methods/plaintext.rb +8 -7
- data/lib/signet/oauth_1/signature_methods/rsa_sha1.rb +11 -11
- data/lib/signet/oauth_2.rb +41 -43
- data/lib/signet/oauth_2/client.rb +328 -313
- data/lib/signet/version.rb +2 -73
- data/signet.gemspec +37 -39
- data/spec/signet/oauth_1/client_spec.rb +313 -315
- data/spec/signet/oauth_1/credential_spec.rb +64 -56
- data/spec/signet/oauth_1/server_spec.rb +362 -362
- data/spec/signet/oauth_1/signature_methods/hmac_sha1_spec.rb +26 -26
- data/spec/signet/oauth_1/signature_methods/plaintext_spec.rb +28 -28
- data/spec/signet/oauth_1/signature_methods/rsa_sha1_spec.rb +34 -35
- data/spec/signet/oauth_1_spec.rb +553 -524
- data/spec/signet/oauth_2/client_spec.rb +652 -576
- data/spec/signet/oauth_2_spec.rb +88 -89
- data/spec/signet_spec.rb +41 -41
- data/spec/spec_helper.rb +7 -7
- data/spec/spec_helper_spec.rb +8 -8
- metadata +64 -52
- data/tasks/clobber.rake +0 -2
- data/tasks/gem.rake +0 -34
- data/tasks/git.rake +0 -40
- data/tasks/metrics.rake +0 -41
- data/tasks/spec.rake +0 -34
- data/tasks/wiki.rake +0 -38
- data/tasks/yard.rake +0 -21
data/lib/signet/version.rb
CHANGED
@@ -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
|
-
|
16
|
-
|
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
|
data/signet.gemspec
CHANGED
@@ -1,46 +1,44 @@
|
|
1
|
-
|
2
|
-
|
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 |
|
6
|
-
|
7
|
-
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "signet"
|
6
|
+
gem.version = Signet::VERSION
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
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
|
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
|
26
|
+
merged_body.write chunk
|
29
27
|
end
|
30
|
-
|
28
|
+
merged_body.string
|
31
29
|
end
|
32
30
|
|
33
|
-
describe Signet::OAuth1::Client,
|
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
|
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
|
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
|
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
|
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
|
51
|
+
it "should have no authorization_uri" do
|
54
52
|
expect(@client.authorization_uri).to be_nil
|
55
53
|
end
|
56
54
|
|
57
|
-
it
|
58
|
-
@client.authorization_uri =
|
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
|
-
|
58
|
+
"http://example.com/authorize"
|
61
59
|
)
|
62
60
|
end
|
63
61
|
|
64
|
-
it
|
62
|
+
it "should allow the authorization_uri to be set to a Hash" do
|
65
63
|
@client.authorization_uri = {
|
66
|
-
:
|
64
|
+
scheme: "http", host: "example.com", path: "/authorize"
|
67
65
|
}
|
68
66
|
expect(@client.authorization_uri.to_s).to include(
|
69
|
-
|
67
|
+
"http://example.com/authorize"
|
70
68
|
)
|
71
69
|
end
|
72
70
|
|
73
|
-
it
|
71
|
+
it "should allow the authorization_uri to be set to a URI" do
|
74
72
|
@client.authorization_uri =
|
75
|
-
Addressable::URI.parse
|
73
|
+
Addressable::URI.parse "http://example.com/authorize"
|
76
74
|
expect(@client.authorization_uri.to_s).to include(
|
77
|
-
|
75
|
+
"http://example.com/authorize"
|
78
76
|
)
|
79
77
|
end
|
80
78
|
|
81
|
-
it
|
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
|
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
|
88
|
+
it "should allow the token_credential_uri to be set to a Hash" do
|
91
89
|
@client.token_credential_uri = {
|
92
|
-
:
|
90
|
+
scheme: "http", host: "example.com", path: "/token"
|
93
91
|
}
|
94
|
-
expect(@client.token_credential_uri.to_s).to eq
|
92
|
+
expect(@client.token_credential_uri.to_s).to eq "http://example.com/token"
|
95
93
|
end
|
96
94
|
|
97
|
-
it
|
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
|
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
|
101
|
+
it "should have no client_credential" do
|
104
102
|
expect(@client.client_credential).to be_nil
|
105
103
|
end
|
106
104
|
|
107
|
-
it
|
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
|
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
|
124
|
-
|
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
|
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
|
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
|
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
|
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
|
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
|
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 =
|
158
|
+
@client.client_credential_key = 12_345
|
161
159
|
end).to raise_error(TypeError)
|
162
160
|
end
|
163
161
|
|
164
|
-
it
|
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
|
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
|
174
|
-
|
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 =
|
174
|
+
@client.client_credential_secret = 54_321
|
177
175
|
end).to raise_error(TypeError)
|
178
176
|
end
|
179
177
|
|
180
|
-
it
|
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
|
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
|
187
|
+
it "should allow the callback to be set to a URI" do
|
190
188
|
@client.callback =
|
191
|
-
Addressable::URI.parse
|
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
|
193
|
+
it "should not allow the callback to be set to a non-String" do
|
196
194
|
expect(lambda do
|
197
|
-
@client.callback =
|
195
|
+
@client.callback = 12_345
|
198
196
|
end).to raise_error(TypeError)
|
199
197
|
end
|
200
198
|
|
201
|
-
it
|
202
|
-
@client.client_credential_key =
|
203
|
-
@client.client_credential_secret =
|
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
|
207
|
+
it "should raise an error if the client credential key is not set" do
|
210
208
|
@client.temporary_credential_uri =
|
211
|
-
|
212
|
-
@client.client_credential_secret =
|
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
|
216
|
+
it "should raise an error if the client credential secret is not set" do
|
219
217
|
@client.temporary_credential_uri =
|
220
|
-
|
221
|
-
@client.client_credential_key =
|
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
|
225
|
+
it "should have no temporary_credential" do
|
228
226
|
expect(@client.temporary_credential).to be_nil
|
229
227
|
end
|
230
228
|
|
231
|
-
it
|
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
|
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
|
248
|
-
|
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
|
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
|
251
|
+
expect(@client.temporary_credential).to eq Signet::OAuth1::Credential.new("12345", "54321")
|
254
252
|
end
|
255
253
|
|
256
|
-
it
|
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
|
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
|
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
|
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
|
283
|
-
|
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 =
|
283
|
+
@client.temporary_credential_key = 12_345
|
286
284
|
end).to raise_error(TypeError)
|
287
285
|
end
|
288
286
|
|
289
|
-
it
|
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
|
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
|
299
|
-
|
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 =
|
299
|
+
@client.temporary_credential_secret = 54_321
|
302
300
|
end).to raise_error(TypeError)
|
303
301
|
end
|
304
302
|
|
305
|
-
it
|
303
|
+
it "should have no token_credential" do
|
306
304
|
expect(@client.token_credential).to be_nil
|
307
305
|
end
|
308
306
|
|
309
|
-
it
|
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
|
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
|
326
|
-
|
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
|
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
|
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
|
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
|
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
|
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
|
361
|
-
|
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 =
|
361
|
+
@client.token_credential_key = 12_345
|
364
362
|
end).to raise_error(TypeError)
|
365
363
|
end
|
366
364
|
|
367
|
-
it
|
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
|
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
|
377
|
-
|
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 =
|
377
|
+
@client.token_credential_secret = 54_321
|
380
378
|
end).to raise_error(TypeError)
|
381
379
|
end
|
382
380
|
|
383
|
-
it
|
384
|
-
|
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,
|
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
|
-
|
393
|
+
"http://example.com/temporary_credentials"
|
396
394
|
@client.authorization_uri =
|
397
|
-
|
395
|
+
"http://example.com/authorize"
|
398
396
|
@client.token_credential_uri =
|
399
|
-
|
400
|
-
@client.callback =
|
401
|
-
@client.client_credential_key =
|
402
|
-
@client.client_credential_secret =
|
403
|
-
@client.temporary_credential_key =
|
404
|
-
@client.temporary_credential_secret =
|
405
|
-
@client.token_credential_key =
|
406
|
-
@client.token_credential_secret =
|
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
|
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
|
414
|
-
expect(deserialized["temporary_credential_uri"]).to eq
|
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
|
-
|
417
|
-
|
418
|
-
expect(deserialized["
|
419
|
-
expect(deserialized["
|
420
|
-
expect(deserialized["
|
421
|
-
expect(deserialized["
|
422
|
-
expect(deserialized["
|
423
|
-
expect(deserialized["
|
424
|
-
expect(deserialized["
|
425
|
-
|
426
|
-
|
427
|
-
|
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
|
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
|
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
|
-
|
434
|
+
"oauth_token=hh5s93j4hdidpola"
|
436
435
|
)
|
437
436
|
end
|
438
437
|
|
439
|
-
it
|
440
|
-
|
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
|
-
|
441
|
+
"oauth_callback=http://example.com/callback"
|
443
442
|
)
|
444
443
|
expect(@client.authorization_uri.to_s).to include(
|
445
|
-
|
444
|
+
"oauth_token=hh5s93j4hdidpola"
|
446
445
|
)
|
447
446
|
end
|
448
447
|
|
449
|
-
it
|
448
|
+
it "should generate an authorization URI with additional parameters" do
|
450
449
|
authorization_uri = @client.authorization_uri(
|
451
|
-
:
|
450
|
+
additional_parameters: { domain: "www.example.com" }
|
452
451
|
)
|
453
452
|
expect(authorization_uri.to_s).to include(
|
454
|
-
|
453
|
+
"oauth_callback=http://example.com/callback"
|
455
454
|
)
|
456
455
|
expect(authorization_uri.to_s).to include(
|
457
|
-
|
456
|
+
"oauth_token=hh5s93j4hdidpola"
|
458
457
|
)
|
459
458
|
expect(authorization_uri.to_s).to include(
|
460
|
-
|
459
|
+
"domain=www.example.com"
|
461
460
|
)
|
462
461
|
end
|
463
462
|
|
464
|
-
it
|
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
|
468
|
+
@client.generate_token_credential_request verifier: nil
|
470
469
|
end).to raise_error(ArgumentError)
|
471
470
|
end
|
472
471
|
|
473
|
-
it
|
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
|
475
|
+
@client.generate_token_credential_request verifier: "12345"
|
477
476
|
end).to raise_error(ArgumentError)
|
478
477
|
end
|
479
478
|
|
480
|
-
it
|
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
|
482
|
+
@client.generate_token_credential_request verifier: "12345"
|
484
483
|
end).to raise_error(ArgumentError)
|
485
484
|
end
|
486
485
|
|
487
|
-
it
|
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
|
489
|
+
@client.generate_token_credential_request verifier: "12345"
|
491
490
|
end).to raise_error(ArgumentError)
|
492
491
|
end
|
493
492
|
|
494
|
-
it
|
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
|
496
|
+
@client.generate_token_credential_request verifier: "12345"
|
498
497
|
end).to raise_error(ArgumentError)
|
499
498
|
end
|
500
499
|
|
501
|
-
it
|
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
|
503
|
+
@client.generate_token_credential_request verifier: "12345"
|
505
504
|
end).to raise_error(ArgumentError)
|
506
505
|
end
|
507
506
|
|
508
|
-
it
|
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
|
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
|
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
|
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
|
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
|
543
|
-
expect
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
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
|
551
|
-
|
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
|
-
:
|
554
|
-
req.url
|
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
|
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
|
563
|
-
:
|
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
|
568
|
+
it "should not raise an error if a request body is chunked" do
|
570
569
|
request = @client.generate_authenticated_request(
|
571
|
-
:
|
572
|
-
:uri
|
573
|
-
: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
|
575
|
+
expect(request.body).to eq "A chunked body."
|
577
576
|
end
|
578
577
|
|
579
|
-
it
|
578
|
+
it "should not raise an error if a request body is chunked" do
|
580
579
|
chunked_body = StringIO.new
|
581
|
-
chunked_body.write
|
580
|
+
chunked_body.write "A chunked body."
|
582
581
|
chunked_body.rewind
|
583
582
|
request = @client.generate_authenticated_request(
|
584
|
-
:
|
585
|
-
:uri
|
586
|
-
: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
|
588
|
+
expect(request.body).to eq "A chunked body."
|
590
589
|
end
|
591
590
|
|
592
|
-
it
|
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
|
-
:
|
596
|
-
:uri
|
597
|
-
:body
|
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
|
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
|
608
|
-
authorization_header = request.headers[
|
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(
|
613
|
-
expect(parameters).not_to have_key(
|
614
|
-
expect(parameters).not_to have_key(
|
615
|
-
expect(parameters[
|
616
|
-
expect(parameters[
|
617
|
-
expect(parameters[
|
618
|
-
expect(parameters[
|
619
|
-
expect(parameters[
|
620
|
-
expect(parameters[
|
621
|
-
expect(parameters[
|
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
|
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
|
-
:
|
628
|
+
verifier: "473f82d3"
|
630
629
|
)
|
631
630
|
expect(request.method).to eq :post
|
632
|
-
expect(request.path).to eq
|
633
|
-
authorization_header = request.headers[
|
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(
|
638
|
-
expect(parameters).not_to have_key(
|
639
|
-
expect(parameters).not_to have_key(
|
640
|
-
expect(parameters[
|
641
|
-
expect(parameters[
|
642
|
-
expect(parameters[
|
643
|
-
expect(parameters[
|
644
|
-
expect(parameters[
|
645
|
-
expect(parameters[
|
646
|
-
expect(parameters[
|
647
|
-
expect(parameters[
|
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
|
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
|
-
|
656
|
-
|
657
|
-
[[
|
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
|
-
:
|
660
|
+
request: original_request
|
662
661
|
)
|
663
662
|
expect(signed_request.method).to eq :get
|
664
|
-
expect(signed_request.path).to eq
|
665
|
-
expect(signed_request.params).to eq({"file"=>"vacation.jpg", "size"=>"original"})
|
666
|
-
authorization_header = signed_request.headers[
|
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(
|
672
|
-
expect(parameters).not_to have_key(
|
673
|
-
expect(parameters).not_to have_key(
|
674
|
-
expect(parameters).not_to have_key(
|
675
|
-
expect(parameters[
|
676
|
-
expect(parameters[
|
677
|
-
expect(parameters[
|
678
|
-
expect(parameters[
|
679
|
-
expect(parameters[
|
680
|
-
expect(parameters[
|
681
|
-
expect(parameters[
|
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
|
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
|
-
|
690
|
-
|
688
|
+
"POST",
|
689
|
+
"https://photos.example.net/photos",
|
691
690
|
[
|
692
|
-
[
|
693
|
-
[
|
694
|
-
[
|
691
|
+
["Host", "photos.example.net"],
|
692
|
+
["Content-Type", "application/x-www-form-urlencoded; charset=utf-8"],
|
693
|
+
["Content-Length", "31"]
|
695
694
|
],
|
696
|
-
[
|
695
|
+
["file=vacation.jpg&size=original"]
|
697
696
|
]
|
698
697
|
signed_request = @client.generate_authenticated_request(
|
699
|
-
:
|
698
|
+
request: original_request
|
700
699
|
)
|
701
700
|
expect(signed_request.method).to eq :post
|
702
|
-
expect(signed_request.path).to eq
|
703
|
-
authorization_header = signed_request.headers[
|
704
|
-
expect(signed_request.body).to eq
|
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(
|
709
|
-
expect(parameters).not_to have_key(
|
710
|
-
expect(parameters).not_to have_key(
|
711
|
-
expect(parameters).not_to have_key(
|
712
|
-
expect(parameters[
|
713
|
-
expect(parameters[
|
714
|
-
expect(parameters[
|
715
|
-
expect(parameters[
|
716
|
-
expect(parameters[
|
717
|
-
expect(parameters[
|
718
|
-
expect(parameters[
|
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
|
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
|
725
|
+
original_request = conn.build_request :get do |req|
|
728
726
|
req.url(
|
729
|
-
|
727
|
+
"https://photos.example.net/photos?file=vacation.jpg&size=original"
|
730
728
|
)
|
731
729
|
req.headers = Faraday::Utils::Headers.new(
|
732
|
-
[[
|
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
|
-
:
|
736
|
+
request: original_request
|
739
737
|
)
|
740
738
|
|
741
739
|
# Should be same request object
|
742
|
-
expect(original_request[
|
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
|
746
|
-
expect(signed_request.params).to eq ({"file"=>"vacation.jpg", "size"=>"original"})
|
747
|
-
authorization_header = signed_request.headers[
|
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(
|
753
|
-
expect(parameters).not_to have_key(
|
754
|
-
expect(parameters).not_to have_key(
|
755
|
-
expect(parameters).not_to have_key(
|
756
|
-
expect(parameters[
|
757
|
-
expect(parameters[
|
758
|
-
expect(parameters[
|
759
|
-
expect(parameters[
|
760
|
-
expect(parameters[
|
761
|
-
expect(parameters[
|
762
|
-
expect(parameters[
|
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
|
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
|
770
|
-
req.url
|
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
|
-
|
773
|
-
[
|
774
|
-
[
|
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
|
-
|
778
|
-
|
775
|
+
"size" => "original",
|
776
|
+
"file" => "vacation.jpg"
|
779
777
|
}
|
780
778
|
end
|
781
779
|
|
782
780
|
signed_request = @client.generate_authenticated_request(
|
783
|
-
:
|
781
|
+
request: original_request
|
784
782
|
)
|
785
783
|
|
786
784
|
# Should be same request object
|
787
|
-
expect(original_request[
|
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
|
791
|
-
authorization_header = signed_request.headers[
|
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(
|
794
|
-
expect(signed_request.body).to include(
|
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(
|
799
|
-
expect(parameters).not_to have_key(
|
800
|
-
expect(parameters).not_to have_key(
|
801
|
-
expect(parameters).not_to have_key(
|
802
|
-
expect(parameters[
|
803
|
-
expect(parameters[
|
804
|
-
expect(parameters[
|
805
|
-
expect(parameters[
|
806
|
-
expect(parameters[
|
807
|
-
expect(parameters[
|
808
|
-
expect(parameters[
|
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
|