Skip to content

Commit 7402118

Browse files
committed
Merge branches 'speedup-auth-fix' and 'require-user-and-pass' into mine
* 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
2 parents 465c738 + 5706ab6 commit 7402118

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

lib/faraday/request/digestauth.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ class DigestAuth < Faraday::Middleware
3131
# - keep_body_on_handshake: if set to truthy, will also send
3232
# the original request body
3333
def initialize(app, user, password, opts = {})
34+
if user.nil?
35+
raise ArgumentError, 'Username cannot be nil'
36+
end
37+
if password.nil?
38+
raise ArgumentError, 'Password cannot be nil'
39+
end
40+
3441
super(app)
3542
@user = user
3643
@password = password

spec/faraday/request/digest_auth_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,34 @@
5656
expect(response.body).to be_empty
5757
end
5858
end
59+
60+
context 'when the username is nil' do
61+
let(:connection) do
62+
Faraday.new('http://api.example.org/') do |builder|
63+
builder.request :digest, nil, 'PASS'
64+
builder.adapter :net_http
65+
end
66+
end
67+
68+
it 'raises ArgumentError during construction' do
69+
expect do
70+
connection.get('http://api.example.com')
71+
end.to raise_error(ArgumentError, /Username cannot be nil/)
72+
end
73+
end
74+
75+
context 'when the password is nil' do
76+
let(:connection) do
77+
Faraday.new('http://api.example.org/') do |builder|
78+
builder.request :digest, 'USER', nil
79+
builder.adapter :net_http
80+
end
81+
end
82+
83+
it 'raises ArgumentError during construction' do
84+
expect do
85+
connection.get('http://api.example.com')
86+
end.to raise_error(ArgumentError, /Password cannot be nil/)
87+
end
88+
end
5989
end

0 commit comments

Comments
 (0)