From c187bb6341cae786e08f5edc90e725c441c92743 Mon Sep 17 00:00:00 2001 From: Bernhard Kohler Date: Thu, 23 Oct 2014 17:05:09 -0500 Subject: [PATCH] quotes qop value prior to parsing it is very common for this header to contain this value unquoted --- lib/httparty/net_digest_auth.rb | 5 ++++- spec/httparty/net_digest_auth_spec.rb | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/httparty/net_digest_auth.rb b/lib/httparty/net_digest_auth.rb index f10e5dc..1a96567 100644 --- a/lib/httparty/net_digest_auth.rb +++ b/lib/httparty/net_digest_auth.rb @@ -44,7 +44,10 @@ module Net private def parse(response_header) - response_header['www-authenticate'] =~ /Digest (.*)/ + header = response_header['www-authenticate'] + .gsub(/qop=(auth(?:-int)?)/, %Q(qop="\\1")) + + header =~ /Digest (.*)/ params = {} $1.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 } params diff --git a/spec/httparty/net_digest_auth_spec.rb b/spec/httparty/net_digest_auth_spec.rb index a42bf5b..4543ba4 100644 --- a/spec/httparty/net_digest_auth_spec.rb +++ b/spec/httparty/net_digest_auth_spec.rb @@ -75,6 +75,17 @@ describe Net::HTTPHeader::DigestAuthenticator do end end + context "when quality of protection (qop) is unquoted" do + before do + @digest = setup_digest({ + 'www-authenticate' => 'Digest realm="myhost@testrealm.com", nonce="NONCE", qop=auth', + }) + end + + it "should still set qop" do + authorization_header.should include(%Q(qop="auth")) + end + end context "with unspecified quality of protection (qop)" do before do