diff --git a/lib/httparty/net_digest_auth.rb b/lib/httparty/net_digest_auth.rb index e18aef1b..66f5c177 100644 --- a/lib/httparty/net_digest_auth.rb +++ b/lib/httparty/net_digest_auth.rb @@ -25,10 +25,13 @@ def authorization_header %Q(nonce="#{@response['nonce']}"), %Q(uri="#{@path}"), %Q(response="#{request_digest}")] + [%Q(cnonce="#{@cnonce}"), - %Q(opaque="#{@response['opaque']}"), %Q(qop="#{@response['qop']}"), %Q(nc="0")].each { |field| header << field } if qop_present? + + header << %Q(opaque="#{@response['opaque']}") if opaque_present? + header end @@ -41,6 +44,10 @@ def parse(response_header) params end + def opaque_present? + @response.has_key?('opaque') and not @response['opaque'].empty? + end + def qop_present? @response.has_key?('qop') and not @response['qop'].empty? end diff --git a/spec/httparty/net_digest_auth_spec.rb b/spec/httparty/net_digest_auth_spec.rb index ee4491b4..205e58b3 100644 --- a/spec/httparty/net_digest_auth_spec.rb +++ b/spec/httparty/net_digest_auth_spec.rb @@ -13,6 +13,31 @@ def authorization_header @digest.authorization_header.join(", ") end + + context "with an opaque value in the response header" do + before do + @digest = setup_digest({ + 'www-authenticate' => 'Digest realm="myhost@testrealm.com", opaque="solid"' + }) + end + + it "should set opaque" do + authorization_header.should include(%Q(opaque="solid")) + end + end + + context "without an opaque valid in the response header" do + before do + @digest = setup_digest({ + 'www-authenticate' => 'Digest realm="myhost@testrealm.com"' + }) + end + + it "should not set opaque" do + authorization_header.should_not include(%Q(opaque=)) + end + end + context "with specified quality of protection (qop)" do before do @digest = setup_digest({