signet 0.13.2 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +11 -0
- data/CHANGELOG.md +70 -40
- data/CODE_OF_CONDUCT.md +43 -0
- data/README.md +10 -7
- data/SECURITY.md +7 -0
- data/lib/signet/oauth_1/client.rb +50 -71
- data/lib/signet/oauth_1/credential.rb +3 -11
- data/lib/signet/oauth_1/server.rb +5 -27
- data/lib/signet/oauth_1/signature_methods/hmac_sha1.rb +1 -1
- data/lib/signet/oauth_1/signature_methods/plaintext.rb +1 -1
- data/lib/signet/oauth_1/signature_methods/rsa_sha1.rb +2 -2
- data/lib/signet/oauth_1.rb +12 -22
- data/lib/signet/oauth_2/client.rb +55 -58
- data/lib/signet/oauth_2.rb +10 -14
- data/lib/signet/version.rb +1 -1
- data/lib/signet.rb +5 -8
- metadata +27 -27
- data/Gemfile +0 -8
- data/Rakefile +0 -112
- data/signet.gemspec +0 -44
- data/spec/signet/oauth_1/client_spec.rb +0 -810
- data/spec/signet/oauth_1/credential_spec.rb +0 -169
- data/spec/signet/oauth_1/server_spec.rb +0 -839
- data/spec/signet/oauth_1/signature_methods/hmac_sha1_spec.rb +0 -61
- data/spec/signet/oauth_1/signature_methods/plaintext_spec.rb +0 -61
- data/spec/signet/oauth_1/signature_methods/rsa_sha1_spec.rb +0 -126
- data/spec/signet/oauth_1_spec.rb +0 -1010
- data/spec/signet/oauth_2/client_spec.rb +0 -1214
- data/spec/signet/oauth_2_spec.rb +0 -194
- data/spec/signet_spec.rb +0 -78
- data/spec/spec.opts +0 -2
- data/spec/spec_helper.rb +0 -10
- data/spec/spec_helper_spec.rb +0 -17
- data/website/index.html +0 -95
data/lib/signet/oauth_2.rb
CHANGED
@@ -16,7 +16,7 @@ require "base64"
|
|
16
16
|
require "signet"
|
17
17
|
require "multi_json"
|
18
18
|
|
19
|
-
module Signet
|
19
|
+
module Signet # :nodoc:
|
20
20
|
##
|
21
21
|
# An implementation of http://tools.ietf.org/html/draft-ietf-oauth-v2-10
|
22
22
|
#
|
@@ -28,10 +28,10 @@ module Signet #:nodoc:
|
|
28
28
|
case auth_scheme
|
29
29
|
when /^Basic$/i
|
30
30
|
# HTTP Basic is allowed in OAuth 2
|
31
|
-
|
31
|
+
parse_basic_credentials(field_value[/^Basic\s+(.*)$/i, 1])
|
32
32
|
when /^OAuth$/i
|
33
33
|
# Other token types may be supported eventually
|
34
|
-
|
34
|
+
parse_bearer_credentials(field_value[/^OAuth\s+(.*)$/i, 1])
|
35
35
|
else
|
36
36
|
raise ParseError,
|
37
37
|
"Parsing non-OAuth Authorization headers is out of scope."
|
@@ -43,7 +43,7 @@ module Signet #:nodoc:
|
|
43
43
|
case auth_scheme
|
44
44
|
when /^OAuth$/i
|
45
45
|
# Other token types may be supported eventually
|
46
|
-
|
46
|
+
parse_oauth_challenge(field_value[/^OAuth\s+(.*)$/i, 1])
|
47
47
|
else
|
48
48
|
raise ParseError,
|
49
49
|
"Parsing non-OAuth WWW-Authenticate headers is out of scope."
|
@@ -76,9 +76,9 @@ module Signet #:nodoc:
|
|
76
76
|
raise TypeError, "Expected String, got #{body.class}." unless body.is_a? String
|
77
77
|
case content_type
|
78
78
|
when %r{^application/json.*}
|
79
|
-
|
79
|
+
MultiJson.load body
|
80
80
|
when %r{^application/x-www-form-urlencoded.*}
|
81
|
-
|
81
|
+
Hash[Addressable::URI.form_unencode(body)]
|
82
82
|
else
|
83
83
|
raise ArgumentError, "Invalid content type '#{content_type}'"
|
84
84
|
end
|
@@ -100,9 +100,8 @@ module Signet #:nodoc:
|
|
100
100
|
raise ArgumentError,
|
101
101
|
"A client identifier may not contain a ':' character."
|
102
102
|
end
|
103
|
-
|
104
|
-
|
105
|
-
).delete("\n")
|
103
|
+
token = Base64.encode64("#{client_id}:#{client_password}").delete("\n")
|
104
|
+
"Basic #{token}"
|
106
105
|
end
|
107
106
|
|
108
107
|
##
|
@@ -121,11 +120,8 @@ module Signet #:nodoc:
|
|
121
120
|
# TODO: escaping?
|
122
121
|
header = "Bearer #{access_token}"
|
123
122
|
if auth_params && !auth_params.empty?
|
124
|
-
|
125
|
-
|
126
|
-
accu << "#{key}=\"#{value}\""
|
127
|
-
end).join(", ")
|
128
|
-
)
|
123
|
+
additional_headers = auth_params.map { |key, value| "#{key}=\"#{value}\"" }
|
124
|
+
header = ([header] + additional_headers).join ", "
|
129
125
|
end
|
130
126
|
header
|
131
127
|
end
|
data/lib/signet/version.rb
CHANGED
data/lib/signet.rb
CHANGED
@@ -14,9 +14,7 @@
|
|
14
14
|
|
15
15
|
require "signet/version"
|
16
16
|
|
17
|
-
module Signet
|
18
|
-
# rubocop:disable Metrics/AbcSize
|
19
|
-
# rubocop:disable Metrics/MethodLength
|
17
|
+
module Signet # :nodoc:
|
20
18
|
def self.parse_auth_param_list auth_param_string
|
21
19
|
# Production rules from:
|
22
20
|
# http://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-12
|
@@ -54,11 +52,12 @@ module Signet #:nodoc:
|
|
54
52
|
# Now parse the auth-param pair strings & turn them into key-value pairs.
|
55
53
|
(auth_param_pairs.each_with_object [] do |pair, accu|
|
56
54
|
name, value = pair.split "=", 2
|
57
|
-
|
55
|
+
case value
|
56
|
+
when /^".*"$/
|
58
57
|
value = value.gsub(/^"(.*)"$/, '\1').gsub(/\\(.)/, '\1')
|
59
|
-
|
58
|
+
when /^'.*'$/
|
60
59
|
value = value.gsub(/^'(.*)'$/, '\1').gsub(/\\(.)/, '\1')
|
61
|
-
|
60
|
+
when %r{[()<>@,;:\\"/\[\]?={}]}
|
62
61
|
# Certain special characters are not allowed
|
63
62
|
raise ParseError,
|
64
63
|
"Unexpected characters in auth param " \
|
@@ -68,6 +67,4 @@ module Signet #:nodoc:
|
|
68
67
|
accu << [name, value]
|
69
68
|
end)
|
70
69
|
end
|
71
|
-
# rubocop:enable Metrics/AbcSize
|
72
|
-
# rubocop:enable Metrics/MethodLength
|
73
70
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: signet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Aman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-09-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '2.
|
20
|
+
version: '2.8'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '2.
|
27
|
+
version: '2.8'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: faraday
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,14 +85,14 @@ dependencies:
|
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
88
|
+
version: 1.25.1
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
91
|
version_requirements: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
95
|
+
version: 1.25.1
|
96
96
|
- !ruby/object:Gem::Dependency
|
97
97
|
name: kramdown
|
98
98
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,14 +127,28 @@ dependencies:
|
|
127
127
|
requirements:
|
128
128
|
- - "~>"
|
129
129
|
- !ruby/object:Gem::Version
|
130
|
-
version: '
|
130
|
+
version: '13.0'
|
131
131
|
type: :development
|
132
132
|
prerelease: false
|
133
133
|
version_requirements: !ruby/object:Gem::Requirement
|
134
134
|
requirements:
|
135
135
|
- - "~>"
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version: '
|
137
|
+
version: '13.0'
|
138
|
+
- !ruby/object:Gem::Dependency
|
139
|
+
name: redcarpet
|
140
|
+
requirement: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '3.0'
|
145
|
+
type: :development
|
146
|
+
prerelease: false
|
147
|
+
version_requirements: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - "~>"
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '3.0'
|
138
152
|
- !ruby/object:Gem::Dependency
|
139
153
|
name: rspec
|
140
154
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,11 +206,12 @@ extensions: []
|
|
192
206
|
extra_rdoc_files:
|
193
207
|
- README.md
|
194
208
|
files:
|
209
|
+
- ".yardopts"
|
195
210
|
- CHANGELOG.md
|
196
|
-
-
|
211
|
+
- CODE_OF_CONDUCT.md
|
197
212
|
- LICENSE
|
198
213
|
- README.md
|
199
|
-
-
|
214
|
+
- SECURITY.md
|
200
215
|
- lib/signet.rb
|
201
216
|
- lib/signet/errors.rb
|
202
217
|
- lib/signet/oauth_1.rb
|
@@ -209,21 +224,6 @@ files:
|
|
209
224
|
- lib/signet/oauth_2.rb
|
210
225
|
- lib/signet/oauth_2/client.rb
|
211
226
|
- lib/signet/version.rb
|
212
|
-
- signet.gemspec
|
213
|
-
- spec/signet/oauth_1/client_spec.rb
|
214
|
-
- spec/signet/oauth_1/credential_spec.rb
|
215
|
-
- spec/signet/oauth_1/server_spec.rb
|
216
|
-
- spec/signet/oauth_1/signature_methods/hmac_sha1_spec.rb
|
217
|
-
- spec/signet/oauth_1/signature_methods/plaintext_spec.rb
|
218
|
-
- spec/signet/oauth_1/signature_methods/rsa_sha1_spec.rb
|
219
|
-
- spec/signet/oauth_1_spec.rb
|
220
|
-
- spec/signet/oauth_2/client_spec.rb
|
221
|
-
- spec/signet/oauth_2_spec.rb
|
222
|
-
- spec/signet_spec.rb
|
223
|
-
- spec/spec.opts
|
224
|
-
- spec/spec_helper.rb
|
225
|
-
- spec/spec_helper_spec.rb
|
226
|
-
- website/index.html
|
227
227
|
homepage: https://github.com/googleapis/signet
|
228
228
|
licenses:
|
229
229
|
- Apache-2.0
|
@@ -241,14 +241,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
241
241
|
requirements:
|
242
242
|
- - ">="
|
243
243
|
- !ruby/object:Gem::Version
|
244
|
-
version: 2.
|
244
|
+
version: '2.5'
|
245
245
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
246
246
|
requirements:
|
247
247
|
- - ">="
|
248
248
|
- !ruby/object:Gem::Version
|
249
249
|
version: 1.3.5
|
250
250
|
requirements: []
|
251
|
-
rubygems_version: 3.
|
251
|
+
rubygems_version: 3.2.17
|
252
252
|
signing_key:
|
253
253
|
specification_version: 4
|
254
254
|
summary: Signet is an OAuth 1.0 / OAuth 2.0 implementation.
|
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "json"
|
3
|
-
require "rake"
|
4
|
-
require "bundler/gem_tasks"
|
5
|
-
|
6
|
-
task :release_gem, :tag do |_t, args|
|
7
|
-
tag = args[:tag]
|
8
|
-
raise "You must provide a tag to release." if tag.nil?
|
9
|
-
|
10
|
-
# Verify the tag format "vVERSION"
|
11
|
-
m = tag.match /v(?<version>\S*)/
|
12
|
-
raise "Tag #{tag} does not match the expected format." if m.nil?
|
13
|
-
|
14
|
-
version = m[:version]
|
15
|
-
raise "You must provide a version." if version.nil?
|
16
|
-
|
17
|
-
api_token = ENV["RUBYGEMS_API_TOKEN"]
|
18
|
-
|
19
|
-
require "gems"
|
20
|
-
if api_token
|
21
|
-
::Gems.configure do |config|
|
22
|
-
config.key = api_token
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
Bundler.with_clean_env do
|
27
|
-
sh "rm -rf pkg"
|
28
|
-
sh "bundle update"
|
29
|
-
sh "bundle exec rake build"
|
30
|
-
end
|
31
|
-
|
32
|
-
path_to_be_pushed = "pkg/signet-#{version}.gem"
|
33
|
-
gem_was_published = nil
|
34
|
-
if File.file? path_to_be_pushed
|
35
|
-
begin
|
36
|
-
response = ::Gems.push File.new(path_to_be_pushed)
|
37
|
-
puts response
|
38
|
-
raise unless response.include? "Successfully registered gem:"
|
39
|
-
gem_was_published = true
|
40
|
-
puts "Successfully built and pushed signet for version #{version}"
|
41
|
-
rescue StandardError => e
|
42
|
-
gem_was_published = false
|
43
|
-
puts "Error while releasing signet version #{version}: #{e.message}"
|
44
|
-
end
|
45
|
-
else
|
46
|
-
raise "Cannot build signet for version #{version}"
|
47
|
-
end
|
48
|
-
|
49
|
-
Rake::Task["kokoro:publish_docs"].invoke if gem_was_published
|
50
|
-
end
|
51
|
-
|
52
|
-
task :ci do
|
53
|
-
header "Using Ruby - #{RUBY_VERSION}"
|
54
|
-
sh "bundle exec rubocop"
|
55
|
-
sh "bundle exec rspec"
|
56
|
-
end
|
57
|
-
|
58
|
-
namespace :kokoro do
|
59
|
-
task :load_env_vars do
|
60
|
-
service_account = "#{ENV['KOKORO_GFILE_DIR']}/service-account.json"
|
61
|
-
ENV["GOOGLE_APPLICATION_CREDENTIALS"] = service_account
|
62
|
-
filename = "#{ENV['KOKORO_GFILE_DIR']}/env_vars.json"
|
63
|
-
env_vars = JSON.parse File.read(filename)
|
64
|
-
env_vars.each { |k, v| ENV[k] = v }
|
65
|
-
end
|
66
|
-
|
67
|
-
task :presubmit do
|
68
|
-
Rake::Task["ci"].invoke
|
69
|
-
end
|
70
|
-
|
71
|
-
task :continuous do
|
72
|
-
Rake::Task["ci"].invoke
|
73
|
-
end
|
74
|
-
|
75
|
-
task :nightly do
|
76
|
-
Rake::Task["ci"].invoke
|
77
|
-
end
|
78
|
-
|
79
|
-
task :release do
|
80
|
-
version = "0.1.0"
|
81
|
-
Bundler.with_clean_env do
|
82
|
-
version = `bundle exec gem list`
|
83
|
-
.split("\n").select { |line| line.include? "signet" }
|
84
|
-
.first.split("(").last.split(")").first || "0.1.0"
|
85
|
-
end
|
86
|
-
Rake::Task["kokoro:load_env_vars"].invoke
|
87
|
-
Rake::Task["release_gem"].invoke "v#{version}"
|
88
|
-
end
|
89
|
-
|
90
|
-
task :post do
|
91
|
-
require_relative "rakelib/link_checker.rb"
|
92
|
-
|
93
|
-
link_checker = LinkChecker.new
|
94
|
-
link_checker.run
|
95
|
-
exit link_checker.exit_status
|
96
|
-
end
|
97
|
-
|
98
|
-
task :publish_docs do
|
99
|
-
require_relative "rakelib/devsite_builder.rb"
|
100
|
-
|
101
|
-
DevsiteBuilder.new(__dir__).publish
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def header str, token = "#"
|
106
|
-
line_length = str.length + 8
|
107
|
-
puts ""
|
108
|
-
puts token * line_length
|
109
|
-
puts "#{token * 3} #{str} #{token * 3}"
|
110
|
-
puts token * line_length
|
111
|
-
puts ""
|
112
|
-
end
|
data/signet.gemspec
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
$LOAD_PATH.push File.expand_path("lib", __dir__)
|
2
|
-
require "signet/version"
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.name = "signet"
|
6
|
-
gem.version = Signet::VERSION
|
7
|
-
|
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"
|
25
|
-
|
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"
|
30
|
-
|
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
|
-
|
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"
|
43
|
-
end
|
44
|
-
end
|
@@ -1,810 +0,0 @@
|
|
1
|
-
# Copyright (C) 2010 Google Inc.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
require "spec_helper"
|
15
|
-
require "multi_json"
|
16
|
-
require "signet/oauth_1/client"
|
17
|
-
require "addressable/uri"
|
18
|
-
require "stringio"
|
19
|
-
|
20
|
-
conn = Faraday.default_connection
|
21
|
-
|
22
|
-
def merge_body chunked_body
|
23
|
-
raise ArgumentError, "Expected chunked body, got nil." if chunked_body == nil
|
24
|
-
merged_body = StringIO.new
|
25
|
-
chunked_body.each do |chunk|
|
26
|
-
merged_body.write chunk
|
27
|
-
end
|
28
|
-
merged_body.string
|
29
|
-
end
|
30
|
-
|
31
|
-
describe Signet::OAuth1::Client, "unconfigured" do
|
32
|
-
before do
|
33
|
-
@client = Signet::OAuth1::Client.new
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should have no temporary_credential_uri" do
|
37
|
-
expect(@client.temporary_credential_uri).to be_nil
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should allow the temporary_credential_uri to be set to a String" do
|
41
|
-
@client.temporary_credential_uri = "http://example.com/"
|
42
|
-
expect(@client.temporary_credential_uri.to_s).to eq "http://example.com/"
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should allow the temporary_credential_uri to be set to a URI" do
|
46
|
-
@client.temporary_credential_uri =
|
47
|
-
Addressable::URI.parse "http://example.com/"
|
48
|
-
expect(@client.temporary_credential_uri.to_s).to eq "http://example.com/"
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should have no authorization_uri" do
|
52
|
-
expect(@client.authorization_uri).to be_nil
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should allow the authorization_uri to be set to a String" do
|
56
|
-
@client.authorization_uri = "http://example.com/authorize"
|
57
|
-
expect(@client.authorization_uri.to_s).to include(
|
58
|
-
"http://example.com/authorize"
|
59
|
-
)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should allow the authorization_uri to be set to a Hash" do
|
63
|
-
@client.authorization_uri = {
|
64
|
-
scheme: "http", host: "example.com", path: "/authorize"
|
65
|
-
}
|
66
|
-
expect(@client.authorization_uri.to_s).to include(
|
67
|
-
"http://example.com/authorize"
|
68
|
-
)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should allow the authorization_uri to be set to a URI" do
|
72
|
-
@client.authorization_uri =
|
73
|
-
Addressable::URI.parse "http://example.com/authorize"
|
74
|
-
expect(@client.authorization_uri.to_s).to include(
|
75
|
-
"http://example.com/authorize"
|
76
|
-
)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should have no token_credential_uri" do
|
80
|
-
expect(@client.token_credential_uri).to be_nil
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should allow the token_credential_uri to be set to a String" do
|
84
|
-
@client.token_credential_uri = "http://example.com/"
|
85
|
-
expect(@client.token_credential_uri.to_s).to eq "http://example.com/"
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should allow the token_credential_uri to be set to a Hash" do
|
89
|
-
@client.token_credential_uri = {
|
90
|
-
scheme: "http", host: "example.com", path: "/token"
|
91
|
-
}
|
92
|
-
expect(@client.token_credential_uri.to_s).to eq "http://example.com/token"
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should allow the token_credential_uri to be set to a URI" do
|
96
|
-
@client.token_credential_uri =
|
97
|
-
Addressable::URI.parse "http://example.com/"
|
98
|
-
expect(@client.token_credential_uri.to_s).to eq "http://example.com/"
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should have no client_credential" do
|
102
|
-
expect(@client.client_credential).to be_nil
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should raise an error for partially set client credentials" do
|
106
|
-
@client.client_credential_key = "12345"
|
107
|
-
@client.client_credential_secret = nil
|
108
|
-
expect(lambda do
|
109
|
-
@client.client_credential
|
110
|
-
end).to raise_error(ArgumentError)
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should raise an error for partially set client credentials" do
|
114
|
-
@client.client_credential_key = nil
|
115
|
-
@client.client_credential_secret = "54321"
|
116
|
-
expect(lambda do
|
117
|
-
@client.client_credential
|
118
|
-
end).to raise_error(ArgumentError)
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should allow the client_credential to be set to a " \
|
122
|
-
"Signet::OAuth1::Credential" do
|
123
|
-
@client.client_credential =
|
124
|
-
Signet::OAuth1::Credential.new "12345", "54321"
|
125
|
-
expect(@client.client_credential_key).to eq "12345"
|
126
|
-
expect(@client.client_credential_secret).to eq "54321"
|
127
|
-
expect(@client.client_credential).to eq Signet::OAuth1::Credential.new("12345", "54321")
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should allow the client_credential to be set to nil" do
|
131
|
-
@client.client_credential_key = "12345"
|
132
|
-
@client.client_credential_secret = "54321"
|
133
|
-
expect(@client.client_credential_key).to eq "12345"
|
134
|
-
expect(@client.client_credential_secret).to eq "54321"
|
135
|
-
@client.client_credential = nil
|
136
|
-
expect(@client.client_credential).to be_nil
|
137
|
-
expect(@client.client_credential_key).to be_nil
|
138
|
-
expect(@client.client_credential_secret).to be_nil
|
139
|
-
end
|
140
|
-
|
141
|
-
it "should not allow the client_credential to be set to a bogus value" do
|
142
|
-
expect(lambda do
|
143
|
-
@client.client_credential = 42
|
144
|
-
end).to raise_error(TypeError)
|
145
|
-
end
|
146
|
-
|
147
|
-
it "should have no client_credential_key" do
|
148
|
-
expect(@client.client_credential_key).to be_nil
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should allow the client_credential_key to be set to a String" do
|
152
|
-
@client.client_credential_key = "12345"
|
153
|
-
expect(@client.client_credential_key).to eq "12345"
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should not allow the client_credential_key to be set to a non-String" do
|
157
|
-
expect(lambda do
|
158
|
-
@client.client_credential_key = 12_345
|
159
|
-
end).to raise_error(TypeError)
|
160
|
-
end
|
161
|
-
|
162
|
-
it "should have no client_credential_secret" do
|
163
|
-
expect(@client.client_credential_secret).to be_nil
|
164
|
-
end
|
165
|
-
|
166
|
-
it "should allow the client_credential_secret to be set to a String" do
|
167
|
-
@client.client_credential_secret = "54321"
|
168
|
-
expect(@client.client_credential_secret).to eq "54321"
|
169
|
-
end
|
170
|
-
|
171
|
-
it "should not allow the client_credential_secret " \
|
172
|
-
"to be set to a non-String" do
|
173
|
-
expect(lambda do
|
174
|
-
@client.client_credential_secret = 54_321
|
175
|
-
end).to raise_error(TypeError)
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should have an out-of-band callback" do
|
179
|
-
expect(@client.callback).to eq ::Signet::OAuth1::OUT_OF_BAND
|
180
|
-
end
|
181
|
-
|
182
|
-
it "should allow the callback to be set to a String" do
|
183
|
-
@client.callback = "http://example.com/callback"
|
184
|
-
expect(@client.callback).to eq "http://example.com/callback"
|
185
|
-
end
|
186
|
-
|
187
|
-
it "should allow the callback to be set to a URI" do
|
188
|
-
@client.callback =
|
189
|
-
Addressable::URI.parse "http://example.com/callback"
|
190
|
-
expect(@client.callback).to eq "http://example.com/callback"
|
191
|
-
end
|
192
|
-
|
193
|
-
it "should not allow the callback to be set to a non-String" do
|
194
|
-
expect(lambda do
|
195
|
-
@client.callback = 12_345
|
196
|
-
end).to raise_error(TypeError)
|
197
|
-
end
|
198
|
-
|
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"
|
202
|
-
expect(lambda do
|
203
|
-
@client.generate_temporary_credential_request
|
204
|
-
end).to raise_error(ArgumentError)
|
205
|
-
end
|
206
|
-
|
207
|
-
it "should raise an error if the client credential key is not set" do
|
208
|
-
@client.temporary_credential_uri =
|
209
|
-
"http://example.com/temporary_credentials"
|
210
|
-
@client.client_credential_secret = "kd94hf93k423kf44"
|
211
|
-
expect(lambda do
|
212
|
-
@client.generate_temporary_credential_request
|
213
|
-
end).to raise_error(ArgumentError)
|
214
|
-
end
|
215
|
-
|
216
|
-
it "should raise an error if the client credential secret is not set" do
|
217
|
-
@client.temporary_credential_uri =
|
218
|
-
"http://example.com/temporary_credentials"
|
219
|
-
@client.client_credential_key = "dpf43f3p2l4k3l03"
|
220
|
-
expect(lambda do
|
221
|
-
@client.generate_temporary_credential_request
|
222
|
-
end).to raise_error(ArgumentError)
|
223
|
-
end
|
224
|
-
|
225
|
-
it "should have no temporary_credential" do
|
226
|
-
expect(@client.temporary_credential).to be_nil
|
227
|
-
end
|
228
|
-
|
229
|
-
it "should raise an error for partially set temporary credentials" do
|
230
|
-
@client.temporary_credential_key = "12345"
|
231
|
-
@client.temporary_credential_secret = nil
|
232
|
-
expect(lambda do
|
233
|
-
@client.temporary_credential
|
234
|
-
end).to raise_error(ArgumentError)
|
235
|
-
end
|
236
|
-
|
237
|
-
it "should raise an error for partially set temporary credentials" do
|
238
|
-
@client.temporary_credential_key = nil
|
239
|
-
@client.temporary_credential_secret = "54321"
|
240
|
-
expect(lambda do
|
241
|
-
@client.temporary_credential
|
242
|
-
end).to raise_error(ArgumentError)
|
243
|
-
end
|
244
|
-
|
245
|
-
it "should allow the temporary_credential to be set to a " \
|
246
|
-
"Signet::OAuth1::Credential" do
|
247
|
-
@client.temporary_credential =
|
248
|
-
Signet::OAuth1::Credential.new "12345", "54321"
|
249
|
-
expect(@client.temporary_credential_key).to eq "12345"
|
250
|
-
expect(@client.temporary_credential_secret).to eq "54321"
|
251
|
-
expect(@client.temporary_credential).to eq Signet::OAuth1::Credential.new("12345", "54321")
|
252
|
-
end
|
253
|
-
|
254
|
-
it "should allow the temporary_credential to be set to nil" do
|
255
|
-
@client.temporary_credential_key = "12345"
|
256
|
-
@client.temporary_credential_secret = "54321"
|
257
|
-
expect(@client.temporary_credential_key).to eq "12345"
|
258
|
-
expect(@client.temporary_credential_secret).to eq "54321"
|
259
|
-
@client.temporary_credential = nil
|
260
|
-
expect(@client.temporary_credential).to be_nil
|
261
|
-
expect(@client.temporary_credential_key).to be_nil
|
262
|
-
expect(@client.temporary_credential_secret).to be_nil
|
263
|
-
end
|
264
|
-
|
265
|
-
it "should not allow the temporary_credential to be set to a bogus value" do
|
266
|
-
expect(lambda do
|
267
|
-
@client.temporary_credential = 42
|
268
|
-
end).to raise_error(TypeError)
|
269
|
-
end
|
270
|
-
|
271
|
-
it "should have no temporary_credential_key" do
|
272
|
-
expect(@client.temporary_credential_key).to be_nil
|
273
|
-
end
|
274
|
-
|
275
|
-
it "should allow the temporary_credential_key to be set to a String" do
|
276
|
-
@client.temporary_credential_key = "12345"
|
277
|
-
expect(@client.temporary_credential_key).to eq "12345"
|
278
|
-
end
|
279
|
-
|
280
|
-
it "should not allow the temporary_credential_key " \
|
281
|
-
"to be set to a non-String" do
|
282
|
-
expect(lambda do
|
283
|
-
@client.temporary_credential_key = 12_345
|
284
|
-
end).to raise_error(TypeError)
|
285
|
-
end
|
286
|
-
|
287
|
-
it "should have no temporary_credential_secret" do
|
288
|
-
expect(@client.temporary_credential_secret).to be_nil
|
289
|
-
end
|
290
|
-
|
291
|
-
it "should allow the temporary_credential_secret to be set to a String" do
|
292
|
-
@client.temporary_credential_secret = "54321"
|
293
|
-
expect(@client.temporary_credential_secret).to eq "54321"
|
294
|
-
end
|
295
|
-
|
296
|
-
it "should not allow the temporary_credential_secret " \
|
297
|
-
"to be set to a non-String" do
|
298
|
-
expect(lambda do
|
299
|
-
@client.temporary_credential_secret = 54_321
|
300
|
-
end).to raise_error(TypeError)
|
301
|
-
end
|
302
|
-
|
303
|
-
it "should have no token_credential" do
|
304
|
-
expect(@client.token_credential).to be_nil
|
305
|
-
end
|
306
|
-
|
307
|
-
it "should raise an error for partially set token credentials" do
|
308
|
-
@client.token_credential_key = "12345"
|
309
|
-
@client.token_credential_secret = nil
|
310
|
-
expect(lambda do
|
311
|
-
@client.token_credential
|
312
|
-
end).to raise_error(ArgumentError)
|
313
|
-
end
|
314
|
-
|
315
|
-
it "should raise an error for partially set token credentials" do
|
316
|
-
@client.token_credential_key = nil
|
317
|
-
@client.token_credential_secret = "54321"
|
318
|
-
expect(lambda do
|
319
|
-
@client.token_credential
|
320
|
-
end).to raise_error(ArgumentError)
|
321
|
-
end
|
322
|
-
|
323
|
-
it "should allow the token_credential to be set to a " \
|
324
|
-
"Signet::OAuth1::Credential" do
|
325
|
-
@client.token_credential =
|
326
|
-
Signet::OAuth1::Credential.new "12345", "54321"
|
327
|
-
expect(@client.token_credential_key).to eq "12345"
|
328
|
-
expect(@client.token_credential_secret).to eq "54321"
|
329
|
-
expect(@client.token_credential).to eq Signet::OAuth1::Credential.new("12345", "54321")
|
330
|
-
end
|
331
|
-
|
332
|
-
it "should allow the token_credential to be set to nil" do
|
333
|
-
@client.token_credential_key = "12345"
|
334
|
-
@client.token_credential_secret = "54321"
|
335
|
-
expect(@client.token_credential_key).to eq "12345"
|
336
|
-
expect(@client.token_credential_secret).to eq "54321"
|
337
|
-
@client.token_credential = nil
|
338
|
-
expect(@client.token_credential).to be_nil
|
339
|
-
expect(@client.token_credential_key).to be_nil
|
340
|
-
expect(@client.token_credential_secret).to be_nil
|
341
|
-
end
|
342
|
-
|
343
|
-
it "should not allow the token_credential to be set to a bogus value" do
|
344
|
-
expect(lambda do
|
345
|
-
@client.token_credential = 42
|
346
|
-
end).to raise_error(TypeError)
|
347
|
-
end
|
348
|
-
|
349
|
-
it "should have no token_credential_key" do
|
350
|
-
expect(@client.token_credential_key).to be_nil
|
351
|
-
end
|
352
|
-
|
353
|
-
it "should allow the token_credential_key to be set to a String" do
|
354
|
-
@client.token_credential_key = "12345"
|
355
|
-
expect(@client.token_credential_key).to eq "12345"
|
356
|
-
end
|
357
|
-
|
358
|
-
it "should not allow the token_credential_key " \
|
359
|
-
"to be set to a non-String" do
|
360
|
-
expect(lambda do
|
361
|
-
@client.token_credential_key = 12_345
|
362
|
-
end).to raise_error(TypeError)
|
363
|
-
end
|
364
|
-
|
365
|
-
it "should have no token_credential_secret" do
|
366
|
-
expect(@client.token_credential_secret).to be_nil
|
367
|
-
end
|
368
|
-
|
369
|
-
it "should allow the token_credential_secret to be set to a String" do
|
370
|
-
@client.token_credential_secret = "54321"
|
371
|
-
expect(@client.token_credential_secret).to eq "54321"
|
372
|
-
end
|
373
|
-
|
374
|
-
it "should not allow the token_credential_secret " \
|
375
|
-
"to be set to a non-String" do
|
376
|
-
expect(lambda do
|
377
|
-
@client.token_credential_secret = 54_321
|
378
|
-
end).to raise_error(TypeError)
|
379
|
-
end
|
380
|
-
|
381
|
-
it "should not allow the two_legged flag " \
|
382
|
-
"to be set to a non-Boolean" do
|
383
|
-
expect(lambda do
|
384
|
-
@client.two_legged = 42
|
385
|
-
end).to raise_error(TypeError)
|
386
|
-
end
|
387
|
-
end
|
388
|
-
|
389
|
-
describe Signet::OAuth1::Client, "configured" do
|
390
|
-
before do
|
391
|
-
@client = Signet::OAuth1::Client.new
|
392
|
-
@client.temporary_credential_uri =
|
393
|
-
"http://example.com/temporary_credentials"
|
394
|
-
@client.authorization_uri =
|
395
|
-
"http://example.com/authorize"
|
396
|
-
@client.token_credential_uri =
|
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"
|
405
|
-
end
|
406
|
-
|
407
|
-
it "should generate a JSON representation of the client" do
|
408
|
-
json = @client.to_json
|
409
|
-
expect(json).not_to be_nil
|
410
|
-
|
411
|
-
deserialized = MultiJson.load json
|
412
|
-
expect(deserialized["temporary_credential_uri"]).to eq "http://example.com/temporary_credentials"
|
413
|
-
expect(deserialized["authorization_uri"]).to include(
|
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
|
427
|
-
@client.temporary_credential_key = nil
|
428
|
-
expect(@client.authorization_uri.to_s).to eq "http://example.com/authorize?oauth_callback=http://example.com/callback"
|
429
|
-
end
|
430
|
-
|
431
|
-
it "should generate an authorization URI with a temporary credential" do
|
432
|
-
@client.callback = nil
|
433
|
-
expect(@client.authorization_uri.to_s).to include(
|
434
|
-
"oauth_token=hh5s93j4hdidpola"
|
435
|
-
)
|
436
|
-
end
|
437
|
-
|
438
|
-
it "should generate an authorization URI both a callback and " \
|
439
|
-
"a temporary credential" do
|
440
|
-
expect(@client.authorization_uri.to_s).to include(
|
441
|
-
"oauth_callback=http://example.com/callback"
|
442
|
-
)
|
443
|
-
expect(@client.authorization_uri.to_s).to include(
|
444
|
-
"oauth_token=hh5s93j4hdidpola"
|
445
|
-
)
|
446
|
-
end
|
447
|
-
|
448
|
-
it "should generate an authorization URI with additional parameters" do
|
449
|
-
authorization_uri = @client.authorization_uri(
|
450
|
-
additional_parameters: { domain: "www.example.com" }
|
451
|
-
)
|
452
|
-
expect(authorization_uri.to_s).to include(
|
453
|
-
"oauth_callback=http://example.com/callback"
|
454
|
-
)
|
455
|
-
expect(authorization_uri.to_s).to include(
|
456
|
-
"oauth_token=hh5s93j4hdidpola"
|
457
|
-
)
|
458
|
-
expect(authorization_uri.to_s).to include(
|
459
|
-
"domain=www.example.com"
|
460
|
-
)
|
461
|
-
end
|
462
|
-
|
463
|
-
it "should raise an error if the verifier is not provided" do
|
464
|
-
expect(lambda do
|
465
|
-
@client.generate_token_credential_request
|
466
|
-
end).to raise_error(ArgumentError)
|
467
|
-
expect(lambda do
|
468
|
-
@client.generate_token_credential_request verifier: nil
|
469
|
-
end).to raise_error(ArgumentError)
|
470
|
-
end
|
471
|
-
|
472
|
-
it "should raise an error if the token credentials URI is not set" do
|
473
|
-
@client.token_credential_uri = nil
|
474
|
-
expect(lambda do
|
475
|
-
@client.generate_token_credential_request verifier: "12345"
|
476
|
-
end).to raise_error(ArgumentError)
|
477
|
-
end
|
478
|
-
|
479
|
-
it "should raise an error if the client credential key is not set" do
|
480
|
-
@client.client_credential_key = nil
|
481
|
-
expect(lambda do
|
482
|
-
@client.generate_token_credential_request verifier: "12345"
|
483
|
-
end).to raise_error(ArgumentError)
|
484
|
-
end
|
485
|
-
|
486
|
-
it "should raise an error if the client credential secret is not set" do
|
487
|
-
@client.client_credential_secret = nil
|
488
|
-
expect(lambda do
|
489
|
-
@client.generate_token_credential_request verifier: "12345"
|
490
|
-
end).to raise_error(ArgumentError)
|
491
|
-
end
|
492
|
-
|
493
|
-
it "should raise an error if the temporary credential key is not set" do
|
494
|
-
@client.temporary_credential_key = nil
|
495
|
-
expect(lambda do
|
496
|
-
@client.generate_token_credential_request verifier: "12345"
|
497
|
-
end).to raise_error(ArgumentError)
|
498
|
-
end
|
499
|
-
|
500
|
-
it "should raise an error if the temporary credential secret is not set" do
|
501
|
-
@client.temporary_credential_secret = nil
|
502
|
-
expect(lambda do
|
503
|
-
@client.generate_token_credential_request verifier: "12345"
|
504
|
-
end).to raise_error(ArgumentError)
|
505
|
-
end
|
506
|
-
|
507
|
-
it "should raise an error if the client credential key is not set" do
|
508
|
-
@client.client_credential_key = nil
|
509
|
-
expect(lambda do
|
510
|
-
@client.generate_authenticated_request
|
511
|
-
end).to raise_error(ArgumentError)
|
512
|
-
end
|
513
|
-
|
514
|
-
it "should raise an error if the client credential secret is not set" do
|
515
|
-
@client.client_credential_secret = nil
|
516
|
-
expect(lambda do
|
517
|
-
@client.generate_authenticated_request
|
518
|
-
end).to raise_error(ArgumentError)
|
519
|
-
end
|
520
|
-
|
521
|
-
it "should raise an error if the token credential key is not set" do
|
522
|
-
@client.token_credential_key = nil
|
523
|
-
expect(lambda do
|
524
|
-
@client.generate_authenticated_request
|
525
|
-
end).to raise_error(ArgumentError)
|
526
|
-
end
|
527
|
-
|
528
|
-
it "should raise an error if the token credential secret is not set" do
|
529
|
-
@client.token_credential_secret = nil
|
530
|
-
expect(lambda do
|
531
|
-
@client.generate_authenticated_request
|
532
|
-
end).to raise_error(ArgumentError)
|
533
|
-
end
|
534
|
-
|
535
|
-
it "should raise an error if no request is provided" do
|
536
|
-
expect(lambda do
|
537
|
-
@client.generate_authenticated_request
|
538
|
-
end).to raise_error(ArgumentError)
|
539
|
-
end
|
540
|
-
|
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)
|
547
|
-
end
|
548
|
-
|
549
|
-
it "should not raise an error if a request is "\
|
550
|
-
"provided without a connection" do
|
551
|
-
request = @client.generate_authenticated_request(
|
552
|
-
request: conn.build_request(:get) do |req|
|
553
|
-
req.url "http://www.example.com/"
|
554
|
-
end
|
555
|
-
)
|
556
|
-
end
|
557
|
-
|
558
|
-
it "should raise an error if no URI is provided" do
|
559
|
-
expect(lambda do
|
560
|
-
@client.generate_authenticated_request(
|
561
|
-
:method => "GET",
|
562
|
-
headers: [],
|
563
|
-
:body => ""
|
564
|
-
)
|
565
|
-
end).to raise_error(ArgumentError)
|
566
|
-
end
|
567
|
-
|
568
|
-
it "should not raise an error if a request body is chunked" do
|
569
|
-
request = @client.generate_authenticated_request(
|
570
|
-
method: "POST",
|
571
|
-
:uri => "https://photos.example.net/photos",
|
572
|
-
:body => ["A chunked body."]
|
573
|
-
)
|
574
|
-
expect(request).to be_kind_of(Faraday::Request)
|
575
|
-
expect(request.body).to eq "A chunked body."
|
576
|
-
end
|
577
|
-
|
578
|
-
it "should not raise an error if a request body is chunked" do
|
579
|
-
chunked_body = StringIO.new
|
580
|
-
chunked_body.write "A chunked body."
|
581
|
-
chunked_body.rewind
|
582
|
-
request = @client.generate_authenticated_request(
|
583
|
-
method: "POST",
|
584
|
-
:uri => "https://photos.example.net/photos",
|
585
|
-
:body => chunked_body
|
586
|
-
)
|
587
|
-
expect(request).to be_kind_of(Faraday::Request)
|
588
|
-
expect(request.body).to eq "A chunked body."
|
589
|
-
end
|
590
|
-
|
591
|
-
it "should raise an error if a request body is of a bogus type" do
|
592
|
-
expect(lambda do
|
593
|
-
@client.generate_authenticated_request(
|
594
|
-
method: "POST",
|
595
|
-
:uri => "https://photos.example.net/photos",
|
596
|
-
:body => 42
|
597
|
-
)
|
598
|
-
end).to raise_error(TypeError)
|
599
|
-
end
|
600
|
-
|
601
|
-
it "should correctly fetch the temporary credentials" do
|
602
|
-
# Repeat this because signatures change from test to test
|
603
|
-
10.times do
|
604
|
-
request = @client.generate_temporary_credential_request
|
605
|
-
expect(request.method).to eq :post
|
606
|
-
expect(request.path).to eq "http://example.com/temporary_credentials"
|
607
|
-
authorization_header = request.headers["Authorization"]
|
608
|
-
parameters = ::Signet::OAuth1.parse_authorization_header(
|
609
|
-
authorization_header
|
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"
|
621
|
-
end
|
622
|
-
end
|
623
|
-
|
624
|
-
it "should correctly fetch the token credentials" do
|
625
|
-
# Repeat this because signatures change from test to test
|
626
|
-
10.times do
|
627
|
-
request = @client.generate_token_credential_request(
|
628
|
-
verifier: "473f82d3"
|
629
|
-
)
|
630
|
-
expect(request.method).to eq :post
|
631
|
-
expect(request.path).to eq "http://example.com/token_credentials"
|
632
|
-
authorization_header = request.headers["Authorization"]
|
633
|
-
parameters = ::Signet::OAuth1.parse_authorization_header(
|
634
|
-
authorization_header
|
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"
|
647
|
-
end
|
648
|
-
end
|
649
|
-
|
650
|
-
it "should correctly fetch the protected resource" do
|
651
|
-
# Repeat this because signatures change from test to test
|
652
|
-
10.times do
|
653
|
-
original_request = [
|
654
|
-
"GET",
|
655
|
-
"https://photos.example.net/photos?file=vacation.jpg&size=original",
|
656
|
-
[["Host", "photos.example.net"]],
|
657
|
-
[""]
|
658
|
-
]
|
659
|
-
signed_request = @client.generate_authenticated_request(
|
660
|
-
request: original_request
|
661
|
-
)
|
662
|
-
expect(signed_request.method).to eq :get
|
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 ""
|
667
|
-
parameters = ::Signet::OAuth1.parse_authorization_header(
|
668
|
-
authorization_header
|
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"
|
681
|
-
end
|
682
|
-
end
|
683
|
-
|
684
|
-
it "should correctly fetch the protected resource" do
|
685
|
-
# Repeat this because signatures change from test to test
|
686
|
-
10.times do
|
687
|
-
original_request = [
|
688
|
-
"POST",
|
689
|
-
"https://photos.example.net/photos",
|
690
|
-
[
|
691
|
-
["Host", "photos.example.net"],
|
692
|
-
["Content-Type", "application/x-www-form-urlencoded; charset=utf-8"],
|
693
|
-
["Content-Length", "31"]
|
694
|
-
],
|
695
|
-
["file=vacation.jpg&size=original"]
|
696
|
-
]
|
697
|
-
signed_request = @client.generate_authenticated_request(
|
698
|
-
request: original_request
|
699
|
-
)
|
700
|
-
expect(signed_request.method).to eq :post
|
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"
|
704
|
-
parameters = ::Signet::OAuth1.parse_authorization_header(
|
705
|
-
authorization_header
|
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"
|
718
|
-
end
|
719
|
-
end
|
720
|
-
|
721
|
-
describe "with Faraday requests" do
|
722
|
-
it "should correctly get the protected resource" do
|
723
|
-
# Repeat this because signatures change from test to test
|
724
|
-
10.times do
|
725
|
-
original_request = conn.build_request :get do |req|
|
726
|
-
req.url(
|
727
|
-
"https://photos.example.net/photos?file=vacation.jpg&size=original"
|
728
|
-
)
|
729
|
-
req.headers = Faraday::Utils::Headers.new(
|
730
|
-
[["Host", "photos.example.net"]]
|
731
|
-
)
|
732
|
-
req.body = ""
|
733
|
-
end
|
734
|
-
|
735
|
-
signed_request = @client.generate_authenticated_request(
|
736
|
-
request: original_request
|
737
|
-
)
|
738
|
-
|
739
|
-
# Should be same request object
|
740
|
-
expect(original_request["Authorization"]).to eq signed_request["Authorization"]
|
741
|
-
|
742
|
-
expect(signed_request.method).to eq :get
|
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 ""
|
747
|
-
parameters = ::Signet::OAuth1.parse_authorization_header(
|
748
|
-
authorization_header
|
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"
|
761
|
-
end
|
762
|
-
end
|
763
|
-
|
764
|
-
it "should correctly post the protected resource" do
|
765
|
-
# Repeat this because signatures change from test to test
|
766
|
-
10.times do
|
767
|
-
original_request = conn.build_request :post do |req|
|
768
|
-
req.url "https://photos.example.net/photos"
|
769
|
-
req.headers = Faraday::Utils::Headers.new([
|
770
|
-
["Host", "photos.example.net"],
|
771
|
-
["Content-Type", "application/x-www-form-urlencoded; charset=utf-8"],
|
772
|
-
["Content-Length", "31"]
|
773
|
-
])
|
774
|
-
req.body = {
|
775
|
-
"size" => "original",
|
776
|
-
"file" => "vacation.jpg"
|
777
|
-
}
|
778
|
-
end
|
779
|
-
|
780
|
-
signed_request = @client.generate_authenticated_request(
|
781
|
-
request: original_request
|
782
|
-
)
|
783
|
-
|
784
|
-
# Should be same request object
|
785
|
-
expect(original_request["Authorization"]).to eq signed_request["Authorization"]
|
786
|
-
|
787
|
-
expect(signed_request.method).to eq :post
|
788
|
-
expect(signed_request.path).to eq "https://photos.example.net/photos"
|
789
|
-
authorization_header = signed_request.headers["Authorization"]
|
790
|
-
# Can't rely on the order post parameters are encoded in.
|
791
|
-
expect(signed_request.body).to include("file=vacation.jpg")
|
792
|
-
expect(signed_request.body).to include("size=original")
|
793
|
-
parameters = ::Signet::OAuth1.parse_authorization_header(
|
794
|
-
authorization_header
|
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"
|
807
|
-
end
|
808
|
-
end
|
809
|
-
end
|
810
|
-
end
|