Skip to content

Commit

Permalink
Merge branches 'speedup-auth-fix' and 'require-user-and-pass' into mine
Browse files Browse the repository at this point in the history
* speedup-auth-fix:
  rubocop
  Squelch rubocop complaints
  Reuse server nonces and account for drbrain/net-http-digest_auth#17

* require-user-and-pass:
  Require username and password to be not nil
  • Loading branch information
p committed Sep 12, 2020
2 parents 465c738 + 5706ab6 commit 7402118
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/faraday/request/digestauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class DigestAuth < Faraday::Middleware
# - keep_body_on_handshake: if set to truthy, will also send
# the original request body
def initialize(app, user, password, opts = {})
if user.nil?
raise ArgumentError, 'Username cannot be nil'
end
if password.nil?
raise ArgumentError, 'Password cannot be nil'
end

super(app)
@user = user
@password = password
Expand Down
30 changes: 30 additions & 0 deletions spec/faraday/request/digest_auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,34 @@
expect(response.body).to be_empty
end
end

context 'when the username is nil' do
let(:connection) do
Faraday.new('http://api.example.org/') do |builder|
builder.request :digest, nil, 'PASS'
builder.adapter :net_http
end
end

it 'raises ArgumentError during construction' do
expect do
connection.get('http://api.example.com')
end.to raise_error(ArgumentError, /Username cannot be nil/)
end
end

context 'when the password is nil' do
let(:connection) do
Faraday.new('http://api.example.org/') do |builder|
builder.request :digest, 'USER', nil
builder.adapter :net_http
end
end

it 'raises ArgumentError during construction' do
expect do
connection.get('http://api.example.com')
end.to raise_error(ArgumentError, /Password cannot be nil/)
end
end
end

0 comments on commit 7402118

Please sign in to comment.