From 3659793cdb4e1048038784ecc9abe84633e0a886 Mon Sep 17 00:00:00 2001 From: Bernd Ritter Date: Fri, 20 Nov 2015 10:34:45 +0100 Subject: [PATCH 1/2] This fixes the nil error and enables to read the reponse again. fixes #447 --- lib/httparty/net_digest_auth.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/httparty/net_digest_auth.rb b/lib/httparty/net_digest_auth.rb index e124583..7729458 100644 --- a/lib/httparty/net_digest_auth.rb +++ b/lib/httparty/net_digest_auth.rb @@ -68,8 +68,10 @@ module Net header =~ /Digest (.*)/ params = {} - non_quoted = $1.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 } - non_quoted.gsub(/(\w+)=([^,]*)/) { params[$1] = $2 } + if $1 + non_quoted = $1.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 } + non_quoted.gsub(/(\w+)=([^,]*)/) { params[$1] = $2 } + end params end From 768b40dd3fe05609d4682a1d4850e5fb647e40c0 Mon Sep 17 00:00:00 2001 From: Bernd Ritter Date: Thu, 26 Nov 2015 15:58:00 +0100 Subject: [PATCH 2/2] Test added for issue #447 --- lib/httparty/net_digest_auth.rb | 4 ++-- spec/httparty/net_digest_auth_spec.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/httparty/net_digest_auth.rb b/lib/httparty/net_digest_auth.rb index 7729458..7009210 100644 --- a/lib/httparty/net_digest_auth.rb +++ b/lib/httparty/net_digest_auth.rb @@ -68,10 +68,10 @@ module Net header =~ /Digest (.*)/ params = {} - if $1 + if $1 non_quoted = $1.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 } non_quoted.gsub(/(\w+)=([^,]*)/) { params[$1] = $2 } - end + end params end diff --git a/spec/httparty/net_digest_auth_spec.rb b/spec/httparty/net_digest_auth_spec.rb index 2bf1d5f..8ead743 100644 --- a/spec/httparty/net_digest_auth_spec.rb +++ b/spec/httparty/net_digest_auth_spec.rb @@ -152,6 +152,22 @@ RSpec.describe Net::HTTPHeader::DigestAuthenticator do end end + context "with http basic auth response when net digest auth expected" do + it "should not fail" do + # fails already so it is defined here + begin + @digest = setup_digest({ + 'www-authenticate' => 'WWW-Authenticate: Basic realm="testrealm.com""' + }) + + expect(authorization_header).to include("Digest") + rescue => e + fail "Should not fail on different authentification method" + end + + end + end + context "with multiple authenticate headers" do before do @digest = setup_digest({