elastomer-client 3.2.0 → 3.2.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 +3 -0
- data/lib/elastomer/client.rb +20 -3
- data/lib/elastomer/version.rb +1 -1
- data/test/client_test.rb +32 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cee8096020bd24f8d94aa4fc6f6f03f561a308091bb13c1fc30540ef98d69b8
|
4
|
+
data.tar.gz: 343bddae6131f036c3c713d328b2be6a378c7b708d82a926a1f610adbc8963cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61af8e5f289d5cae59239bf8fda64087ee722cef979f0898b56e10d5559830fc0fec403ee4dbabe1fd80b07849adf64ac9be6e654da40a94d02a7b808eb4cf99
|
7
|
+
data.tar.gz: 9b4f0d10dc3ec6664de87832108736e1963f0ff0da5caf84d730683dde6251a27a16c35e1e9642ed05dcbeb93bc1ee7913e796536fa8351ad87627300fc5c616
|
data/CHANGELOG.md
CHANGED
data/lib/elastomer/client.rb
CHANGED
@@ -147,10 +147,10 @@ module Elastomer
|
|
147
147
|
conn.options[:timeout] = read_timeout
|
148
148
|
conn.options[:open_timeout] = open_timeout
|
149
149
|
|
150
|
-
if
|
150
|
+
if token_auth?
|
151
151
|
conn.token_auth(@token_auth)
|
152
|
-
elsif
|
153
|
-
conn.basic_auth(@basic_auth
|
152
|
+
elsif basic_auth?
|
153
|
+
conn.basic_auth(@basic_auth[:username], @basic_auth[:password])
|
154
154
|
end
|
155
155
|
|
156
156
|
if @adapter.is_a?(Array)
|
@@ -483,6 +483,23 @@ module Elastomer
|
|
483
483
|
end.join(", ")
|
484
484
|
"<##{self.class}:#{self.object_id.to_s(16)} #{public_vars}>"
|
485
485
|
end
|
486
|
+
|
487
|
+
private
|
488
|
+
|
489
|
+
def token_auth?
|
490
|
+
present_for_auth?(@token_auth)
|
491
|
+
end
|
492
|
+
|
493
|
+
def basic_auth?
|
494
|
+
@basic_auth.is_a?(Hash) &&
|
495
|
+
present_for_auth?(@basic_auth[:username]) &&
|
496
|
+
present_for_auth?(@basic_auth[:password])
|
497
|
+
end
|
498
|
+
|
499
|
+
# Cheap implementation of ActiveSupport's Object#present?
|
500
|
+
def present_for_auth?(object)
|
501
|
+
object.respond_to?(:empty?) ? !object.empty? : !!object
|
502
|
+
end
|
486
503
|
end # Client
|
487
504
|
end # Elastomer
|
488
505
|
|
data/lib/elastomer/version.rb
CHANGED
data/test/client_test.rb
CHANGED
@@ -119,6 +119,38 @@ describe Elastomer::Client do
|
|
119
119
|
assert basic_auth_spy.has_been_called_with?("my_user", "my_secret_password")
|
120
120
|
end
|
121
121
|
|
122
|
+
it "ignores basic authentication if password is missing" do
|
123
|
+
client_params = $client_params.merge(basic_auth: {
|
124
|
+
username: "my_user"
|
125
|
+
})
|
126
|
+
client = Elastomer::Client.new client_params
|
127
|
+
|
128
|
+
connection = Faraday::Connection.new
|
129
|
+
basic_auth_spy = Spy.on(connection, :basic_auth).and_return(nil)
|
130
|
+
|
131
|
+
Faraday.stub(:new, $client_params[:url], connection) do
|
132
|
+
client.ping
|
133
|
+
end
|
134
|
+
|
135
|
+
refute basic_auth_spy.has_been_called?
|
136
|
+
end
|
137
|
+
|
138
|
+
it "ignores basic authentication if username is missing" do
|
139
|
+
client_params = $client_params.merge(basic_auth: {
|
140
|
+
password: "my_secret_password"
|
141
|
+
})
|
142
|
+
client = Elastomer::Client.new client_params
|
143
|
+
|
144
|
+
connection = Faraday::Connection.new
|
145
|
+
basic_auth_spy = Spy.on(connection, :basic_auth).and_return(nil)
|
146
|
+
|
147
|
+
Faraday.stub(:new, $client_params[:url], connection) do
|
148
|
+
client.ping
|
149
|
+
end
|
150
|
+
|
151
|
+
refute basic_auth_spy.has_been_called?
|
152
|
+
end
|
153
|
+
|
122
154
|
it "can use token authentication" do
|
123
155
|
client_params = $client_params.merge(token_auth: "my_secret_token")
|
124
156
|
client = Elastomer::Client.new client_params
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastomer-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.
|
4
|
+
version: 3.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Pease
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-08-
|
12
|
+
date: 2019-08-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|