elastomer-client 3.2.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3abce6a0da503d9a912b1f444cfb1911aa230db717c703d3eba42d31122295f
4
- data.tar.gz: 5ad2807d576cf3a48665217ad8601a531d308de10a1264ee63b131779014bdda
3
+ metadata.gz: 4cee8096020bd24f8d94aa4fc6f6f03f561a308091bb13c1fc30540ef98d69b8
4
+ data.tar.gz: 343bddae6131f036c3c713d328b2be6a378c7b708d82a926a1f610adbc8963cd
5
5
  SHA512:
6
- metadata.gz: 8c390f6c7fb21ae298beacd9eac8d471a897b7e6f53a642c4db2024b011f1f8b07118edcb0e3df6ce217509a86a05735c51424c46eb7bda537c8d4e213512c71
7
- data.tar.gz: b4ff217cd41090457e10cbb70b0beabfc5f672745d626afe4552f618ddb69367ff070691cc0743f00325ef06e8808e03a5c1509ff7da3e0e9fb9bcf1b983d8d8
6
+ metadata.gz: 61af8e5f289d5cae59239bf8fda64087ee722cef979f0898b56e10d5559830fc0fec403ee4dbabe1fd80b07849adf64ac9be6e654da40a94d02a7b808eb4cf99
7
+ data.tar.gz: 9b4f0d10dc3ec6664de87832108736e1963f0ff0da5caf84d730683dde6251a27a16c35e1e9642ed05dcbeb93bc1ee7913e796536fa8351ad87627300fc5c616
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 3.2.1 (2019-08-27)
2
+ - Ignore basic_auth unless username and password are present
3
+
1
4
  ## 3.2.0 (2019-08-22)
2
5
  - Add config based basic and token auth to `Elastomer::Client#connection`
3
6
  - Filter `Elastomer::Client#inspect` output to hide basic and token auth info,
@@ -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 @token_auth.present?
150
+ if token_auth?
151
151
  conn.token_auth(@token_auth)
152
- elsif @basic_auth.present?
153
- conn.basic_auth(@basic_auth.fetch(:username), @basic_auth.fetch(:password))
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
 
@@ -1,5 +1,5 @@
1
1
  module Elastomer
2
- VERSION = "3.2.0"
2
+ VERSION = "3.2.1"
3
3
 
4
4
  def self.version
5
5
  VERSION
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.0
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-22 00:00:00.000000000 Z
12
+ date: 2019-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable